Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear
 

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Consultancy
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Find out about Online Training
• Download a Brochure
• Request a Brochure
• Download a Demo
• Request a Demo
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 11 Professional
Maple 11 Academic
Maple 11 Student Use
Recorded Online Seminars
FREE Training Resources


MapleNet
Maple T.A.
MapleConnect
BlockImporter for Simulink
BlockBuilder for Simulink
Maple Toolboxes
Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

View Maple 10 in Action
Product Comparison Chart

Latest Information

New Features: Professional
New Features: Academic
The Maple Reporter
The Maple Reporter Online
Numerical Algorithms Group
(NAG)


Service & Support

Maple 10 Training Videos
MaplePrimes, blogs, forums
Elite Maintenance Program
Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

List Archives >  Maple User Group List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MUG] multiple integration

Search email archive for  

[MUG] multiple integration
Author: Maple User Group    Posted: Thu, 30 Jan 2003 16:43:00 -0500

>> From: Maple User Group "maple_gr"

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: Douglas Harder "dwharder"
Subject: multiple integral with procedure (please ignore first one)
To: "maple-list"
Date: Tue, 14 Jan 2003 09:22:52 -0500 (EST)

Use unevaluation quotes:

> evalf(Int(Int('Flux2'(r,p,d,func)*r, r=0..5), p=0..2*Pi));

You were using 'name' quotes:

> evalf(Int(Int(`Flux2`(r,p,d,func)*r, r=0..5), p=0..2*Pi));

In Maple, we have the following objects:

1. Names `variable name`
2. Strings "Hello world"
3. Unevaluation 'sin(0)'

In the first case, if the variable name is nice, the back quotes can be
left off. Nice is any variable name whose first character is either alphabetic
or an _ and whose subsequent characters are either alphanumeric or _.

Thus, `x` and x are the same variable. You only need the back quotes if
you decide to use something like

> `This is a cool variable` := 3:
> `This is a cool variable`^2;

9

To delay evaluation, you use usual quotes: '' In your case, it prevents
the function from being evaluated with arguments r,p,d,func and the function
is only evaluated when evalf/Int substitutes numeric values for r, p, d, and
func.

You get the same error if you just do:

> Flux2(r,p,d,func);
Error, (in Flux2) cannot determine if this expression is true or false: 2 < r

The error message since Maple8 (I think) is a lot nicer, it actually tells
you what it's having a problem with instead of giving a pointless 'cannot
evaluate boolean' error.

Cheers,

