Fall 2007 Jairo Sinova Texas A&M University Maple Tutorial and Examples In Maple a command line or paragraph starts with > and it is executed whenever you hit return. In order to write a set of command paragraphs use the Shift+Return key to go to the next line. Every command must be followed by a semicolon (;) or a colon (:). The ; will show the result of the command and the : will not show it and simply execute it. The commands can be in a sequence within a line or in several lines, Maple does not distinguish this, it only cares about the ; and : demarcations. To start a program always start with the command " restart: " in order to clear the values previously assigned to all variables. Maple has many packages which you can read about in the help files but one of the ones that you are going to use a lot is plots so you should start also with the command " with(plots):". To learn Maple is it best to do it by seeing examples and keeping in mind that there are many ways of doing the same thing. Also, just like Mathematica, Maple can be picky about notation and how things are written , e.g. if it wants a ( ) then [ ] will not work and it will complain. It is best to look at the Help where it shows you examples of the usage of things. Below we show the folloing General notatation, s imple arithemtic, numerical values, and a ssigning expressions Defining functions and s olving algebraic equations Simple 2D plot Parametric 2D plot Animation of 2D plots through a single variable t More complicated 2D plots by creating a sequence of frames Simple 3D surface plots Parametric 3D line curves More complicated 3D plots by creating a sequence of frames (almost the same as 2D) Keep in mind that learning Maple has to be done by creating your own programs and putting them together by looking up examples within the help and the internet search engines. Below you can click on the arrow to expand the view in the subsectoin.
<Text-field style="Heading 1" layout="Heading 1">General notation, simple arithmetic, and assigning expressions</Text-field> LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2I1EhRic= restart: # anything to the right of the # is considered a comment 3+4^2; Pi+3; #computes numercal value of Pi+3, evalf stand for evlauate floating point. The 20 in the second form corresponds to the precission evalf(Pi+3);evalf(Pi+3,20); # % takes the value of the last executed command (%)^2; # assigns the expression a x^2+ b x +c to f. Note that this does NOT define an f(x) it simply says that f stands for such an expression. The := is what is used to assign f := a*x^2 + b*x + c; #solves the f=0 equation for x. solve(f,x); #we can also solve f=0 for a instead solve(f,a);
<Text-field style="Heading 1" layout="Heading 1">Defining functions and simple 2D plots</Text-field> g := (x,y) -> sin(x)*cos(y) + x*y; g(1,1); evalf(g(1,1)); h := x -> exp(-x^2); LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2I1EhRic= restart:with(plots): # simple 2D plot plot(x^2+x,x=-5..5); # you can also plot the functions that you have defined above h := x -> exp(-x^2); plot(h(x),x=-2..2); # there is also anther way, define the expression f:=exp(-(x-t)^2); t:=0; #I have put here the t to illustrate something below plot(f,x=-2..2); # you can do multiple plots (note that the functions are grouped in [f1,f2,f3,...] t:=1; plot([h(x),f],x=-3..3);
<Text-field style="Heading 1" layout="Heading 1">2D animation </Text-field> #one can animate something that depends parametrically on t (the command animate or plots[animate] are equivalent). You can animate by clicking on the figure and using the play buttons that appear above with the different options. The default number of frames is 16 so you want a smoother movie you have to increase this restart: with(plots):; f:=exp(-(x-t)^2); animate(f,x=-5..5,t=0..5,frames=50,color=green);
<Text-field style="Heading 1" layout="Heading 1">2D parametric plots</Text-field> #parametri plot where the x and y points of the curve are determined by a single time variable restart:with(plots): plot([cos(t),sin(t),t=0..1.5*Pi]);
<Text-field style="Heading 1" layout="Heading 1">2D plot of dots with a density wave </Text-field> restart:with(plots):roll:=rand(1..20):ppoints:=NULL:pove:=NULL:Dt:=2*Pi/50:pMove:=NULL: px:=Matrix(20): py:=Matrix(20): for i from 1 to 20 do for j from 1 to 20 do px[i,j]:=roll(); py[i,j]:=roll(); end do: end do: t:=0: for k from 1 to 100 do ppoints2:=NULL; ppoints:=NULL; t:=t+Dt; for i from 1 to 20 do for j from 1 to 20 do ppoints2:=[i+0.05*px[i,j]+0.3*evalf(cos(i+j-t)),j+0.05*py[i,j]+0.3*evalf(cos(i+j-t))]: ppoints:=ppoints,ppoints2: end do: end do: pFrame:=plots[pointplot]([ppoints],style=point,symbol=circle,color=blue,view=[1..20,1..20]): pMove:=pMove,pFrame: end do: plots[display](pMove,insequence=true); LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2I1EhRic=
<Text-field style="Heading 1" layout="Heading 1">2D animation of two circules moving in a circular orbits</Text-field> restart:with(plots): m1 := 50: m2 := 50: r1 := 10: r2 := m2*r1/m1: x1 := -r1*cos(theta): x2 := r2*cos(theta): y1 := -r1*sin(theta): y2 := r2*sin(theta): size := 1: animate({[size*cos(z) + x1, size*sin(z) + y1, z=-Pi..Pi], [size*cos(z)+x2, size*sin(z)+y2, z=-Pi..Pi]}, theta=0..2*Pi, frames=75, scaling=constrained,color=red);
<Text-field style="Heading 1" layout="Heading 1"><Equation executable="false" style="Heading 1" input-equation="" display="LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzZCLUkjbW5HRiQ2JVEiMkYnLyUsbWF0aHZhcmlhbnRHUSVib2xkRicvJStmb250d2VpZ2h0R0YxLUkjbWlHRiQ2JlEiREYnLyUnaXRhbGljR1EmZmFsc2VGJ0YvRjItSSNtb0dGJDYuUSJ+RidGL0YyLyUmZmVuY2VHRjovJSpzZXBhcmF0b3JHRjovJSlzdHJldGNoeUdGOi8lKnN5bW1ldHJpY0dGOi8lKGxhcmdlb3BHRjovJS5tb3ZhYmxlbGltaXRzR0Y6LyUnYWNjZW50R0Y6LyUnbHNwYWNlR1EmMC4wZW1GJy8lJ3JzcGFjZUdGTy1GNTYmUSphbmltYXRpb25GJ0Y4Ri9GMkY7LUY1NiZRI29mRidGOEYvRjJGOy1GNTYmUSJhRidGOEYvRjJGOy1GNTYmUSt0cmFqZWN0b3J5RidGOEYvRjJGOy1GNTYmUSZ1c2luZ0YnRjhGL0YyRjtGWEY7LUY1NiZRKXNlcXVlbmNlRidGOEYvRjJGO0ZVRjstRjU2JlEmcGxvdHNGJ0Y4Ri9GMi1JKG1mZW5jZWRHRiQ2JS1GIzYwLUY1NiZRKGFkYXB0ZWRGJ0Y4Ri9GMkY7LU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IrRidGL0YyRj9GQUZDRkVGR0ZJRksvRk5RLDAuMjIyMjIyMmVtRicvRlFGW3MtRiw2JVEiMUYnRi9GMkZocEZbcUYvRjItRjw2LlEiLEYnRi9GMkY/L0ZCUSV0cnVlRidGQ0ZFRkdGSUZLRk0vRlFRLDAuMzMzMzMzM2VtRictSSZtZnJhY0dGJDYoLUYjNilGZXEtRjw2LlExJkludmlzaWJsZVRpbWVzO0YnLyUlYm9sZEdGOi9GMFEnbm9ybWFsRidGP0ZBRkNGRUZHRklGS0ZNRlAtRmJvNiVGZXJGL0YyRmhwRltxRi9GMi1GIzYnLUYsNiVRJDEwMEYnRi9GMkZocEZbcUYvRjIvJS5saW5ldGhpY2tuZXNzR1EiMUYnLyUrZGVub21hbGlnbkdRJ2NlbnRlckYnLyUpbnVtYWxpZ25HRl91LyUpYmV2ZWxsZWRHRjpGaHBGW3FGL0YyRi9GMi8lJW9wZW5HUSJbRicvJSZjbG9zZUdRIl1GJ0Y7RjtGaHBGW3FGL0Yy</Equation></Text-field> <Text-field style="Heading 1" layout="Heading 1"></Text-field> The simulation of particle motion in this and the following Examples in this worksheet is achieved by creating a number of graphics that are then shown one after the next in a continuous fashion. The motion of a particle in two-dimensions is described by the vector r(t) = [x(t), y(t)], in the interval LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYkLUkjbW5HRiQ2JFEiMEYnL0Y2USdub3JtYWxGJ0Y+LyUvc3Vic2NyaXB0c2hpZnRHUSIwRidGPg== < t < LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1Z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c2xpYkdGJzYkLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic=, LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEoJkRlbHRhO0YnLyUnaXRhbGljR1EmZmFsc2VGJy8lLG1hdGh2YXJpYW50R1Enbm9ybWFsRidGMg==LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= is a time increment, and LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEibkYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy9GM1Enbm9ybWFsRic= is the number of time increments (or the number of graphs used in the animation). For this example, we use x(t) = t+1, y(t) = t(t+1)/100 as the components of the position of the particle, LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYmLUkjbWlHRiQ2I1EhRictRiM2Ji1JJW1zdWJHRiQ2JS1GLDYlUSJ0RicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUYjNiQtSSNtbkdGJDYkUSIwRicvRjtRJ25vcm1hbEYnRkMvJS9zdWJzY3JpcHRzaGlmdEdRIjBGJy1JI21vR0YkNi1RIj1GJ0ZDLyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0ZOLyUpc3RyZXRjaHlHRk4vJSpzeW1tZXRya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FibGVsaW1pdHNHRkIvJSdhY2NlbnRHRkIvJSdsc3BhY2VHUSwwLjI3Nzc3NzhlbUYnLyUncnNwYWNlR0ZRLUkjbW5HRiQ2JFEkMTAwRidGPkY+RitGPg==. restart:r:=[t+1,t*(t+1)/100];t0:=0;Dt:=2;n:=100; Next, we calculate LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYkLUYvNiVRImZGJ0YyRjUvRjZRJ25vcm1hbEYnLyUvc3Vic2NyaXB0c2hpZnRHUSIwRidGPQ==, the velocity and acceleration vectors (v = dr/dt and a = dv/dt), and we define a function mag to calculate the magnitude of a three dimensional vector x = [LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYoLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEieEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYkLUkjbW5HRiQ2JFEiMUYnL0Y2USdub3JtYWxGJ0Y+LyUvc3Vic2NyaXB0c2hpZnRHUSIwRictSSNtb0dGJDYtUSIsRidGPi8lJmZlbmNlR1EmZmFsc2VGJy8lKnNlcGFyYXRvckdGNC8lKXN0cmV0Y2h5R0ZJLyUqc3ltbWV0cmljR0ZJLyUobGFyZ2VvcEdGSS8lLm1vdmFibGVsaW1pdHNHRkkvJSdhY2NlbnRHRkkvJSdsc3BhY2VHUSYwLjBlbUYnLyUncnNwYWNlR1EsMC4zMzMzMzMzZW1GJy1GLDYlRi4tRiM2JC1GOzYkUSIyRidGPkY+RkBGQy1GLDYlRi4tRiM2JC1GOzYkUSIzRidGPkY+RkBGPg==], namely, LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkjbWlHRiQ2JVEkbWFnRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnL0YzUSdub3JtYWxGJw==(x) = LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUkmbXNxcnRHRiQ2Iy1GIzYoLUkjbWlHRiQ2I1EhRictRiM2JC1JKG1zdWJzdXBHRiQ2Jy1GMTYlUSJ4RicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUYjNiQtSSNtbkdGJDYkUSIxRicvRkBRJ25vcm1hbEYnRkgtRkU2JFEiMkYnRkgvJTFzdXBlcnNjcmlwdHNoaWZ0R1EiMEYnLyUvc3Vic2NyaXB0c2hpZnRHRk9GSC1JI21vR0YkNi1RIitGJ0ZILyUmZmVuY2VHUSZmYWxzZUYnLyUqc2VwYXJhdG9yR0ZYLyUpc3RyZXRjaHlHRlgvJSpzeW1tZXRyaWNHRlgvJShsYXJnZW9wR0ZYLyUubW92YWJsZWxpbWl0c0dGWC8lJ2FjY2VudEdGWC8lJ2xzcGFjZUdRLDAuMjIyMjIyMmVtRicvJSdyc3BhY2VHRmFvLUYjNiQtRjc2J0Y5LUYjNiRGSkZIRkpGTUZQRkhGMEZIRkg=: tf:=t0+(n-1)*Dt;v:=diff(r,t):v;a:=diff(v,t):a;mag:=x->sqrt(x[1]^2+x[2]^2): The next step is to produce plots of the magnitudes of the position, velocity, and acceleration vectors as functions of time in the interval LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYkLUkjbW5HRiQ2JFEiMEYnL0Y2USdub3JtYWxGJ0Y+LyUvc3Vic2NyaXB0c2hpZnRHUSIwRidGPg== < t < LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYkLUklbXN1YkdGJDYlLUkjbWlHRiQ2JVEidEYnLyUnaXRhbGljR1EldHJ1ZUYnLyUsbWF0aHZhcmlhbnRHUSdpdGFsaWNGJy1GIzYkLUYvNiVRImZGJ0YyRjUvRjZRJ25vcm1hbEYnLyUvc3Vic2NyaXB0c2hpZnRHUSIwRidGPQ==, with the purpose of determining their relative sizes. This information will be used later to produce plots of the vectors themselves. The vector plots are based on the coordinate system where the path of the motion is plotted. Thus, to produce vectors for position, velocity, and acceleration that are visible (and reasonably sized) in the plots, we may need to scale the actual vectors up or down to make them fit the coordinate system where the motion path is plotted. pp:=array(1..2,1..2):pp[1,1]:=plot(mag(r),t=t0..tf,axes=boxed,labels=["t","r"],color = blue):pp[1,2]:=plot(mag(v),t=t0..tf,axes=boxed,labels=["t","v"],color=magenta):pp[2,1]:=plot(mag(a),t=t0..tf,axes=boxed,labels=["t","a"],color=brown):pp[2,2]:=plots[display]({pp[1,1],pp[1,2],pp[2,1]},labels=["t","all"]):plots[display](pp); Notice that, for this case, the magnitude of the position vector reaches close to 400 units, while the magnitude of the velocity vector reaches only to about 4.0 units, and the magnitude of the acceleration vector is only slightly larger than zero. Later in the worksheet we will use a factor of 20 to plot the velocity vector, and a factor of 2000 to plot the acceleration vector (Typically, a few different values need to be tried before finding the best factors for these two vectors). The next step is to produce a plot of the particle's trajectory, which is displayed below and saved into variable pCurve: pCurve:=plot([r[1],r[2],t=t0..tf],axes=framed,color=blue,labels=["x","y"]):plots[display](pCurve); The next execution group contains a do loop that creates the different graphics used in the animation. Variable pMove contains the list of graphs that show the moving particle as a function of time. The following variables are used: * pSize = determines the size of the particle in the plot (=10 in this case) * vecL, vecH, vecR are parameters determining the size of the vectors representing position, velocity and acceleration. These parameters are used in the call to function plottools[arrow]. vecL is the thickness of the base of the vector, vecH is the size of the head of the vector, and vecR is the ratio of the head length to the vector length. In this case we use vecL = 4, vecH = 8, vecR = 0.1. * rFactor = distance from the vector to the label "r" identifying the vector * vFactor, aFactor = multiplicative factors to scale the velocity and acceleration vectors * pPoint, pPlabel, pR, pV, pVlabel, pA, pAlabel = variables holding the intermediate plots *pAll = a display collecting all the plots at a given time step * rt, vt, at = current values of position, velocity, and acceleration pMove:=NULL:pSize:=10:vecL:=1:vecH:=2:vecR:=0.2:rFactor:=10:vFactor:=20:aFactor:=2000: for k from 1 to n do t:=t0+(k-1)*Dt:rt:=r:pt2:=rt/2:f:=1:pL:=rt+rFactor*[1,1]:pL2:=pt2+rFactor*[1,1]:vt:=v:at:=a: pPoint:=plots[pointplot]([rt],style=point,symbol=box,symbolsize=pSize,color=red): pPlabel:=plots[textplot]([seq(pL[j],j=1..2),"P"],color=blue): pR:=plottools[arrow]([0,0],vector(rt),vecL,vecH,vecR):pR:=plots[display](pR,color=black): pRlabel:=plots[textplot]([seq(pL2[j],j=1..2),"r"],color=blue): pLineV:=plots[pointplot]([rt,[rt[1],0]],style=line,color=green): pLineH:=plots[pointplot]([rt,[0,rt[2]]],style=line,color=green): pProjH:=plots[pointplot]([rt[1],0],style=point,symbol=circle,color=blue): pProjV:=plots[pointplot]([0,rt[2]],style=point,symbol=circle,color=blue): pV:=plottools[arrow](rt,vector(vFactor*vt),vecL,vecH,vecR):pV:=plots[display](pV,color=red): pVlabel:=plots[textplot]([seq(rt[j]+vFactor*vt[j]+rFactor,j=1..2),"v"],color=blue): pA:=plottools[arrow](rt,vector(aFactor*at),vecL,vecH,vecR):pA:=plots[display](pA,color=magenta): pAlabel:=plots[textplot]([seq(rt[j]+aFactor*at[j]+rFactor,j=1..2),"a"],color=blue): pAll:=plots[display]({pCurve,pPoint,pPlabel,pR,pRlabel,pV,pVlabel,pA,pAlabel,pLineV,pLineH,pProjH,pProjV},title=cat("t = ",convert(t,string))): pMove:=pMove,pAll: end do: The collection of plots is displayed after this do loop by using function plots[display] with the option insequence=true. After the graph is shown, click on the graph and press the play button [>] in the animation menu bar shown. The animation shows not only the particle moving in time and its velocity and acceleration vectors, but also the projections of the particle motion on the x and y axes. plots[display](pMove,insequence=true);
<Text-field style="Heading 1" layout="Heading 1">Gradient 2D plots</Text-field> restart:with(plots): p1 := gradplot(x*y,x=-1..1,y=-1..1, color=blue): p2 := implicitplot( {x*y=.1, x*y=.2, x*y=.3, x*y=-.1, x*y=-.2, x*y=-.3},x=-1..1, y=-1..1, color=red, thickness=2): p3 := textplot( [0, .75, `Gradients are normal to level curves!`],font=[HELVETICA,BOLDOBLIQUE,14] ); display({p1,p2,p3});
<Text-field style="Heading 1" layout="Heading 1">3D plots and 3D surface parametric plots </Text-field> restart:with(plots): plot3d( cos(x) + y^2/2, x=-10..10, y=-2..2); #same as above but with some options plot3d( cos(x) + y^2/2, x=-10..10, y=-5..5,scaling=constrained, style=patchcontour, axes=boxed,orientation=[135,120], shading=none, lightmodel=light2, numpoints=2000); # Parametric surface plot in 3D plot3d( [ r*cos(th), r*sin(th), cos(th)*sin(th) ],r = 0 .. 1, th = 0 .. 2*Pi, grid = [10,60], orientation=[100,25], shading=zhue, lightmodel=light2, style=patch); z = x*y/(x^2 + y^2);
<Text-field style="Heading 1" layout="Heading 1">3D parametric space curve (not a surface but a line)</Text-field> restart:with(plots): plotopts:= t=0..20*Pi, orientation=[0,60], numpoints=1000, scaling=constrained: p1:=spacecurve([cos(1.1*t)*(5+sin(t)),sin(1.1*t)*(5+sin(t)),cos(t)],plotopts, shading=ZGREYSCALE, thickness=1): p2:=spacecurve([cos(2*t)*(5+sin(9*t)),sin(2*t)*(5+sin(9*t)),cos(9*t)],plotopts, shading=zhue, thickness=3): display({p1,p2});
<Text-field style="Heading 1" layout="Heading 1">3D animation of a trajectory - <Equation executable="false" style="Heading 1" input-equation="" display="LUklbXJvd0c2Iy9JK21vZHVsZW5hb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0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW9HRiQ2LlEwJkFwcGx5RnVuY3Rpb247RidGNi9GPVEnbm9ybWFsRicvJSZmZW5jZUdGOC8lKnNlcGFyYXRvckdGOC8lKXN0cmV0Y2h5R0Y4LyUqc3ltbWV0cmljR0Y4LyUobGFyZ2VvcEdGOC8lLm1vdmFibGVsaW1pdHNHRjgvJSdhY2NlbnRHRjgvJSdsc3BhY2VHUSYwLjBlbUYnLyUncnNwYWNlR0ZVLUkobWZlbmNlZEdGJDYlLUYjNictRiw2JlEidEYnRjZGOUY8LyUnZmFtaWx5R1EwVGltZXN+TmV3flJvbWFuRicvJSVzaXplR1EjMTJGJ0Y2RkNGNkZDRmpuRl1vRjZGQy1GQDYuUSI9RidGNkZDRkVGR0ZJRktGTUZPRlEvRlRRLDAuMjc3Nzc3OGVtRicvRldGZG8tRlk2Jy1GIzYsRistRiM2KS1GLDYmUSRzaW5GJ0Y2L0Y6RjhGQ0Y/RlhGam5GXW9GNkZDLUZANi5RIixGJ0Y2RkNGRS9GSEY7RklGS0ZNRk9GUUZTL0ZXUSwwLjMzMzMzMzNlbUYnLUYjNiktRiw2JlEkY29zRidGNkZfcEZDRj9GWEZqbkZdb0Y2RkNGYHBGZ25Gam5GXW9GNkZDRjZGQy8lJW9wZW5HUSJbRicvJSZjbG9zZUdRIl1GJ0ZqbkZdb0Y2RkNGK0ZqbkZdb0Y2RkM=</Equation> - helix</Text-field> A helix is a three-dimensional curve shaped like a metal spring. restart:r:=[sin(t),cos(t),t];t0:=1;Dt:=0.1;n:=100;tf:=t0+(n-1)*Dt; v:=diff(r,t):v;a:=diff(v,t):a;mag:=x->sqrt(x[1]^2+x[2]^2+x[3]^2): pp:=array(1..2,1..2):pp[1,1]:=plot(mag(r),t=t0..tf,axes=boxed,labels=["t","r"],color = blue):pp[1,2]:=plot(mag(v),t=t0..tf,axes=boxed,labels=["t","v"],color=magenta):pp[2,1]:=plot(mag(a),t=t0..tf,axes=boxed,labels=["t","a"],color=brown):pp[2,2]:=plots[display]({pp[1,1],pp[1,2],pp[2,1]},labels=["t","all"]):plots[display](pp); pCurve:=plots[spacecurve](r,t=t0..tf,axes=framed,orientation=[-8,64],color=blue,labels=["x","y","z"]):plots[display](pCurve); pMove:=NULL:pSize:=5:vecL:=0.05:vecH:=0.1:vecR:=0.1:rFactor:=0.1:vFactor:=0.75:aFactor:=0.75: for k from 1 to n do t:=t0+(k-1)*Dt:rt:=r:pt2:=rt/2:f:=1:pL:=rt+rFactor*[1,1,1]:pL2:=pt2+rFactor*[1,1,1]:vt:=v:at:=a: pPoint:=plots[pointplot3d]([rt],style=point,symbol=box,symbolsize=pSize,color=red): pPlabel:=plots[textplot3d]([seq(pL[j],j=1..3),"P"],color=blue): pR:=plottools[arrow]([0,0,0],vector(rt),vecL,vecH,vecR,cylindrical_arrow):pR:=plots[display](pR,color=black): pRlabel:=plots[textplot3d]([seq(pL2[j],j=1..3),"r"],color=blue): pV:=plottools[arrow](rt,vector(vFactor*vt),vecL,vecH,vecR,cylindrical_arrow):pV:=plots[display](pV,color=red): pVlabel:=plots[textplot3d]([seq(rt[j]+vFactor*vt[j]+rFactor,j=1..3),"v"],color=blue): pA:=plottools[arrow](rt,vector(aFactor*at),vecL,vecH,vecR,cylindrical_arrow):pA:=plots[display](pA,color=magenta): pAlabel:=plots[textplot3d]([seq(rt[j]+aFactor*at[j]+rFactor,j=1..3),"a"],color=blue): pAll:=plots[display]({pCurve,pPoint,pPlabel,pR,pRlabel,pV,pVlabel,pA,pAlabel},title=cat("t = ",convert(t,string))): pMove:=pMove,pAll: end do: plots[display](pMove,insequence=true);
LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2I1EhRic=