0

If I write in Maple

AC := Amp*sin(2*Pi/T*t);

then I am able to see the expression in algebraic way. But I can't plot it because T is unset (plotting against t, of course).

If I write

T := 100e-6; 
AC := Amp*sin(2*Pi/T*t);
plot(AC, t=0..1e-3);

then I can plot it, but the expression is shown with numbers but not symbols.

My question is the following: If there is a way to nicely combine these both desires? So

  1. to have the variables declared,
  2. to have the expression written in symbols,
  3. to have it plotted.

I know that it is possible to write the expression firstly and then add its parameters. It work for small worksheets. But what to do if I have a 5-8-pages job and want to localize the variables in the beginning of the document (not to look for them everywhere)?

Thank you!

Andrew
  • 201
  • 1
  • 3
  • 10

1 Answers1

1

If you put equations for the parameters in a list (assigned earlier in the worksheet) then you can use so-called 2-argument eval whenever you want to instantiate your symbolic expressions with those values.

For example, at the top of the worksheet you could have something like,

params:=[T=100e-6,Amp=33.0,parB=2.3,parC=-0.9];

and then later on your can still create new expressions containing unassigned symbols T, Amp, etc.

AC := Amp*sin(2*Pi/T*t);  

                                        2 Pi t
                          AC := Amp sin(------)
                                          T

And then, whenever you wish to use those particular values,

plot(eval(AC,params), t=0..1e-3);

That last command succeeds because the 2-argument eval call acts liks so,

eval(AC,params);

                       33.0 sin(20000.00000 Pi t)

Even after that plot call, you can still use unassigned T, etc, in new symbolic expressions.

Hope that helps.

acer
  • 6,671
  • 15
  • 15
  • Thanks a lot, this does really works! However, I wasn't able then to create "encapsulated" params: params := [T = 0.100e-3, omega = 2*Pi/T, Amp = -.9]; AC := Amp*sin(omega*t); plot(eval(AC, params), t = 0 .. 0.1e-2). This didn't work. Any ideas? (sorry, I dont know how to make formatting in comments) – Andrew Jan 22 '13 at 09:20
  • 1
    Either use subs with the equations *not* in a list and rely on careful order of defns, or use a double layer of eval. Eg. p:=[T=.1e-3,A=-.9];v:=[om=Pi/T];AC:=A*sin(om*t);plot(eval(eval(AC,v),p),t=0..0.001); OR p:=[om=Pi/T,T=.1e-3,A=-.9];AC:=A*sin(om*t);plot(subs(op(p),AC),t=0..0.001); – acer Jan 22 '13 at 13:28