Hi,
I'm trying to plot a simple function of K*Cos(w1*t)+K*Cos(W2*t)+K*Cos(W3*t) in frequency domain using Maple.
Y-axis can be the amplitude and X-axis is frequency domain in radian.
I could use Fourier transform to conver the time domain to frequency domain function.
But,
Since the w1, w2, and w3 are undefined values, I don't know how I could draw it in symbolc way in frequency domain.
Here is my assumption for w1, w2, and w3.
w2-w1 not equal to w3-w2
They could certain frequencies in positive.
K is a positive constant.
I expect a plot as following:
Amplitude
^
|
| | | |
| | | |
----------|-------w1----w2--w3----------> w [Rad/sec]
As seen, w1, w2, and w3 has a different interval and
Dirac pulse at w1, w2 and w3 domain with an amplitude of K.
I have no idea how I could implement this symbolic plot in Maple.
Should I use some assumption statement? or programming??
Please help.
Thanks,
An example
For example,
f:=(cos(t)+cos(3*t)+cos(4*t))/Pi: S:=inttrans[fourier](f,t,w); S := Dirac(w + 4) + Dirac(w - 3) + Dirac(w + 3) + Dirac(w - 4) + Dirac(w + 1) + Dirac(w - 1) F:=S->map(x->plottools[line]([-op([1,2],x),0],[-op([1,2],x),1]),[op(S)]): plots[display](F(S),color=blue, tickmarks=[[-4="-w3",-3="-w2",-1="-w1",1="w1",3="w2",4="w3"],[0=0]], labels=[`w[Rad/sec]`,Amplitude],view=[-6..6,0..1]);I wonder what happened with -w1 (Classic Maple plotting specifics?) Font also could look better.
See also Plotting the Dirac Function thread.
If you are interested in drawing arrows at the end of the axes and putting labels there, see How to control the thickness of axes and tickmarks thread.
____________
Alec Mihailovs
http://mihailovs.com/Alec/
An excellent example!
Hi,
Thanks a lot for the quick reply!
and the example is awesome!
Yet w1,w2, and w3 are prefinded as 1, 3, and 4.
Then the plot is replaced with the symbol in X-axis.
Can we also specify amplitude of X in a symbol of K?
i.e) K*Cos(w*t)
Amplutude can be represented in the value of K.
Let's say we have arbitary w1, w2, and w3 values.
Is there another way to draw the symbolic plot rather than using
the predefined numbers of 1, 3, and 4??
Thanks,
FYI) In my case, I saw -w1 in plot.
Maybe the font issue..
Other ways
There is no other way, in general, to plot symbolic values (except choosing numbers other than 1, 3, 4), plot is a numerical procedure in Maple. K can be added to the tickmarks; for example, 1=K after 0=0, and view of the y-axis in this case can be increased to, say, 0..1.5 instead of 0..1 - you can experiment to find a better looking value. By the way, according to Maple calculations, it should be K*Pi instead of K, but that depends on the units.
P.S. Did you use Classic Maple or Standard? What version?
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Good advice!
I got it.
I thought there is a way to draw the plot in symbolic ways.
I used classic Maple 10.
Thanks for comments!
Can make the same plot in Matlab?
Hi,
Using Matlab, can I draw the same plot as Maple?
i.e) same labeling in X-axis as Maple (w1, w2, w3...)
I heard that Matlab is also using Maple kernel with some limitations.
Thanks!
Can make the same plot in Matlab?
Yes you can. If you are using the professional version of Matlab, then the Maple engine is available as a toolbox. The Mathworks has two versions. One is a basic version and the other has more symbolic functions associated with it.
If you are using the student version of Matlab, it should come with a basic version of the symbolic toolbox already.
Regards,
Georgios Kokovidis
Then how could I use the Maple command in professional version?
Hi,
I'm using the Matlab pro version.
Can I just copy and paste the Maple command?
or should I specify that the command is Maple in some ways?
Thanks!
Matlab Professional Version
Do you have a copy of the symbolic toolbox for Matlab? If not you can not do this. Matlab is stricly a numeric package. You have to substitute numbers for your variables and then perform an fft, using the fft function. Then you can plot it using the plot command. In Matlab, help plot will display the help commands available for the plot function and help fft will display the help commands for the fft function. At the Matlab prompt, if you type fftdemo, you will see and example of the fft command in action. If you want to see the code used for the fftdemo, you can display it by typing the following at the Matlab prompt:
>> help plot
>> help fft
>> fftdemo
>> type fftdemo
Regards,
Georgios Kokovidis
With a different amplitude of signal?
Hi,
Does anyone know why the following doesn't work?
I just changed amplitude of cos(t) to be 2cos(t).
Somehow Maple doesn't like the expression.
Error, (in unknown) improper op or subscript selector
Any idea?
How can I tickmarks for value in Y-axis?
f:=(2*cos(t)+cos(3*t)+cos(4*t))/Pi:
S:=inttrans[fourier](f,t,w);
F:=S->map(x->plottools[line]([-op([1,2],x),0],[-op([1,2],x),1]),[op(S)]):
plots[display](F(S),color=blue,
tickmarks=[[-4="-w3",-3="-w2",-1="-w1",1="w1",3="w2",4="w3"],[0=0]],labels=[`w[Rad/sec]`,Amplitude],view=[-6..6,0..5]);
Thanks!
An example
All terms should be homogeneous for using map. That means that coefficients should be added to every term. In this case, the formula from my earlier post in Plotting the Dirac Function thread, that I cited above, can be used,
f:=(2*cos(t)+1.5*cos(3*t)+3*cos(4*t))/Pi: S:=inttrans[fourier](f,t,w); S := 1.500000000 Dirac(w - 3.) + 2. Dirac(w + 1.) + 3. Dirac(w + 4.) + 1.500000000 Dirac(w + 3.) + 2. Dirac(w - 1.) + 3. Dirac(w - 4.) F:=S->map(x->plottools[line]([-op([2,1,2],x),0],[-op([2,1,2],x),op(1,x)]),[op(S)]): plots[display](F(S),color=blue, tickmarks=[[-4="-w3",-3="-w2",-1="-w1",1="w1",3="w2",4="w3"], [0=0,1.5=K2,2=K1,3=K3]], labels=[`w [Rad/sec]`,Amplitude],view=[-6..6,0..4]);__________
Alec Mihailovs
http://mihailovs.com/Alec/
How can I plot positive side only? and spcifying fram and points
Hi Alec,
From the above example,
After FourierTransform, w has both positive and negative sides.
f:=(2*cos(t)+1.5*cos(3*t)+3*cos(4*t))/Pi:
How can I plot positive side w only?
Which means...w1 = 1, w2 = 3, w3 = 4 with amplitude of 2, 1.5, and 3 accordingly.
Also,
In plots, how can I specify frame and numpoints?
Here is an example from you.
http://beta.mapleprimes.com/forum/plotting-the-dirac-function
In the case, you specified the framed and numpoints...
plot([s,0], t=0..3000/fc, title="AM Waveform (fm = 4kHz)",
titlefont=[HELVETICA,16], font=[HELVETICA,12],
labels=["Time (s)", "Amplitude"], labeldirections=[HORIZONTAL,VERTICAL],
color=[red,black], axes=framed, numpoints=500);
S := inttrans[fourier](s,t,f);
Thanks,
View
Choose view that doesn't include vertical lines with negative x, something like view=[0..6,0..1.5]. I don't think that I chose framed axes and 500 numpoints - I just modified that guy's example. They can be added to the options in the display command. Many other options can be added, see ?plot,option
__________
Alec Mihailovs
http://mihailovs.com/Alec/
WOW~ Amazing!
Thanks a lot for quick reply!
Seems you are the Maple guru.
I'm just enjoying Maple power as a beginner... :-)
Thanks again.
"op" statement in plottools makes me very confusing :-)
Can you explain the "op" statement in more easy ways?
or any helpgul websites??
Thanks,
op is a sequence of terms
op is a sequence of terms, type ?op in Maple for examples. If it used with indexes, such as op(1,a) or op([2,1,2],a), then the corresponding subterms are selected. In the last example,
s:=op(S); s := 1.500000000 Dirac(w - 3.), 2. Dirac(w + 1.), 3. Dirac(w + 4.), 1.500000000 Dirac(w + 3.), 2. Dirac(w - 1.), 3. Dirac(w - 4.) op(1,s[1]); 1.500000000 op([2,1,2],s[1]); -3.?map is also useful in this context.
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Thanks for the usuful tips! Reference books?
Thanks for the comment!
By the way, do you know good reference books to learn Maple?
Particulary in communication area.
Manuals
Many people recommend manuals and guides that come with Maple. I've never read them in full, so I can't tell how good they are actually are. Those fragments that I read (mostly in the Advanced Programming guide), were useful. Help pages are often useful, you can type something like ?plot and read a short description of it, with examples, then follow links at the bottom of the page, or at the top in Classic Maple and from the left hand side in Standard Maple. New user's tour (in the Help menu) can be useful. Then, some of tutorials and PowerTools in Maple Application Center can be used for some specific topics, such as Calculus, Abstract Algebra, or Differential Equations.
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Got it! Mathemetica evaluation is different from Maple?
Thanks for the guide!
In Mathematica, I typed the following expression.
Cos(w1 t)/Cos(1)
Then it gives me w1
In Maple format, I typed
cos(w1 t)/cos(1)
Then it give me cos(w1 t)/cos(1)
Why is it different?
How can I have the same result in Maple?
Is there other ways to extract frequency domains?
i.e) cos(w1*t+w2*t)
I want to save w1+w2 into an array to post-processing.
Thanks!
Functions in Mathematica
In Mathematica, you have to use square brackets for function arguments, Cos[w1 t]/Cos[1].
Extracting w1+w2 from cos(w1*t+w2*t) can be done, for example, as
a:=cos(w1*t+w2*t): coeff(op(a),t); w1 + w2__________
Alec Mihailovs
http://mihailovs.com/Alec/
What a simple !
Thanks!
What a simple way...
What about with amplitude?
** FYI. finally I changed my username :)
An example
Another example,
A:=f->eval(indets(f,function),[cos=(x->x),t=1]): f:=(2*cos(t)+1.5*cos(3*t)+3*cos(4*t))/Pi: A(f); {1, 3, 4} a:=3/4*cos(w1*t+w2*t): A(a); {w1 + w2}or
B:=f->map(coeff,map(op,indets(f,function)),t): B(f); {1, 3, 4} B(a); {w1 + w2}__________
Alec Mihailovs
http://mihailovs.com/Alec/
Impressive functions!
Wow!
As I come to know Maple more, it is more interested!
Thanks for the help!
Can I remove the "{}"?
As seen an example before, can I get rid of the "{ }"? and disp w1+w2 only? Thanks,op
Just op it.
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Comments on Maple, Mathmetica, and Matlab?
Many similar Math softwares ... :-)
Mathematica, Maple, Matlab...
What are main pros and cons between them?
Thanks,
Maple, Mathematica, and Matlab
Maple and Mathematica are both symbolic and numerical systems, but Matlab's numerics is usually better. Matlab uses Maple kernel in its Symbolic toolbox. If you are a student, it is good to try all of them - student versions are very cheap. Comparing them doesn't have much sense - it is like asking what is better, MS Word, or MS Excel - each of them is good for its own purpose.
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Seems I need more exercise :)
Thanks for the advice!
Seems I need more exercise with the Math tools :-)
Finding MAX and MIN under assumption?
Let's say we have several combination of unknown values(w1, w2, w3) in an array.
array[0] = w1+w2-w3
array[1] = -w1+2*w2+w3
array[1] = 2*w1-w2-2*w3
array[1] = -w1+w2-w3
array[1] = -w1+w2+w3
Assumptions are as following:
w1, w2, and w3 > 0
w3 > w2 > w1
w3 - w2 not equal to w2 - w1
w2 - w1 > w3 - w2
How can I find MAX and MIN from the above array under the assumptions?
Is it possible without using a real number for w1, w2, and w3?
Thanks,
max and min under assumptions
a:=w1+w2-w3,-w1+2*w2+w3,2*w1-w2-2*w3,-w1+w2-w3,-w1+w2+w3: b:=w3>w2,w2>w1,w1>0,w2-w1>w3-w2: max(a) assuming b; -w1 + 2 w2 + w3 min(a) assuming b; 2 w1 - w2 - 2 w3_________
Alec Mihailovs
http://mihailovs.com/Alec/
Facing an error with array usage?
I modified the above code to use an array little bit:
a[1]:=w1+w2-w3:
a[2]:=-w1+2*w2:
a[3]:=2*w1-w2-2*w3:
a[4]:=-w1+w2-w3:
a[5]:=-w1+w2+w3:
b:=w3>w2,w2>w1,w1>0,w2-w1>w3-w2:
max(a) assuming b
I faced the following error:
;Error, (in assuming) when calling 'simpl/max'.
Received: 'arguments must be of type algebraic'
Any suggestion?
Thanks,
arrays and tables
There are many different data structures in Maple (in contrast with Mathematica and Matlab). What you are doing, doesn't create an array, it creates a table,
type(a,array); false type(a,table); truemax and min operate on sequences, not tables or arrays, so to use them, one should extract a sequence first,
max(op(convert(a,list))) assuming b; -w1 + w2 + w3The answer is different because you changed a[2].
If you would like to work with Arrays, then the difference is that the size of the Array should be specified before assigning. Something like
Then, after assigning values, max and min can be found either as above, or as
max(seq(i,i=a)) assuming b; -w1 + w2 + w3Sorting in this case can be done as
sort(a,is@`<`) assuming b; [2 w1 - w2 - 2 w3, -w1 + w2 - w3, w1 + w2 - w3, -w1 + 2 w2, -w1 + w2 + w3] type(%,Array); trueThat seems to be undocumented.
_________
Alec Mihailovs
http://mihailovs.com/Alec/
Can I sort the numbers under assumption?
We just found how to find max and min.
What about sort?
Can we sort the numbers in "a" variable?
Using an array of "a" variable.. (ie. a[0], a[1] ...)
Thanks,
Sorting with assumptions
For sorting you have to provide a sorting procedure. For example,
sort(convert(a,list),is@`<`) assuming b; [2 w1 - w2 - 2 w3, -w1 + w2 - w3, w1 + w2 - w3, -w1 + 2 w2, -w1 + w2 + w3]__________
Alec Mihailovs
http://mihailovs.com/Alec/
Amazing Maple!
Wow~
The way Maple handles the symbols is just amazing!!!
Really appreciated for dedicated replies!
Good questions
You ask good questions, in the correct form, and with good examples, so you get a lot of replies (unlike some other people on this site.)
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Finding array index# based on Sorted data? and plot?
We have found how we could sort unknown values based on assumptions. Now how can we find index from sorted data? As shown in an example before, we have an array if "a": a[1]:=w1+w2-w3: a[2]:=-w1+2*w2: a[3]:=2*w1-w2-2*w3: a[4]:=-w1+w2-w3: a[5]:=-w1+w2+w3: b:=w3>w2,w2>w1,w1>0,w2-w1>w3-w2: Sort results came out using "sort" function before as following: [2 w1 - w2 - 2 w3, -w1 + w2 - w3, w1 + w2 - w3, -w1 + 2 w2, -w1 + w2 + w3] How can I display index# of sorted data? Its result should be something like that. [3, 4, 1, 2, 5] As seen, index# from the array should be displayed according to sort. You also mentioned before, to draw plot, data should be real numbers? We have sorted numbers and assumptions, can I draw a plot with the data? or For plotting, should I plug in a real number for w1, w2, and w3? i.e) plug-in unknown values of an array "a". S := Dirac(w - a[1]) + Dirac(w - a[2]) + Dirac(w - a[3]) + Dirac(w - a[4]) + Dirac(w - a[5]) We know where the array of "a" is located based on sorted data and assumptions. Possible to plot the "S" function? or should values have to be real numbers? Thanks,Sorting of indices
It is possible to find an index of an expression, but that requires searching. It is easier just to sort indices,
sort([$1..5],(i,j)->(is(a[i]<a[j]) assuming b)); [3, 4, 1, 2, 5]And yes, for plot you have to substitute some numerical values (or at least values that can be evaluated to numeric), plot is a numerical procedure.
Also, first 2 values, a[3] and a[4] are negative, and the 3rd value, a[1] can be either positive or negative. If you do fourier transform of cosines, they will also give positive peaks, and if you display only positive part, then the order of them will be different than in sorting just a[i].
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Thanks for the help! Facing another challenge?
Thanks for quick help! I was thinking "if" statement to extract index# of the array from sorted data. Another challenge to plot Dirac function! Let's use our "a" array: a[1]:=w1+w2-w3: a[2]:=-w1+2*w2: a[3]:=2*w1-w2-2*w3: a[4]:=-w1+w2-w3: a[5]:=-w1+w2+w3: Using assumptions, we now know what the max, min, and order is. Let me define w1, w2, and w3 with a real number to plot Dirac function. w1:=50 w2:=60 w3:=65 As seen, the number well falls into our assumptions. Let me define Dirac function using the array. S := 20/7*k*Dirac(w - a[1])+2*k*Dirac(w - a[2])+ 10*k*Dirac(w - a[3])+1*k*Dirac(w - a[4])+8/3*k*Dirac(w - a[5]) Let's define the symbol k for drawing plot k:=1 # I want to display k symbol using tickmarks in plot Expected plot may be like this because we know order by sort: Amplitude ^ | | | | | | | | | | | | | -----|-------+-------+--------+--------+---------+------> w [Rad/sec] 2w1-w2-2w3 -w1+w2-w3 w1+w2-w3 -w1+2w2 -w1+w2+w3 Its amplitude in X-axis could be different accordingly. but should have label with "k". ie) If amplitude is 5/3*k, plot display the 5k/3. I now face a challenge how I define the "tickmarks" and "view" automatically by reading the information of array and amplitude. The "tickmarks" and "view" in plots option should be changed accordingly based on real numbers of w1, w2, and w3..and amplitudes. The "view" range for X and Y-axis could be found min and max function using amplitude and real w numbers. The "tickmarks" could be also defined automatically using real numbers and its w function. i.e) With the w1, w2, and w3 real numbers, w1+w2-w3 can be replaced with 50+60-65 = 45 So "tickmarks" for 45 should represent w1+w2-w3 To make a more universal program, can I generate the "plots" function with auto generated "tickmarks" and "view"? so that..whenever I change w1, w2, and w3 numbers and amplitudes, Plot should also be changed accordingly rather than changing the "tickmarks" and "views" in "plots" manually. Seems this becomes another challenge for me :-) Thanks! FYI, The following is the previous "plots" example: plots[display](F(S),color=blue, tickmarks=[[-4="-w3",-3="-w2",-1="-w1",1="w1",3="w2",4="w3"], [0=0,1.5=K2,2=K1,3=K3]], labels=[`w [Rad/sec]`,Amplitude],view=[-6..6,0..4]);An example
You don't need sorting for that. It can be done as
aplot:=(a,k,A,K)->plots[display]( seq(plottools[line]([A[i],0],[A[i],K[i]]),i=1..nops(a)), tickmarks=[[seq(A[i]=StringTools:-SubstituteAll( sprintf("%a",a[i]),"*",""),i=1..nops(a))], [seq(K[i]=StringTools:-SubstituteAll( sprintf("%a",k[i]),"*"," "),i=1..nops(a))]]): a:=[w1+w2-w3, -w1+2*w2, 2*w1-w2-2*w3, -w1+w2-w3, -w1+w2+w3]: k:=[20/7*K,2*K,10*K,K,8/3*K]: aplot([op(a),op(-a)],[op(k),op(k)], eval([op(a),op(-a)],[w1=50, w2=60,w3=65]), eval([op(k),op(k)],K=1));The problem with that is that the tickmarks overlap.
It looks slightly better if you plot only positive peaks,
pos,neg:=selectremove(i->eval(a[i],[w1=50, w2=60,w3=65])>0,[$1..5]); pos, neg := [1, 2, 5], [3, 4] aplot([seq(a[i],i=pos),seq(-a[i],i=neg)], [seq(k[i],i=pos),seq(k[i],i=neg)], eval([seq(a[i],i=pos),seq(-a[i],i=neg)],[w1=50, w2=60,w3=65]), eval([seq(k[i],i=pos),seq(k[i],i=neg)],K=1));You can make that into a procedure to try other values of w1,w2, and w3,
The previous plot can be obtained then as f(50,60,65).
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Ummm ... Interesting! but X-axis lable and pos function?
Again impressive codes!!! Another question... When I run Maple using your code (I just copy and pasted), I don't see proper labeling for X-axis. How can I display in symbols in X-axis. i.e) "45" label should be replaced with "w1+w2-w3" label. If I use "pos" and "neg", combination of w1, w2, and w3 could be negative under certain numbers. i.e) w1 = 1, w2 = 8, w4=10 w1+w2-w3 becomes -1, which is negative value and could be removed by "pos" function but I need to plot the number. As described before, Since I have assumed that my equation is just positive side Dirac function, can I draw the plot based on the assumption? so that plot can be drawn whatever result from combination of w1, w2, and w3 is positive or negative. Here is my modified code for plot under the assumption. As seen, I removed the "op(-a)" from the "aplot" function so that symmetry plots don't show up. plot:=(a,k,A,K)->plots[display]( seq(plottools[line]([A[i],0],[A[i],K[i]]),i=1..nops(a)), tickmarks=[[seq(A[i]=StringTools:-SubstituteAll( sprintf("%a",a[i]),"*",""),i=1..nops(a))], [seq(K[i]=StringTools:-SubstituteAll( sprintf("%a",k[i]),"*"," "),i=1..nops(a))]]): a:=[w1+w2-w3, -w1+2*w2, 2*w1-w2-2*w3, -w1+w2-w3, -w1+w2+w3]: k:=[20/7*K,2*K,10*K,K,8/3*K]: aplot([op(a)],[op(k),op(k)], eval([op(a)],[w1=50, w2=60,w3=65]), eval([op(k),op(k)],K=1));A comment
You, probably, didn't try using f procedure. It plots positive parts. Choosing only op(a) as you did, doesn't do that. Just an example, a=[-5,-3,1,2,4]. Choosing op(a) does nothing with it. Originally I used both op(a) and op(-a) to include all positive and negative parts. then I used pos and neg to separate positive values from negative, leave positive values unchanged and change the sign of negative values. Another option would be to use
absfor that, but then we would need another procedure for handling symbolic values, and using pos and neg avoids that.If you see numbers on the x-axis, that means that you assigned your variables. You can restart (either click the restart button, or enter
restart;), and execute needed commands again. I see symbolic values on both axes.__________
Alec Mihailovs
http://mihailovs.com/Alec/
Matching with Sort result? Improved Plot options?
I made a tiny mistake. That is why proper label for X-axis didn't show up. :-) I now can see proper labels. ======> Question 1: As described the above, you assmed a=[-5,-3,1,2,4]. Then without removing the op(-a) as seen in my code, how could I modify your code to plot -5,-3,1,2,4 only rather than plotting its symmetry values 5,3,-1,-2,-4 ? ======> Question 2: when we draw "positive" side plot using "pos", its first point is close to Y-axis. How can I make proper distance from Y-axis from the first point? Using "view" option ??? =====> Question 3: How can I count paticular numbers? ie) Let's assume we have the following data a:=[1, 1, 1, 3, 4, 7, 3.2, -1, -1, 5 1, -1]: How can I count how many both 1 and -1 has in the array? I expect to have 7 counts. =====> Question 4: I have a data such as: a:=[1,2,3,4,1,5,2,2]: As seen in the array, the number "1" has twice and "2" has three times. What I want is that (1) Find true or false from the array data. If any number is duplicated in the array, it is "true" otherwise "false" (2) Then find what number is duplicated. From the above example, duplicated numbers are "1" and "2". =====> Question 5: I made the following simple expression. restart: X:=array(1..12): for i to 12 do X[i]:=i: end do: print(X); nops(X); Its result came out: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] size:=1 How can I print the array size to be 12? Somehow using the "nops" doesn't give me a correct size. Let's assume the X is Table and not an array. In the case, how can I display number of contents in the table? i.e) for i to 12 do X[i]:=i: end do: print(X); nops(X); Its result: TABLE([1 = 1, 2 = 2, 3 = 3, 5 = 5, 4 = 4, 7 = 7, 6 = 6, 10 = 10, 11 = 11, 8 = 8, 9 = 9, 12 = 12]) size:=1 ** Still give me 1 for table size. I expect 12. ======> Question 6: I sorted the "a" array under assumptions and its result came out. Used code: a:=[w1+w2-w3, -w1+2*w2, 2*w1-w2-2*w3, -w1+w2-w3, -w1+w2+w3]: b:=w3>w2,w2>w1,w1>0,w2-w1>w3-w2:
Sort result becomes:
2*w1-w2-2*w3, -w1+w2-w3, w1+w2-w3, -w1+2*w2, -w1+w2+w3
If we plot original values (without symmetry values),
points in X-axis perfectly match with the sort result !! :-)
Let's assume we draw the plot in positive side only using your "pos" procedure.
Order of points in X-axis plot now becomes:
w1+w2-w3, w1-w2+w3, -w1+2*w2, -w1+w2+w3, -2*w1+w2+2*w3
As seen, its order is now different from the result by
previous "sort" function and the negative symbol becomes positive in positive plot.
How can I modify the previous "sort" command to match with the order of positive points and symbols in X-axis plot?
Thanks!
Answers
1. Yes, using op(a) plots [-5,-3,1,2,4], but it is not what you originally wanted - you wanted to plot positive peaks. Every number m gives 2 peaks - at m and at -m. So positive peaks in this example will be at [1,2,3,4,5]. The last procedure f in my post does that.
2. Yes, it can be done by using view option. Note however that in that case it is more likely that the tickmarks will overlap.
3. Using
numboccur,a:=[1, 1, 1, 3, 4, 7, 3.2, -1, -1, 5, 1, -1]: numboccur(a,{1,-1}); 74.(1) For example,
a:=[1,2,3,4,1,5,2,2]: f:=a->evalb(nops(a)<>nops({op(a)})): f(a); true(2)
ListTools:-FindRepetitions(a); [1, 2, 2]5. As I said a few times earlier, don't use arrays or tables; use lists or Arrays. The corresponding operations are op(2,eval(a)) for arrays - that gives a range, something like 1..5, and if you know that the first index is 1, then the number of elements can be obtained as op([2,2],eval(a)). For tables that can be done as nops(op(op(t))). For lists it's much more simple - just nops(a). For Arrays, ArrayNumElems(a) - one can easily see that the command was created during a transition period from old Maple names, short but cryptic, to new Maple names, similar to Mathematica names; if it was created earlier, it would be named nels; if it was created now, it would be, probably, named ArrayTools:-Main_AT:-ArrayInformation:-Main_AI:-BasicArrayInformation:-
`www.maplesoft.com/NumberOfArrayElements`.
6. It is not only pos, it is both pos and neg. It's not that simple. One way is to sort [op(a),-op(a)] and then choose the 5 top elements, but that doesn't work in this case, because the order can not be determined uniquely, mainly because of the closest to 0 element that can be either positive or negative. It is much easier to do for numerical values - using pos and neg and the same sequence constructed from them as in f (the last procedure in my post with plotting procedures.)
_________
Alec Mihailovs
http://mihailovs.com/Alec/
Impressive codes as always! Another challenge..
===> Question 1:
We have found number of occurance through the following:
a:=[1, 1, 1, 3, 4, 7, 3.2, -1, -1, 5, 1, -1]:
numboccur(a,{1,-1});
Without using for or other loop statements,
Can we print its index easily?
I expect to print the result as
1, 2, 3, 8, 9, 11, 12
As seen, index in the array is printed in order when number is 1 or -1.
Can we also print numbers in order when number is 1 or -1?
I expect to print the result as
1, 1, 1, -1, -1, 1, -1
As seen, its actual number is printed in order when number is 1 or -1.
===> Question 2:
I used the "Array" but not "array".
Here is an example code.
restart:
a:=Array(1..12):
for i to 12 do
a[i]:=i:
end do:
print(a);
nops(a);
I expect contents of
a is 1,2,3,4,5,6,7,8,9,10,11,12
But the code doesn't print contents of a properly.
I see the following message:
[1.12 1-D Array
Data Type: anything
Storage: rectangular
Order: Fortran_order]
Can you explan why the "print(a)" doesn't print contents of a?
I noticed when I change the Array size to be 5.
I was able to print the contents properly.
Does the Array have a limitation?
Thanks!
For example
1. For example,
a:=[1, 1, 1, 3, 4, 7, 3.2, -1, -1, 5, 1, -1]: select(x->abs(a[x])=1,[$1..12])[]; 1, 2, 3, 8, 9, 11, 12 seq(a[i],i=%); 1, 1, 1, -1, -1, 1, -12. The maximal size of an array displayed inline can be specified using interface(rtablesize). For example,
interface(rtablesize=infinity): a:=Array([$1..12]); a := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]And, as I said earlier, nops gives the number of elements of a list or a set, but for Arrays the following command should be used,
ArrayNumElems(a); 12or
Statistics:-Count(a); 12Also, if you clicked right mouse button on the output, you would see many operations available including the number of elements.
__________
Alec Mihailovs
http://mihailovs.com/Alec/
WOW~~~ I am amazed by Maple capabilities ;-)
Hi,
Thanks a lot for your help!!!
Finally I was able to finish a small project
on behavioral modeling of nonlinear system using Maple :-)
It would take forever without your help...!
You should open Maple classes or write a book :-)
Thanks again!
Happy Thanksgiving!!!
Congratulations and Happy Thanksgiving
Congratulations with finishing your project and Happy Thanksgiving!
I actually wrote a couple of Maple manuals and taught a Maple lab.
__________
Alec Mihailovs
http://mihailovs.com/Alec/
Dear Dr. Alec: Which one is
Dear Dr. Alec:
Which one is the book that you wrote?
Thanks
My old Maple page
If you are interested in my publications, the list of them (with links) can be found in my vita. Some Maple related stuff, beside my posts here, can be downloaded from my old Maple page (don't use Firefox for accessing it - use IE).
__________
Alec Mihailovs
http://mihailovs.com/Alec/