Fwd: [Maxima-discuss] dblquad fail

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: [Maxima-discuss] dblquad fail

Ether Jones-2
Hello.

I am trying to numerically integrate a function using dblquad, but getting errors shown below.  Thank you.

octave-3.6.4.exe:3> I = dblquad(@(r,q)r*sqrt(r^2+1-2*cos(2*pi()*q)),0,1,0,1)
error: for A^b, A must be a square matrix
error: evaluating argument list element number 1
error: called from:
error:    at line -1, column -1
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 72, column 10
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 65, column 5


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

Re: [Maxima-discuss] dblquad fail

Doug Stewart-4


On Wed, Jul 27, 2016 at 9:57 PM, Ether Jones <[hidden email]> wrote:
Hello.

I am trying to numerically integrate a function using dblquad, but getting errors shown below.  Thank you.

octave-3.6.4.exe:3> I = dblquad(@(r,q)r*sqrt(r^2+1-2*cos(2*pi()*q)),0,1,0,1)
error: for A^b, A must be a square matrix
error: evaluating argument list element number 1
error: called from:
error:    at line -1, column -1
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 72, column 10
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 65, column 5


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


I don't know what you want, but maybe this will help.

>> I = dblquad(@(r,q)abs( r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)
I =  0.58663

--
DAS


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

Re: [Maxima-discuss] dblquad fail

Doug Stewart-4


On Wed, Jul 27, 2016 at 10:32 PM, Doug Stewart <[hidden email]> wrote:


On Wed, Jul 27, 2016 at 9:57 PM, Ether Jones <[hidden email]> wrote:
Hello.

I am trying to numerically integrate a function using dblquad, but getting errors shown below.  Thank you.

octave-3.6.4.exe:3> I = dblquad(@(r,q)r*sqrt(r^2+1-2*cos(2*pi()*q)),0,1,0,1)
error: for A^b, A must be a square matrix
error: evaluating argument list element number 1
error: called from:
error:    at line -1, column -1
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 72, column 10
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 65, column 5


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


I don't know what you want, but maybe this will help.

>> I = dblquad(@(r,q)abs( r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)
I =  0.58663

--
DAS



This might also help:


 r=0:.01:1;
 q=0:.01:1;
 [xx yy]=meshgrid(r,q);
 
  ff= @(r,q)abs( r.*sqrt(r.^2+1-2*cos(2*pi*q)))
 zz=ff(xx,yy);
 mesh(xx,yy,zz) # this shows the surface that we are using.
 
 I = dblquad(@(r,q)abs( r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)



--
DAS


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

Re: Fwd: [Maxima-discuss] dblquad fail

tmacchant
In reply to this post by Ether Jones-2
>From: Ether Jones 
>To: help-octave  
>Date: 2016/7/28, Thu 10:57
>Subject: Fwd: [Maxima-discuss] dblquad fail
>
>
>Hello.
>
>I am trying to numerically integrate a function using dblquad, but getting errors shown below.  Thank you.
>
>octave-3.6.4.exe:3> I = dblquad(@(r,q)r*sqrt(r^2+1-2*cos(2*pi()*q)),0,1,0,1)
>error: for A^b, A must be a square matrix
>error: evaluating argument list element number 1
>error: called from:
>error:    at line -1, column -1
>error:    at line -1, column -1
>error: quadcc: integrand F must return a single, real-valued vector
>error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 72, column 10
>error:    at line -1, column -1
>error: quadcc: integrand F must return a single, real-valued vector
>error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 65, column 5


In the octave manual of dblquad [1]

**********************************
f is a function handle, inline function, or string containing the name of the function to evaluate. 
The function f must have 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.

**********************************

It should return a vector of the same length and orientation as x.


So that function should be written using element-by-element  calculation [2]
As written by Doug, you should write function as

@(r,q)r.*sqrt(r.^2+1-2*cos(2*pi()*q)) 

[1] https://www.gnu.org/software/octave/doc/interpreter/Functions-of-Multiple-Variables.html#index-dblquad
[2] https://www.gnu.org/software/octave/doc/interpreter/Arithmetic-Ops.html#Arithmetic-Ops


BTW, you seem to use old octave 3.6.4 on windows.
The latest and modern octave 4.0.3 is available on the 
https://ftp.gnu.org/gnu/octave/windows/


Tatsuro

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

Re: [Maxima-discuss] dblquad fail

Ether Jones
In reply to this post by Doug Stewart-4

Thank you.

This works:
octave-3.6.4.exe:3>  I = dblquad(@(r,q)abs( r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)
I =  0.586626703381746

... but this doesn't:
octave-3.6.4.exe:4>  I = dblquad(@(r,q)r.*sqrt(r.^2+1-2*cos(2*pi*q)),0,1,0,1)
error: quadcc: integrand F must return a single, real-valued vector
error: called from:
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 72, column 10
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 65, column 5

Why is the abs() necessary?

Reply | Threaded
Open this post in threaded view
|

Re: [Maxima-discuss] dblquad fail

Doug Stewart-4


On Thu, Jul 28, 2016 at 7:54 AM, Ether Jones <[hidden email]> wrote:

Thank you.

This works:
octave-3.6.4.exe:3>  I = dblquad(@(r,q)abs(
r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)
I =  0.586626703381746

... but this doesn't:
octave-3.6.4.exe:4>  I =
dblquad(@(r,q)r.*sqrt(r.^2+1-2*cos(2*pi*q)),0,1,0,1)
error: quadcc: integrand F must return a single, real-valued vector
error: called from:
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 72,
column 10
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 65,
column 5

Why is the abs() necessary?





Your range of values for r and p start at zero.

if you put 0 and 0 in your eq. you get

sqrt(0^2+1-2*1)
sqrt(-1) this is imaginary

instead of abs you could try

 I = dblquad(@(r,q)real(r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)

 I = dblquad(@(r,q)imag(r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)  



Look at the plot of the surfase when you ask for the real part.


--
View this message in context: http://octave.1599824.n4.nabble.com/Fwd-Maxima-discuss-dblquad-fail-tp4678866p4678889.html
Sent from the Octave - General mailing list archive at Nabble.com.

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



--
DASCertificate for 206392


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

Re: [Maxima-discuss] dblquad fail

c.-2
In reply to this post by Ether Jones

Il 28 lug 2016 5:50 PM, "Ether Jones" <[hidden email]> ha scritto:
>
>
> Thank you.
>
> This works:
> octave-3.6.4.exe:3>  I = dblquad(@(r,q)abs(
> r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)
> I =  0.586626703381746
>
> ... but this doesn't:
> octave-3.6.4.exe:4>  I =
> dblquad(@(r,q)r.*sqrt(r.^2+1-2*cos(2*pi*q)),0,1,0,1)
> error: quadcc: integrand F must return a single, real-valued vector
> error: called from:
> error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 72,
> column 10
> error:    at line -1, column -1
> error: quadcc: integrand F must return a single, real-valued vector
> error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 65,
> column 5
>
> Why is the abs() necessary?

The error message you reported says:
error: quadcc: integrand F must return a single, real-valued vector

Is your integrand function real for any value of (r,q) in (0,1)?

c.


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

Re: [Maxima-discuss] dblquad fail

tmacchant
In reply to this post by Ether Jones-2
--- octave

>
> Thank you.
>
> This works:
> octave-3.6.4.exe:3>  I = dblquad(@(r,q)abs(
> r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)
> I =  0.586626703381746
>
> ... but this doesn't:
> octave-3.6.4.exe:4>  I =
> dblquad(@(r,q)r.*sqrt(r.^2+1-2*cos(2*pi*q)),0,1,0,1)
> error: quadcc: integrand F must return a single, real-valued vector
> error: called from:
> error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 72,
> column 10
> error:    at line -1, column -1
> error: quadcc: integrand F must return a single, real-valued vector
> error:   K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m at line 65,
> column 5
>
> Why is the abs() necessary?
>
perhaps at report some values of r, p, the term in squere root is minus and square root of it is imaginary and this causes error.

Tatsuro


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

Re: [Maxima-discuss] dblquad fail

tmacchant
In reply to this post by Ether Jones
----- Original Message -----

> From: Ether Jones 
> To: help-octave
> Cc:
> Date: 2016/7/28, Thu 20:54
> Subject: Re: [Maxima-discuss] dblquad fail
>
>
> Thank you.
>
> This works:
> octave-3.6.4.exe:3>  I = dblquad(@(r,q)abs(
> r.*sqrt(r.^2+1-2*cos(2*pi*q))),0,1,0,1)
> I =  0.586626703381746
>
> ... but this doesn't:
> octave-3.6.4.exe:4>  I =
> dblquad(@(r,q)r.*sqrt(r.^2+1-2*cos(2*pi*q)),0,1,0,1)
> error: quadcc: integrand F must return a single, real-valued vector
> error: called from:
> error: 
> K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m
> at line 72,
> column 10
> error:    at line -1, column -1
> error: quadcc: integrand F must return a single, real-valued vector
> error: 
> K:\OctaveVS\share\octave\3.6.4\m\general\dblquad.m
> at line 65,
> column 5
>
> Why is the abs() necessary?
>
As already written by some persons, the function value should be real
for all integration range.
However when example r=0.1, q=1
>> r.^2+1-2*cos(2*pi*q)
ans = -0.99000


>> sqrt (r.^2+1-2*cos(2*pi*q))
ans =  0.00000 + 0.99499i

Then
>> r.*sqrt(r.^2+1-2*cos(2*pi*q))
ans =  0.000000 + 0.099499i

pure imaginary.

Perhaps problem is not simple double integration.
(conditional integration with r and q)
I recommend you reconsider your problem in mathematical or physical sense.


Tatsuro

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