L-24 MCS 320 Friday 21 October 2005
| > | restart; |
| > | with(plots); |
Warning, the name changecoords has been redefined
![]()
![]()
![]()
![]()
![]()
![]()
![]()
1. Plotting functions and formulas
We can plot functions and formulas without explit conversions:
| > | formula := exp(-x^2)*sin(Pi*x^2); |
| > | plot(formula,x=-2..2); # x is the independent variable |
![[Plot]](images/lec24_10.gif)
| > | f := unapply(formula,x): |
| > | plot(f(t),t=-2..2); # plotting via a conversion to formula |
![[Plot]](images/lec24_11.gif)
| > | plot(f,-2..2); # no need to specify x |
![[Plot]](images/lec24_12.gif)
2. Displaying and animating plots
Maple has datastructures for plots. The plot command from above proceeded in two steps:
1. create the plot; 2. rendering the plot. If we assign the plot to a variable, we can separate these two stages.
| > | p1 := plot(formula,x=-2..2); # creation of the plot, stored in p1 |
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Note that we better terminate with a : instead of the semi-colon...
| > | display(p1); # rendering of the plot |
![[Plot]](images/lec24_100.gif)
The display can handle multiple arguments.
| > | p2 := plot(subs(Pi=2*Pi,formula),x=-2..2,color=green): |
| > | display(p1,p2); |
![[Plot]](images/lec24_101.gif)
Instead of putting p1 and p2 on the same plot, we can put them after each other:
| > | display(p1,p2,insequence=true); |
![[Plot]](images/lec24_102.gif)
Suppose we would like an animation of 20 frames, for increasing values of the factor in front of the Pi, i.e.: p1 is for 1*Pi, p2 is for 2*Pi, in general p[k] will be for k*Pi.
| > | pl := seq(plot(subs(Pi=k*Pi,formula),x=-2..2),k=1..20): |
| > | display(pl,insequence=true); |
![[Plot]](images/lec24_103.gif)
| > |
3. Plotting around singularities
We can plot algebraic curves, defined by one polynomial in two variables.
| > | curve := x^3 + y^3 -5*x*y + 1/5; |
| > | implicitplot(curve,x=-3..3,y=-3..3,numpoints=5000); |
![[Plot]](images/lec24_105.gif)
| > | watt := (x^2+y^2)^3 + 5.12*(x^2+y^2)^2 - 5.15*(x^4-y^4) - 14.7456*y^2; |
| > | implicitplot(watt,x=-3..3,y=-3..3,numpoints=10000); |
![[Plot]](images/lec24_107.gif)
By taking enough samples we can get a faithful plot. The problem is the singularity at the origin, at (0,0), which we can resolve via polar coordinates.
| > | polar_watt := subs(x=r*cos(t),y=r*sin(t),watt); |
![]()
| > | s := solve(polar_watt/r^2,r); |
![]()
![]()
![]()
The solution give us parameterization r as a function of t, for this curve.
| > | polarplot(s[1],t=0..Pi); |
![[Plot]](images/lec24_114.gif)
| > |
4. Sparse Matrices
see lecture note
5. Curve Fitting
see lecture note