octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #59403] integral2 and quad2d functions do not


From: Nicholas Jankowski
Subject: [Octave-bug-tracker] [bug #59403] integral2 and quad2d functions do not accurately document form of integrand function F
Date: Tue, 30 Jan 2024 22:27:11 -0500 (EST)

Follow-up Comment #12, bug#59403 (group octave):

the test cases for integrands with non-vectorized inputs:

1d.  The help for all of the 1D integral functions (except quadv) clearly
state something like "must be vectorized and return a vector of output values
when given a vector of input values". quadv or 'arrayvalued' options force the
integrator to provide scalar inputs and avoid matrix math problems.


>>f = @(x) sinc(x) * sinc(x);

>> quadv(f, -1, 1)  ## designed for vector/matrix valued fns
ans = 0.9028

>> integral(f, -1, 1)  ## uses quadcc
error: operator *: nonconformant arguments (op1 is 33x1, op2 is 33x1)
error: called from
    integral at line 146 column 11

>> quadgk(f,-1,1)
error: operator *: nonconformant arguments (op1 is 150x1, op2 is 150x1)
error: called from
    @<anonymous> at line 1 column 18
    quadgk>@<anonymous> at line 355 column 28
    quadgk>__quadgk_eval__ at line 558 column 5
    quadgk at line 369 column 22

>> integral(f, -1, 1, 'arrayvalued',true)
ans = 0.9028

>> quadgk(f, -1, 1, 'arrayvalued',true)
ans = 0.9028


2D:
integral2, dblquad, and quad2d state: "F must be of the form z = f(x,y) where
X is a vector and Y is a scalar.  It should return a vector of the same length
and orientation as X."  As per last comment, this is actually only valid for
dblquad (and integral2 when it mimics dblquad with the 'iterated' method).
'vectorized' option for integral2 & dblquad wrap f with arrayfun to force
scalar operations in the integrand. 


>> f = @(x, y) sinc(x) * sinc(y);

>> integral2(f, -1, 1, -1, 1)
ans = 12.328

>>dblquad(f, -1, 1, -1, 1)
ans = 1.3900

>> quad2d(f, -1, 1, -1, 1)
ans = 12.328

>> integral2(f, -1, 1, -1, 1, 'vectorized', true) 
ans = 12.328

>> integral2(f, -1, 1, -1, 1, 'vectorized', false)
ans = 1.3900

>> integral2(f, -1, 1, -1, 1, 'method', 'iterated') #avoids quad2d
ans = 1.3900

>> quad2d(f, -1, 1, -1, 1, 'vectorized', true)
ans = 12.328

>> quad2d(f, -1, 1, -1, 1, 'vectorized', false)
ans = 1.3900


matlab produces an input error for integral2 and quad2d for having
non-vectorized operations, but dblquad produces the same output as octave.

3D:

>> f = @(x, y, z) sinc(x) * sinc(y) * sinc(z);

>> integral3(f, -1, 1, -1, 1, -1, 1) ##uses quad2d
ans = 14.535

>> triplequad(f, -1, 1, -1, 1, -1, 1)
ans = 1.6388

>> integral3(f, -1, 1, -1, 1, -1, 1, 'method', 'iterated')
ans = 1.6388

>> integral3(f, -1, 1, -1, 1, -1, 1, 'vectorized', true)
ans = 14.535

>> integral3(f, -1, 1, -1, 1, -1, 1, 'vectorized', false)
ans = 1.6388


(where matlab again errors for integral3 and produces the same answer for
triplequad)


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?59403>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]