- Subject: Two problems
- From: Richard Petti <petti at ALLEGHENY.SCRC.Symbolics.COM>
- Date: Thu, 22 Jun 89 13:51:01 -0500
- Apparently-to: mathgroup-out at yoda.ncsa.uiuc.edu
Date: Wed, 21 Jun 89 00:35:34 -0500
From: Dallas_Burtraw at um.cc.umich.edu
Greetings. I am in the Economics Dept at Michigan and have been using
Mathematica for a little while. Two questions have surfaced that we
have not been able to resolve. Can you help?
First, I want to attach a penalty in a function within a program, so
for example, I always want x > xo. The number x is a real. I want to write
((x - xo)^2)^(.5) - (x - xo) which is 0 for x nonnegative and greater than
0 for x negative. The problem is Mathematica automatically simplifies this
algebra. Is there a way to prevent that?
I can only suggest how these problems are solved using MACSYMA. Perhaps
Mathematica has similar features. MACSYMA is quite careful about assumptions
like SQRT(X^2) -> ABS(X), and has a data base for storing facts about
symbolic variables. It helps in this case:
(D1) ABS(X0 - X) + X0 - X
(C2) ASSUME(X-X0 > 0);
(D2) [X > X0]
(C4) FORGET(X-X0 > 0);
(D4) [X > X0]
(D5) ABS(X0 - X) + X0 - X
(C6) ASSUME(X-X0 < 0);
(D6) [X0 > X]
(D7) 2 X0 - 2 X
(C8) FORGET(X-X0 < 0);
(D8) [X0 > X]
The MACSYMA data base can store many other types of properties and use them
in calculuations. For example consider the greatest integer function ENTIER:
The second, more substantial question is the reason the first came up.
It seems Mathematica can not use its problem solving techniques, either
Solve or FindRoot, over conditional statements. For example,
f(x) = x if ....
f(x) = x^2 otherwise.
Writing such a conditional with If or Which, then FindRoot can not
solve because it can not compute the derivatives. Is there a way around
this other than calculating maximization conditions separately and then
rewriting a new conditional? It seems like an easy fix within the
program if it truly is a bug.
The real issue on this second question is the construction of a constrained
maximization or Lagrangian problem. It seems clumsy, but I have had to
solve each f(x) = x, etc. and then test the "if" statement. This wastes
time and I lose any numerical value for the Lagrangian weight on the
constraint. Do you have suggestions?
Regards, Dallas Burtraw
Dallas_Burtraw at um.cc.umich.edu
MACSYMA's ROOT_BY_BISECTION command handles functions, including compiled
user-defined functions. The functions can include logical operations like
conditional branching (if-then) statements. Example:
(C1) F(X):=IF X > 0 THEN 2*(X-3) ELSE 3*(X-3);
(D1) F(X) := IF X > 0 THEN 2 (X - 3) ELSE 3 (X - 3)
Computer Aided Mathematics Group
email: petti at symbolics.com
Prev by Date:
Quaternions in Mathematica?
Previous by thread:
Next by thread:
Quaternions in Mathematica?