Re: Implementing AbsTol for quadcc

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AbsTol for quadcc

NJank
Rik, can you or someone else check the following against your newly pushed quadcc? this throws an error in the 4.2,1 release version. unless it's something now fixed in your version I think it calls for a bug report.  I stumbled on it when I tried to pass a function of x only to integral2:

>> quadv(@(x) 1, 0,1)
ans = 1
>> quad(@(x) 1, 0,1)
ans = 1
>> quadgk(@(x) 1, 0,1)
ans = 1
>> quadcc(@(x) 1, 0,1)
error: quadcc: integrand F must return a single, real-valued vector

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AbsTol for quadcc

Pantxo
NJank wrote

> Rik, can you or someone else check the following against your newly pushed
> quadcc? this throws an error in the 4.2,1 release version. unless it's
> something now fixed in your version I think it calls for a bug report.  I
> stumbled on it when I tried to pass a function of x only to integral2:
>
>>> quadv(@(x) 1, 0,1)
> ans = 1
>>> quad(@(x) 1, 0,1)
> ans = 1
>>> quadgk(@(x) 1, 0,1)
> ans = 1
>>> quadcc(@(x) 1, 0,1)
> error: quadcc: integrand F must return a single, real-valued vector
>
> _______________________________________________
> Help-octave mailing list

> Help-octave@

> https://lists.gnu.org/mailman/listinfo/help-octave

Hi,

This error is still present on the development branch but if I understand
the documentation correctly, it is expected:

>> The function F must be vectorized and must return a vector of output
>> values if given a vector of input values

So the correct call form should be something like
quadcc (@(x) ones (size (x)), 0,1)

Pantxo



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AbsTol for quadcc

NJank
On Fri, Sep 29, 2017 at 9:35 AM, Pantxo <[hidden email]> wrote:
NJank wrote
> Rik, can you or someone else check the following against your newly pushed
> quadcc? this throws an error in the 4.2,1 release version. unless it's
> something now fixed in your version I think it calls for a bug report.  I
> stumbled on it when I tried to pass a function of x only to integral2:
>
>>> quadv(@(x) 1, 0,1)
> ans = 1
>>> quad(@(x) 1, 0,1)
> ans = 1
>>> quadgk(@(x) 1, 0,1)
> ans = 1
>>> quadcc(@(x) 1, 0,1)
> error: quadcc: integrand F must return a single, real-valued vector
>
> _______________________________________________
> Help-octave mailing list

> Help-octave@

> https://lists.gnu.org/mailman/listinfo/help-octave

>> The function F must be vectorized and must return a vector of output
>> values if given a vector of input values

understood. but quadgk is also has the same requirement, but doesn't choke on the function. what does it do differently?

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AbsTol for quadcc

Rik-4
In reply to this post by NJank
On 09/29/2017 05:27 AM, Nicholas Jankowski wrote:

> Rik, can you or someone else check the following against your newly
> pushed quadcc? this throws an error in the 4.2,1 release version. unless
> it's something now fixed in your version I think it calls for a bug
> report.  I stumbled on it when I tried to pass a function of x only to
> integral2:
>
> >> quadv(@(x) 1, 0,1)
> ans = 1
> >> quad(@(x) 1, 0,1)
> ans = 1
> >> quadgk(@(x) 1, 0,1)
> ans = 1
> >> quadcc(@(x) 1, 0,1)
> error: quadcc: integrand F must return a single, real-valued vector

It throws an error, but I think it might be correct.  The integrand is
supposed to return a vector for vector inputs.  This allows the quadrature
routine to call f(x1, x2, x3, ..., xn) and get y1,y2,y3, ..., yn. 
Vectorization is always far faster than having to write this as a for loop
from 1:n and then call the function repeatedly.

Just to test, if you change the integrand to a vector function it works
correctly.

quadcc (@(x) ones (size (x)), 0, 1)
ans =  1.00000

Cheers,
Rik

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AbsTol for quadcc

NJank
Just to test, if you change the integrand to a vector function it works
correctly.

quadcc (@(x) ones (size (x)), 0, 1)
ans =  1.00000

Cheers,
Rik

Yes, I just find it curious that the other functions do not error on the same integrand despite having the same vector function requirements.

Peeking in quadgk I assume it's because of the transform that occurs on lines 235-236, that essentially redefines the function as a vector function whether it starts as one or not.  maybe similar things happen in quadl. quad and quadv don't have the same requirement.

I bring this up because I was trying out some compatibility tests with integral2. 

Matlab gives the same vector function error as quadcc for all of its vectorized quad functions (quadgk, quadl) and integral. similar for dblquad:

>> dblquad(@(x,y) x, 0,1,0,1)
ans =
    0.5000
>> dblquad(@(x,y) y, 0,1,0,1)
Error using quad (line 70)
The integrand function must return an output vector of the same length as the input vector.

but not for integral2:
>> integral2(@(x,y) x, 0,1,0,1)
ans =
    0.5000
>> integral2(@(x,y) y, 0,1,0,1)
ans =
    0.5000

since we switched integral2 over to using quadcc, we get the same effort as dblquad
>> integral2(@(x,y) x, 0,1,0,1)
ans =  0.50000
>> integral2(@(x,y) y, 0,1,0,1)
error: quadcc: integrand F must return a single, real-valued vector


just leave this under the category of 'undocumented matlab we aren't going to worry about'?


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Implementing AbsTol for quadcc

Rik-4
On 09/29/2017 09:27 AM, Nicholas Jankowski wrote:
Just to test, if you change the integrand to a vector function it works
correctly.

quadcc (@(x) ones (size (x)), 0, 1)
ans =  1.00000

Cheers,
Rik

Yes, I just find it curious that the other functions do not error on the same integrand despite having the same vector function requirements.

Peeking in quadgk I assume it's because of the transform that occurs on lines 235-236, that essentially redefines the function as a vector function whether it starts as one or not.  maybe similar things happen in quadl. quad and quadv don't have the same requirement.

I bring this up because I was trying out some compatibility tests with integral2. 

Matlab gives the same vector function error as quadcc for all of its vectorized quad functions (quadgk, quadl) and integral. similar for dblquad:

>> dblquad(@(x,y) x, 0,1,0,1)
ans =
    0.5000
>> dblquad(@(x,y) y, 0,1,0,1)
Error using quad (line 70)
The integrand function must return an output vector of the same length as the input vector.

but not for integral2:
>> integral2(@(x,y) x, 0,1,0,1)
ans =
    0.5000
>> integral2(@(x,y) y, 0,1,0,1)
ans =
    0.5000

since we switched integral2 over to using quadcc, we get the same effort as dblquad
>> integral2(@(x,y) x, 0,1,0,1)
ans =  0.50000
>> integral2(@(x,y) y, 0,1,0,1)
error: quadcc: integrand F must return a single, real-valued vector


just leave this under the category of 'undocumented matlab we aren't going to worry about'?


I think that's good enough for now.

--Rik

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave