Search code examples
plotsymbolsnumericmaplesymbolic-math

Maple plot of algebraic expression


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!


Solution

  • 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.