# Sample Maple Commands for each Project # This notebook contains sample Maple commands which you may cut-and-paste from and use in your current notebook. The projects below are in alphabetic order for ease of use. # Analytic Geometry > d1 := sqrt( (x+c)^2 + y^2 ):\ d2 := sqrt( (x-c)^2 + y^2 ):\ ( d1^2 - d2^2 ); > q := c^2 - k^2 * c^2 + x^2 -a^2 * x^2 + y^2 - b^2 * y^2:\ collect( q, [x,y,c] ); > with(plots):\ implicitplot(((x-1)/3)^2 + y^2 = 8, x = -10..10, y = -10..10, \ scaling = CONSTRAINED); # Note: the scaling = CONSTRAINED options prevents Maple from rescaling and essentially drawing a circle. # Arclength > ds := (y,x) -> sqrt(1 + D(y)(x)^2);\ y := x -> x^2:\ dsParabola := ds(y,x);\ sParabola := int(dsParabola, x);\ subs(x=1, sParabola) - subs(x=0, sParabola); # Area > f := x -> sqrt(1 - x^2):\ a := 0: b := 1.0:\ n := 5: delx := (b - a)/n:\ Rsum := delx * sum( f(a + (i+.5)*delx), i = 0..n-1):\ approxPi := 4 * Rsum; # (The) Asteroid Problem > for x from 0 by 0.2 to 1.0 do\ lprint(x, cos(x) -x)\ od; # (The) Binomial Theorem > sum := 0:\ for k from 1 by 2 to 7 do\ sum := sum + k^2\ od; # Chaos # See Newton Project below for the Newton loop. # Center of Mass > a := 'a':\ volume := int( int( int( 1, z = 0..a-x-y ), y = 0..a-x), x = 0..a);\ cmassX := int( int( int(x, z = 0..a-x-y ), y = 0..a-x ), x = 0..a )\ / volume; # Curve Fitting for Discrete Data Sets > xdata := [.2, 1.1, 2.0, 3.1, 3.9, 5.1]:\ ydata := [-2, 0, 1, 2.8, 5, 7]:\ data := zip( (x,y) -> [x,y], xdata, ydata);\ with(stats):\ cof := linregress(ydata, xdata);\ y := cof[1] + cof[2] * x; # Derivatives, Slopes and Tangents # After defining f, we can get the tangent: > b := 2.1:\ slope := (f(b) - f(2)) / (b - 2.0):\ secant := f(2.0) + slope*(x - 2.0):\ print(`slope is `, slope);\ plot({secant, f(x)}, x = 1.5..3.0); # Derivative in Maple > y := 1/(1 + sqrt(1 + sqrt(x)));\ diff(y, x); # Finding Roots with Maple > quadeqn := a*x^2 + b*x + c = 0;\ solutions := solve(quadeqn, x);\ subs(x = solutions[1], quadeqn);\ Digits := 10:\ lhs := x^3 - 3*x^2 + 1:\ solutions := fsolve(lhs = 0, x); # Force Applications in 3D # Here is a typical 3D integration in rectangular coordinates. > z := 'z': x := 'x': y := 'y':\ h := 1: R := 3:\ int( int( int( z+h+R, \ x = -sqrt(R^2 - y^2 - z^2)..sqrt(R^2 - y^2 - z^2) ),\ y = -sqrt(R^2 - z^2)..sqrt(R^2 - z^2) ),\ z = -R..R); # Fourier Frequency Decomposition > f := x -> x*(Pi - x)*(Pi + x):\ nmax := 2: npi := evalf(Pi):\ b := seq( 2/npi * int( f(x)*sin(k*x), x=0..npi), k=1..nmax);\ fn := x -> sum( b[n]*sin(n*x), n = 1..nmax):\ plot({f, fn}, 0..Pi); # Functions Defined by Integrals > myLog := int( 1/x, x = 1..z);\ P := sqrt(1/Pi) * int( exp(-x^2/2), x = 0..z);\ z := 'z':\ MyErf := 2/sqrt(Pi) * int( exp(-t^2), t = 0..z); # Graphical Equation Solving > plot(2*a^3 + a - 2, a = 0.7..1.1); # Integration in Maple # A numerical integration: > x := 'x':\ evalf( int( arcsin(x), x = 0..1/2) ); # Inverse Square Law Problems > q := a + eps:\ R := sqrt( q^2 + r^2 - 2*q*r*cos(phi) ):\ F := -3*G*M*m/(4*Pi*a^3) * \ int( int( int( (q - r*cos(phi))/R^3*r^2*sin(phi),\ phi = 0..Pi ), r = 0..a ), theta = 0..2*Pi );\ q := 'q':\ subs( eps = q-a, F); # Limits and Continuity > f := x -> (sqrt(25 + 3*x) - sqrt(25 - 2*x))/x:\ plot(f(x), x = -1..1);\ for x from -1.0 by 0.2 to 1.0 do\ print(x, ` `, f(x))\ od; # Limits with Maple > limit(sin(x)/x, x=0); # Line Integrals and Work > x := t -> 2*t:\ y := t -> t:\ FT := t -> D(x)(t) + D(y)(t)*exp(c*x(t) - y(t)): # Now integrate this function to get work. # Linearization of Nonlinear Data > ddata := [8.6, 10.7, 11., 11.4, 12.0, 13.3, 14.5, 16.0,17.3,18.0,20.6]:\ vdata := [10.3, 18.8, 18.2, 21.4, 19.1, 27.4, 36.3, 38.3,55.4,51.5,77.]:\ with(plots):\ data := zip( (x,y) -> [x,y], ddata, vdata);\ plot(data, style = POINT);\ with(stats):\ cof := linregress( vdata, ddata);\ linearFit := cof[1] + cof[2]*x; # Newton's Method # f := x -> x^2 - 5: # xn := 6.0: # for k to 5 do # xn := xn - f(xn)/ D(f)(xn); # od; # Newton's Method in 2D > p := 4: q := 1:\ r := 0:\ f := (a,b) -> 2*a^3 + 8*a*b^2 + (1 - 2*r)*a - p:\ g := (a,b) -> 32*b^3 + 8*b*a^2 + (1 - 8*r)*b - q:\ dfx := (a,b) -> D[1](f)(a,b):\ dfy := (a,b) -> D[2](f)(a,b):\ dgx := (a,b) -> D[1](g)(a,b):\ dgy := (a,b) -> D[2](g)(a,b):\ printlevel := 0:\ an := 1.1: bn := .1:\ for n to 8 do\ an := an - ( f(an,bn)*dgy(an,bn) - g(an,bn)*dfy(an,bn) ) /\ ( dfx(an,bn)*dgy(an,bn) - dgx(an,bn)*dfy(an,bn) ):\ bn := bn - ( g(an,bn)*dfx(an,bn) - f(an,bn)*dgx(an,bn) ) /\ ( dfx(an,bn)*dgy(an,bn) - dgx(an,bn)*dfy(an,bn) ):\ lprint( an, bn )\ od; # Numerical Integration I > f := x -> x^4 + 1:\ a := 0: b := 5:\ n := 5: delx := (b - a)/n:\ p := 0.0:\ Rsum := delx * sum(f(a + (i+p)*delx), i = 0..n-1); # Numerical Integration II # Here are the basic integration procedures: > Mid := proc(f, a, b, n)\ Rsum(f, a, b, n, 0.5)\ end;\ Trap := proc(f, a, b, n)\ 0.5 * ( Rsum(f, a, b, n, 0) + Rsum(f, a, b, n, 1) );\ evalf(") \ end;\ Simp := proc(f, a, b, n)\ ( Trap(f, a, b, n, 0) + 2*Mid(f, a, b, n, 1) ) / 3.0\ end; # Parametric Curves in 2D > x := t -> cos(t):\ y := t -> sin(t):\ plot( [x, y, 0..2*Pi] ); # (The) Piston Problem > q := (x,L) -> sin(2*t) + sqrt(L^2 -cos(2*t)^2):\ L := 'L':\ qpr := diff(q(t,L),t); # Plotting in Polar Coordinates > with(plots, polarplot):\ k := 2:\ r := t -> sin(k*t):\ polarplot( r(t), t = 0..2*Pi); # (The) Probability Integral > p := x -> exp(-x^2/2) / sqrt(2*Pi);\ int( p(x), x = -infinity.. infinity); # Simple Harmonic Motion > f := x -> cos(x) - sin(x):\ plot(f, -Pi..Pi); # Snell's Law # f := x -> 3*x^4 - 24*x^3 + 51*x^2 - 32*x + 64; # plot(f, -10..10); # Solving Differential Equations > f := x -> 3*cos(2*x):\ kMax := 11:\ Pn := taylor( f(x), x=0, kMax );\ for k from 0 to kMax do\ b[k] := coeff( Pn, x, k)\ od:\ a[0] := 2: a[1] := 0:\ for k from 0 to kMax do\ a[k+2] := (b[k] - a[k]) / ((k+1)*(k+2))\ od; \ yn := sum( a[n]*x^n, n = 0..kMax+2); # (The) Tank Problem > 4*r* int( sqrt(1 - (x/r)^2), x = 0..r );\ 4*a* int( sqrt(1 - (y/b)^2), y = 0..b ); # Taylor Polynomials > f := x -> x * cos(2*x):\ a := 0: n := 6:\ ourSeries := taylor( f(x), x = 0, n);\ Pn := convert(ourSeries, polynom); # Tutorial Exercises > evalf(sin(Pi/3)); \ f := x^2 + 1;\ g := x^3 - x^2 - 9*x + 9;\ plot({f,g}, x = -5..5); # Twisting Space Curves > n := 'n':\ x := cos(2*n*t)*sin(t):\ y := sin(2*n*t)*sin(t):\ z := 3*cos(t):\ ds := simplify( sqrt( diff(x,t)^2 + diff(y,t)^2 + diff(z,t)^2 ) );\ n := 1:\ plots[spacecurve]( [x, y, z], t = 0..2*Pi, axes = BOXED,\ orientation=[45, 60] ); # Vectors and Work > with(linalg):\ v := [2, 3, 4]: w := [1, 1, 1]:\ u := add(9*v, -29*w); > u := [1, 2, 3]:\ norm2 := (sqrt( dotprod(u,u) ) ):\ uhat := u / norm2; # Work Along an Arc > sqrt((3-1)^2 + (3-2)^2) +\ sqrt((4-3)^2 + (5-3)^2) +\ sqrt ((5-4)^2 + (5-5)^2) +\ sqrt ((6-5)^2 + (8-5)^2):\ evalf("); > h := x -> sqrt(4 - x^2):\ a := -2: b := 2:\ ArcLength := int( sqrt(1 + D(h)(x)^2), x = a..b);