Adept Scientific - English
The world's best software and hardware 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  
UKdedksvnofi
Home
Products
Training
Events
 Buy Online
Downloads
Academic Discounts
Support
My Adept
International |  About Us |  Adept Scientific Blog |  Contact Us |  Press Room |  Jobs
Adept Scientific on Facebook Adept Scientific on Twitter Adept Scientific on YouBube Adept Scientific on LinkedIn


The Next Steps

• Ask us a question
• Watch Maple Video Demonstrations
• Buy Maple Now
• View Maple Pricing
• Download a Brochure
• Request an Evaluation
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 17 Overview
Maple 17 Professional
Maple 17 Academic
Maple 17 Student Use
Maple 17 Personal Edition
What's New in Maple 17
Maple Features
Maple History
Recorded Online Seminars

MapleSim
MapleNet
Maple T.A.
BlockImporter™
Maple Toolboxes
The Möbius Project

Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

Latest Information

New Features: Professional
New Features: Academic
Maple Features
The Maple Reporter Online

Service & Support

Maple Primes
blogs, forums etc

Elite Maintenance Program
Application Centre
Powertools
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
Subject: multiple integral with procedure (please ignore first one)
To: /> 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" /> To: /> 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 /> >>>
>>>
>
>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 /> Date: Tue, 14 Jan 2003 17:06:14 +0000
To: /> 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
wrote:
>
> >> From: Max Bian /> >
> 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 /> To: /> 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 /> To: /> 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 /> 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 /> To: /> 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" /> To: /> 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: //
// WWW: http://www.maths.curtin.edu.au/~gregg //


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

Date: Wed, 15 Jan 2003 07:37:34 -0800 (PST)
From: Max Bian /> Subject: multiple integral with procedure (Round 2)
To: />
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.

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?

For more pricing information:
Visit our webstore, call us on +44 (0) 1462 480055 or email us at sales@adeptscience.co.uk

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

Latest News

Global Optimization Toolbox: Better Optimization to Solve More Problems, Faster
Global Optimization Toolbox: Better Optimization to Solve More Problems, Faster
New MapleSim release delivers advanced model development and analysis, extended toolchain connectivity and quicker results
Maple 17 offers advanced solving and application development capabilities
New release of Maple advances teaching and research
adept

Top of the Page

Popular Links: ChemDraw | ChemOffice | Data Acquisition | Data Analysis | EndNote | Mathcad | MathType | Quality Analyst | Reference Manager | VisSim

EU ePrivacy Directive | Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2013, Adept Scientific Ltd.
Site designed and maintained by Lyndon Ash

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