nm

8552 Reputation

19 Badges

13 years, 28 days

MaplePrimes Activity


These are questions asked by nm

When I do

restart:
alias(DS=DynamicSystems):
sys:=DS:-TransferFunction(5*s/(s^2+4*s+25)):
DS:-BodePlot(sys,output=dualaxis);

I get nice small plot.  with no outer frame filling the whole window



But if I just do

DS:-BodePlot(sys);

The plot is too large. So I tried the size option, but all what this did is reduce the plot size, but left the outer frame filling the whole window:

DS:-BodePlot(sys,size=[400,300]);

 

Is there a way to get the above plot, but either without the outer frame, or have the outerframe fit correctly around the plots?

Maple 18 on window 7

 

Here is one example:

restart;
alias(DS=DynamicSystems):
zeros :=[-1,-2]:
poles :=[0,-4,-6]:
gain  :=5:
sys   :=DS:-TransferFunction(zeros,poles,gain):

now sys above is a transfer function "object". But how would one go about extracting its properties? For example, I'd like to read the actual rational polynomial in s that represents the transfer function, which is embedded inside this oject, but I am not able to find an API to read it. I can only print it to the screen :


DS:-PrintSystem(sys);

But I'd like to assign the  "tf" printed above (the rational polynomial) into a seaprate variable, so I can extract the numerator and denominator if I want to. I have looked and not able to see a way to read this out. I just started learning this package.

Any idea how to look into these system objects? This does nothing:

o:=DS:-PrintSystem(sys);
whattype(o);
o[1];

Using Maple 18. I am looking for a programmable approach, using code. Not a click and point and menu based solution.

 

According to help here  on display, it says "The options parameter can include plot options as described in the plot/option "  and when  I go to the plots/option I see legend there. But when I try to use it, I get an error that plots:-display does not accept the legened option.

I am generating 2 plots, and use display() to show them on one axes. But need to add a legend as well. Is there a correct way to do this? 

restart:
with(DynamicSystems):
with(plots):
sys := TransferFunction(1/(s^2+0.2*s+1)): 
p1:=ResponsePlot(sys, Step(),duration=50,color=red):
p2:=ImpulseResponsePlot(sys,50);
display([p1,p2],axes=boxed, title=`step and impulse reponses`,legend=["step","impulse"]);

Now if I add legend, it fail

display([p1,p2],axes=boxed, title=`step and impulse reponses`,legend=["step","impulse"]);

I am sure I am doing something wrong. How to add legend to display? I can't use plot([...]) since the plots are allready generated by other Maple functions.

 

 

One can write 

restart;
alias(C=binomial);
C(4,2);

or

restart;
C:=binomial;
C(4,2);

and then both work the same. In the first case, the replacement of "C" by "binomial" is done at parsing time before evluator gets hold of the code, while in the second case, the replacement is done at run-time (evaluation).

So alias will be more efficient and more safe, I assume.

Is that all there is to it, or are there other more subtle and important reasons to use alias vs. :=  when one want to bind long name to smaller ones to save on typing.

 

I am newbie in Maple, and trying to understand when to use operator `if` as I see in some code vs. normal if. This is in context if using map()

I noticed I can write

A:=[seq(i,i=1..10)];
f:=x->x^2;
map(x->`if`(x<5,f(x),NULL),A);

or

map(x->if x<5 then f(x) fi,A);

And they both work the same. When should one use `if` vs. if? with the case of `if` I had to give a third argument NULL for the else part, while with using direct "if", I did not have to give the "else" part.

Also, suppose I want to use  IF .. THEN .. ELIF ... FI, then how would this be done using the operator syntax? in normal "if", I can write

A:=[seq(i,i=1..10)];
f:=x->x^2;
map(x->if x<5 then f(x) elif x=5 then x else x-1 fi,A);

Actually if I understand better when `if` is meant to be used vs. where the normal "if", I might understand more its use. 

 

ps. I did look at the help here but did not see it recommend when to use over the other (unless I overlooked it)

 

 

 

 

First 152 153 154 155 156 157 158 Last Page 154 of 164