List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] Creating new names
| [MUG] Creating new names |
|
Author: Bob McElrath
Posted: Wed, 1 May 2002 00:19:01 -0500
|
>> From: Bob McElrath "mcelrath"
I wish to create new global names inside a procedure, and I'm finding
experimentally that there are often several names defined by maple where
I want only one, usually with zero to two tilde's on the end.
I have tried every combination I can think of using evaln, eval, ||, and
assume(), but nothing seems to work.
Essentially what I want to do is inside a procedure, if a variable is
complex, convert it to a real representation like:
realrep := proc(EX, x)
local myEX;
myEX := EX;
if(is(x, complex)) then
assume(r||x, real);
assume(i||x, real);
myEX := subs(x=r||x+I*i||x, myEX);
fi;
return myEX;
end;
> assume(x, complex);
> realrep(x^2+y*3*x, x);
2
(rx~~ + I ix~~) + 3 y (rx~~ + I ix~~)
> is(rx, real);
FAIL
> is(ir, real);
FAIL
As you can see this procedure created the symbols rx~~ and ix~~.
Normally when you assume(x, real), it creates a symbol x~. (note one
less tilde)
How can I do this?
Cheers,
-- Bob
Bob McElrath ()
Univ. of Wisconsin at Madison, Department of Physics
|
| [MUG] Re: Creating new names |
|
Author: Maple User Group
Posted: Mon, 6 May 2002 13:56:40 -0400 (
|
>> From: Maple User Group "maple_gr"
On Wed, 1 May 2002, Bob McElrath wrote:
> I wish to create new global names inside a procedure, and I'm finding
> experimentally that there are often several names defined by maple where
> I want only one, usually with zero to two tilde's on the end.
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Wed, 1 May 2002 14:44:34 -0700 (PDT)
From: Robert Israel "israel"
To: "maple-list"
Subject: Creating new names
The problem seems to be that when an assumed variable name is converted to
a string, it has the trailing tilde (even if you set the Assumed Variables
option to "No annotation": that only affects how things are printed).
> assume(z, complex);
convert(z, string);
"z~"
Well, to remove the extra tilde you could do something like this:
> notilde:= a ->
StringTools[Remove](evalb@rcurry(`=`,"~"),a);
[ this is in Maple 7: it isn't too hard to program a version for previous
releases where StringTools doesn't exist ]
and then in your procedure:
> realrep := proc(EX, x)
local myEX, xp, rx, ix, r, i;
myEX := EX;
if(is(x, complex)) then
xp:= notilde(x);
rx:= cat(r,xp);
ix:= cat(i,xp);
assume(rx,real);
assume(ix,real);
myEX:= subs(x=rx+I*ix, myEX);
fi;
return myEX;
end;
Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Sun, 05 May 2002 18:31:01 +0200
From: Helmut Kahovec "helmut.kahovec"
To: "maple-list"
Subject: Creating new names
The following Maple7 session might help you. Note that I have set
'Assumed Variables' to 'No Annotation' in the 'Options' menu.
> restart;
> realrep:=proc(expr,x)
if is(x,complex) then
assume(r||x,real,i||x,real);
eval(expr,eval(x)=r||x+I*i||x)
else
expr
end if
end proc:
> assume(x,complex);
> is(r||('x'),real),is(i||('x'),real);
FAIL, FAIL
> is(rx,real),is(ix,real);
FAIL, FAIL
> realrep(x^2+y*3*x,'x');
2
(rx + I ix) + 3 y (rx + I ix)
> is(r||('x'),real),is(i||('x'),real);
true, true
> is(rx,real),is(ix,real);
true, true
Kind regards
Helmut
|
Previous by date: [MUG] Re: Finding the maximum value of a function over a rang e, Willard, Daniel Dr DUSA-OR
Next by date: [MUG] FW: Position at WMI, L Bernardin
Previous thread: [MUG] Re: Swap hunter, Maple User Group
Next thread: [MUG] FW: Position at WMI, L Bernardin
|