Douglas
--
Douglas Wilhelm Harder -: 3- -.- =.- -: -3 .* =. -:- :- . -: .= -:- * -:- -.
Department of Electrical and Computer Engineering http://ece.uwaterloo.ca/
University of Waterloo http://cheetah.vlsi.uwaterloo.ca/~dwharder/
.___ DC 2703 519-885-1211 x7023 http://links.uwaterloo.ca/
EII \ ."""". .-----._____.-----._______.-----._____.-----._____.--
DGR \____/ --10-- http://www.scg.uwaterloo.ca/ http://mapleapps.com/


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Tue, 14 Jan 2003 10:57:01 -0600
From: "Philip B. Yasskin" "yasskin"
To: "maple-list"
Subject: multiple integral with procedure

Try a nested numerical middlesum from the student package:

> with(student);
> n:=8;
>evalf(middlesum (middlesum (`Flux2`(r,p,d,func)*r, r=0..5,n),
p=0..2*Pi,n));

Then keep doubling n.

Phil Yasskin
Texas A&M

Max Bian wrote:

>>>From: Max Bian "zbian"
>>>
>>>
>
>Hello maple-list!
>
>This is my first post and I am hoping for a quick help.
>
>I need to do a numerical integral over a procedure with two parameters.
>This shouldn't be too hard as I had figured:
>
> evalf(Int(Int(`Flux2`(r,p,d,func)*r, r=0..5), p=0..2*Pi));
>
>and "Flux2" is a procedure.
>
>However I get problem if the procedure includes boolean evaluations
>such as:
>
> If r>2 then do
> ...
> end do:
>
>I always get error saying that "cannot evaluate boolean...".
>
>How do I get around this?
>
>Thank you!
>
>Max
>
>



-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: Stanley J Houghton "S.J.Houghton"
Date: Tue, 14 Jan 2003 17:06:14 +0000
To: "maple-list"
Subject: multiple integral with procedure (please ignore first one)

It is all down to premature evaluation, i.e. evaluating the function as
applied to arguments that have not yet been assigned values.

I use two simplified examples to demonstrate. There are two ways to
correct it:

1. to quote the function call as in

> restart;
> Flux2:=
> (r,p)->if r>2 then
> 0
> else
> p^3+(r-2)^2
> end if;
> evalf(Int(Int('Flux2'(r,p)*r, r=0..5), p=0..2*Pi));

but note that these are simple quotes (') to quote a value as
opposed to "back quotes" (`) that delimit a name.

2. The alternative is to generalise your function to return a quoted
value of the arguments are symbolic, i.e. do not evaluate to constant
values, as in

> restart;
> Flux2:=
> (r,p)->if not(type(r,'constant') and type(p,constant)) then
> 'Flux2'(r,p) # that is, handle the symbolic case first
> elif r>2 then
> 0
> else
> p^3+(r-2)^2
> end if;
> evalf(Int(Int(Flux2(r,p)*r, r=0..5), p=0..2*Pi));

Hope it helps

Stan

On Wed, 8 Jan 2003 15:55:20 -0800 (PST) Max Bian "zbian"
wrote:
>
> >> From: Max Bian "zbian"
>
> Hello maple-list!
>
> This is my first post and I am hoping for a quick help.
>
> I need to do a numerical integral over a procedure with two parameters.
> This shouldn't be too hard as I had figured:
>
> evalf(Int(Int(`Flux2`(r,p,d,func)*r, r=0..5), p=0..2*Pi));
>
> and "Flux2" is a procedure.
>
> However I get problem if the procedure includes boolean evaluations
> such as:
>
> If r>2 then do
> ...
> end do:
>
> I always get error saying that "cannot evaluate boolean...".
>
> How do I get around this?
>
> Thank you!
>
> Max
>




-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Tue, 14 Jan 2003 15:04:44 -0500 (EST)
From: Carl Devore "devore"
To: "maple-list"
Subject: multiple integral with procedure



On Wed, 8 Jan 2003, Max Bian wrote:
> I need to do a numerical integral over a procedure with two parameters.
> This shouldn't be too hard as I had figured:
> evalf(Int(Int(`Flux2`(r,p,d,func)*r, r=0..5), p=0..2*Pi));
> and "Flux2" is a procedure.
>
> However I get problem if the procedure includes boolean evaluations

evalf(Int((r,p)-> Flux2(r,p,d,func)*r, [0..5, 0..2*Pi]));


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Tue, 14 Jan 2003 16:08:24 -0800 (PST)
From: Robert Israel "israel"
To: "maple-list"
Subject: multiple integral with procedure (please ignore first one)


The problem is premature evaluation. Back=quotes as in `Flux2` are
for making something into a name: in this case they don't really
do anything, since Flux2 is already a name. What you want for delaying
evaluation are forward quotes. Thus the following should work:

evalf(Int(Int('Flux2'(r,p,d,func)*r, r=0..5), p=0..2*Pi));

Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2


On Wed, 8 Jan 2003, Max Bian wrote:

> Hello maple-list!
>
> This is my first post and I am hoping for a quick help.
>
> I need to do a numerical integral over a procedure with two parameters.
> This shouldn't be too hard as I had figured:
>
> evalf(Int(Int(`Flux2`(r,p,d,func)*r, r=0..5), p=0..2*Pi));
>
> and "Flux2" is a procedure.
>
> However I get problem if the procedure includes boolean evaluations
> such as:
>
> If r>2 then do
> ...
> end do:
>
> I always get error saying that "cannot evaluate boolean...".
>
> How do I get around this?
>
> Thank you!
>
> Max
>


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Wed, 15 Jan 2003 01:36:29 +0100
From: Helmut Kahovec "helmut.kahovec"
To: "maple-list"
Subject: multiple integral with procedure (please ignore first one)

Max Bian wrote:

>| This is my first post and I am hoping for a quick help.
>|
>| I need to do a numerical integral over a procedure with two parameters.
>| This shouldn't be too hard as I had figured:
>|
>| evalf(Int(Int(`Flux2`(r,p,d,func)*r, r=0..5), p=0..2*Pi));
>|
>| and "Flux2" is a procedure.
>|
>| However I get problem if the procedure includes boolean evaluations
>| such as:
>|
>| If r>2 then do
>| ...
>| end do:
>|
>| I always get error saying that "cannot evaluate boolean...".
>|
>| How do I get around this?


Well, integration procedures like int() or `evalf/Int`() evaluate their
arguments. Thus your `Flux2` gets called when r and p are still symbols,
and in this case Maple cannot decide whether r>2 is true or not. If you
put two single quotes around the name `Flux2` then Maple will evaluate
'`Flux2`'(...) to `Flux2`(...) and not any further (i.e., will not call
it with r and p as symbols). Actually, your back quotes around the name
Flux2 are not necessary.

Cf. the following short Maple8 session.

> restart;
> int(int(x+y,y=0..1/2),x=0..1/2);

1/8

> myproc:=proc(x,y)
if x<=1/2 and y<=1/2 then x+y else 0 end if
end proc:

> evalf(Int(Int(myproc(x,y),x=0..1),y=0..1));
Error, (in myproc) cannot determine if this expression is true or\
false: x-1/2 <= 0 and y-1/2 <= 0

> evalf(Int(Int('myproc'(x,y),x=0..1),y=0..1));

0.1250000000


Kind regards,

Helmut


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: "Greg Gamble" "gregg"
To: "maple-list"
Subject: multiple integral with procedure (please ignore first one)
Date: Wed, 15 Jan 2003 09:50:43 +0800

On Thursday, 9 January 2003 7:55 AM, Max Bian wrote:
> Hello maple-list!
>
> This is my first post and I am hoping for a quick help.
>
> I need to do a numerical integral over a procedure with two parameters.
> This shouldn't be too hard as I had figured:
>
> evalf(Int(Int(`Flux2`(r,p,d,func)*r, r=0..5), p=0..2*Pi));
>
> and "Flux2" is a procedure.

Firstly, I hope you realise that Int is the ``inert'' form of int,
which is left intact by eval, though evaluated by evalf. (This is
not your problem, just an FYI = `For your information'.)

> However I get problem if the procedure includes boolean evaluations
> such as:
>
> If r>2 then do
> ...
> end do:

Of course, you didn't mean to capitalise the If here. Does the ...
contain a way of escaping the (infinite) do-loop (a `break' or
something)? Again this does not lead to the error below, but may
point to another problem with your code.

> I always get error saying that "cannot evaluate boolean...".

It's possible you need to embed r>2 in is( ... ) i.e. have

if is(r>2) then ...

However, are you sure this is where the error lies? I think you
need to provide the list with the function Flux2 itself, if that's
possible, or at least a cut-down version that exhibits the problem.

Regards,
Greg Gamble

// Greg Gamble, Dept. of Maths & Stats //
// Curtin University, Bentley WA 6102 //
// Mailto: "gregg" //
// WWW: http://www.maths.curtin.edu.au/~gregg //


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Wed, 15 Jan 2003 07:37:34 -0800 (PST)
From: Max Bian "zbian"
Subject: multiple integral with procedure (Round 2)
To: "maple-list"

I received several suggestions, but I still cannot get it. I have cut
the minimum maple code as below. Would you please try it and let me
know what else I can try?

Thank you very much!

Max

btw: I am using Maple 7 for windows.
=============================
Htc := 3:
H := 1.5:
Hcs := 4:
TD := evalf(Htc + H + Hcs):
Dc := 1:
TargetR := 15:

FTa := th->(cos(th))^0.5:

Flux := proc(x, y, d, func)
local xa, ya, xb, yb, ra, rb, th, tmp;

xa := d + (x-d)*(Hcs+H)/TD;
ya := y*(Hcs+H)/TD;
ra := evalf(sqrt(xa^2+ya^2));

xb := d + (x-d)*Hcs/TD;
yb := y*Hcs/TD;
rb := evalf(sqrt(xb^2+yb^2));

if (ra > Dc/2) or (rb > Dc/2) then
return 0;
else
tmp := sqrt((x-d)^2 + y^2 + TD^2);
th := arccos(TD/tmp);
return `func`(th)*TD/tmp^3;
end if;
end proc:


Coli := proc (d, func)
evalf(Int(Int('Flux'(r,p,d,func)*r, r=0..TargetR), p=0..2*Pi));
# evalf(Int((r,p)-> Flux(r,p,d,func)*r, [0..TargetR, 0..2*Pi]));

end proc:

Coli(0, FTa);

===============================================


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Wed, 22 Jan 2003 06:12:56 -0500 (EST)
From: Carl Devore "devore"
To: "maple-list"
Subject: multiple integral with procedure



On Tue, 14 Jan 2003, Carl Devore wrote:
> On Wed, 8 Jan 2003, Max Bian wrote:
> > I need to do a numerical integral over a procedure with two parameters.
> > This shouldn't be too hard as I had figured:
> > evalf(Int(Int(`Flux2`(r,p,d,func)*r, r=0..5), p=0..2*Pi));
> > and "Flux2" is a procedure.
> >
> > However I get problem if the procedure includes boolean evaluations
>
> evalf(Int((r,p)-> Flux2(r,p,d,func)*r, [0..5, 0..2*Pi]));

Dear Moderator:

Please add to my answer above:

This only works in Maple 8.

Previous by date: [MUG] max element of array, Jeffrey Dambacher
Next by date: [MUG] Pb with minimize, Franck Wielonsky
Previous thread: [MUG] plotting colors in maple,  Kristian Jantz
Next thread: [MUG] Pb with minimize, Franck Wielonsky



Ready to buy?

Maple - single user licence
Add to shopping basket
$ 1,895.00
Upgrade to Maple 12 from v11
Add to shopping basket
$ 995.00
Upgrade to Maple 12 from v10 & below
Add to shopping basket
$ 1,395.00

Featured Downloads

Maple White Paper: Technical Knowledge - An Asset You Can Afford to Lose?
Maple in Electronics Application Pack
Maple in Robotics & Aerospace Application Pack
Maple in Finance Application Pack

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks
adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2007, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055