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] Re: minimizing functions - question

Search email archive for  

[MUG] Re: minimizing functions - question
Author: Maple User Group    Posted: Tue, 11 Jun 2002 17:31:40 -0400

>> From: Maple User Group "maple_gr"

| >> From: Alexander Serebrenik "Alexander.Serebrenik"
| I try to find the minimal value of an interval-defined function as
| following:
|
| > h := x -> if x < 5 then t-x^2 else x+t end if ;
| h := proc(x)
| option operator, arrow;
| if x < 5 then t - x^2 else x + t end if
| end proc
|
| > minimize(h(x,t), x = 0..7, t=10..14);
| Error, (in h) cannot evaluate boolean: x < 5

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

Date: Wed, 5 Jun 2002 14:13:40 -0700 (PDT)
From: Robert Israel "israel"
To: "maple-list"
Subject: minimizing functions - question

There are several problems here.

The error message is caused by premature evaluation: when you say
h(x,t) you are trying to evaluate the function h with the symbolic
argument x, and this can't be done because Maple can't determine
which branch to take in the "if" statement. One way around this
would be to use the "piecewise" function.

A second problem is that you defined h with one argument and called
it with two. The second argument, t, will simply be ignored. In
this case that doesn't cause problems because the result will be the
same with h(x,t) as it would be with h(x).

You could say

> h:= (x,t) -> piecewise(x<5, t-x^2, x+t);
minimize(h(x,t), x= 0 .. 7, t = 10 .. 14);

In Maple 6 or 7 this produces an error message (the result of a bug):

Error, (in solve/addident) wrong number (or type) of parameters in
function map

Maple 8 (surprisingly enough) comes up with an answer, which I presume
is the one you wanted:

-15

The final problem is that this isn't really correct either: the function
has an infimum but not a minimum on the rectangle 0 <= x <= 7,
10 <= t <= 14, since h(x,10) -> -15 as x -> 5-, but h(5,10) = +15.

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





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

From: Alec Mihailovs "amihailo"
To: "maple-list"
Subject: minimizing functions - question
Date: Wed, 5 Jun 2002 21:43:25 -0400

> h := piecewise(x < 5,t-x^2,x+t):
> minimize(h, x=0..7, t=10..14);

-15
Best wishes,
Alec Mihailovs
http://webpages.shepherd.edu/amihailo


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

From: "Bill Page" "bill.page1"
To: "maple-list"
Subject: minimizing functions - question
Date: Wed, 5 Jun 2002 22:19:54 -0400

Alexander,

The first argument to minimize is supposed to be an
"algebraic" expression. In your example Maple evaluates
h(x,t) prematurely, even before attempting the minimization
and fails right away. The same thing happens if you just
write

> h(x,t);

But Maple 8 understands the function 'piecewise' as a kind
of algebraic expression. If h is defined as follows:

> h:=(x,t) -> piecewsie(x < 5,t-x^2,x+t);

then h(x,t) evaluates as the expression piecewsie(x < 5,t-x^2,x+t)
which is processed properly by minimize.

> minimize(h(x,t), x = 0..7, t=10..14);

But note: Maple 7 fails on this and Maple 5 gets the wrong result
with a similar command

> minimize(h(x,t), {x,t}, {x = 0..7, t=10..14});

(Maple 5 used a different syntax for minimize.)

Cheers,
Bill Page.

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

From: Stanley J Houghton "S.J.Houghton"
Date: Fri, 7 Jun 2002 15:52:21 +0100
To: "Alexander.Serebrenik" "maple-list"
Subject: minimizing functions - question

It is a case of premature evaluation. Since the parameters of
functions such as minimize or plot3d are evaluated, you have to write
your function to return an unevaluated result if x and t are not
constants.

> h :=
> (x,t) -> if not (type(x,'constant') and type(t,'constant')) then
> 'procname'(x,t) # return unevaluated
> elif x < 5 then t-x^2
> else x+t end if ;
> minimize(h(x,t), x = 0..4.9999995, t=10..14);

This was not much help though, since, although I could plot3d the
function h(x,t), the minimise call returned unevaluated after
"thinking" for a while.

I will leave it for others to comment on this aspect.

I would add that, in the new release 8, you can simplify this form by
using piecewise as below

> h := (x,t) -> piecewise( x < 5 , t-x^2 , x+t ) ;
> minimize(h(x,t), x = 0..7, t=10..14,location);

This worked and returned the correct answer (but, I repeat, only in
version 8).

Regards
Stan

On Tue, 4 Jun 2002 11:11:16 +0200
(MEST) Alexander Serebrenik
"Alexander.Serebrenik" wrote:

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

Date: Tue, 11 Jun 2002 13:20:33 +0200
From: PierLuigi Zezza "pierluigi.zezza"
Subject: minimizing functions - question
To: "maple-list"

Hi, you have two different problems:<br><br>
1. In the definition your function you must include the possibility of x
being a formal parameter
>h := proc(x): if
type(x,numeric) then if x < 5 then t-x^2 else x+t end if else 'h(x)'
end if end;

2. To my knowledge minimize work for univariate functions<br><br>
> minimize(h(1,t), t=10..14);
9

gigi zezza

PierLuigi Zezza
"pzezza"

[View Complete Thread]



Previous by date: [MUG] Export to html in Maple 8 -- problem, Carl Eberhart
Next by date: [MUG] Re: Assignment, Maple User Group
Previous thread: [MUG] Export to html in Maple 8 -- problem, Carl Eberhart
Next thread: [MUG] Assignment,  Edgar G Goodaire



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

What's New in Maple 11 for Professionals
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