> restart;MyName:=sfb;Today:="Sep 4, 2001"; > > #Syntax part one. > #1. Expressions that begin with the comment character `#' are comments > #2. Comments are not executed by Maple, but are a way of annotating the work > #3. The difference between `:=' (assignment) and `=' (equals). > #The next line sets the variable `eqn' to be the equation `x^2-x-6=0' > eqn := x^2-x-6=0; > #We can use `eqn' just as if it were the equation, for example > solve(x^2-x-6=0);solve(eqn); > Today;MyName; > #Although Maple has functions, we will almost always work with expressions like > f:=x^2; > #Ways to get f(2) which should be 4 > subs({x=2},f);eval(f,{x=2}); > #Ways that might work, but DON'T > f(2);subst({x=2},f); > #function notation does NOT define functions > h(x):=x^2;h(2);h; > #Ways that sort of work, but cause problems so do NOT use them > #(x:='x' clears the value of x. restart clears all variables). > x;f;x:=2;f;x;g:=x^2;x:='x';x;f;g; > #Syntax Part two, Parenthesize, starize, capitalize > wrong:= x y; > wrong:=x^-3; > surprise:=a/b*c;surprise:=a/b/c;nosurprise:=a/(b*c); > surprize:=pi;evalf(surprize);evalf(Pi);evalf(E);evalf(e);evalf(exp(1)); > surprize:=(x)(y);a:=subs({x=2,y=3},surprize);evalf(a); > correct:=(x)*(y);b:=subs({x=2,y=3},correct);evalf(b); > abc; > plot(exp(x),x=-1..1,color=plum,thickness=2); > with(student);with(plots);#Load some useful libraries > completesquare(x^2+2*x+2,x); > int(x^2,x);int(x^2,x=1..3); > middlebox(x^2,x=1..3,4); > leftbox(x^2,x=1..3,4); > rightbox(x^2,x=1..3,4); > #make our own trapbox -- done by a professional -- don't try this at home > n:=4;a:=1;b:=3;f:=x^2;delta:=a+i*(b-a)/n;deltaPlus1:=delta+(b-a)/n; > curve:=[seq(eval([delta,eval(f,x=delta)]),i=0..n)]; > boxes:=seq(POLYGONS(eval([[delta,0],[delta,eval(f,x=delta)],[deltaPlus1,eval(f,x=deltaPlus1)],[deltaPlus1,0]]),COLOR(RGB,.7,.9,.7)),i=0..n-1); > plotA:=plot(curve,filled=true,color=COLOR(RGB,.7,.9,.7)):plotA; > plotB:=PLOT(boxes):display(plotB); > plotC:=plot(f,x=a..b,color=red):plotC; > display(plotA,plotC); > display(plotB,plotC); > #Lets do some numerical work > leftsum(x^2,x=1..3,100);value(leftsum(x^2,x=1..3,100)); > for i from 1 to 10 do evalf([2^i,leftsum(x^2,x=1..3,2^i)]); od; > rightsum(x^2,x=1..3,100);value(rightsum(x^2,x=1..3,100)); > for i from 1 to 10 do evalf([2^i,rightsum(x^2,x=1..3,2^i)]); od; > middlesum(x^2,x=1..3,100);value(middlesum(x^2,x=1..3,100)); > for i from 1 to 10 do evalf([2^i,middlesum(x^2,x=1..3,2^i)]); od; > trapezoid(x^2,x=1..3,100);value(trapezoid(x^2,x=1..3,100)); > for i from 1 to 10 do evalf([2^i,trapezoid(x^2,x=1..3,2^i)]); od; > simpson(x^2,x=1..3,100);value(simpson(x^2,x=1..3,100)); > Digits:=10;for i from 1 to 10 do evalf([2^i,simpson(x^2,x=1..3,2^i)]); od; > #All at once > for i from 1 to 10 do evalf([2^i,leftsum(x^2,x=1..3,2^i),rightsum(x^2,x=1..3,2^i),middlesum(x^2,x=1..3,2^i),trapezoid(x^2,x=1..3,2^i),simpson(x^2,x=1..3,2^i)]); od; > #7.6 > f:=x^3*exp(x);a:=3;b:=6;answer:=int(f,x=a..b);error1:=array[1..10];error2:=array[1..10]; > d:=2;Digits:=20; > for i from 1 to 10 do error1[i]:=value(leftsum(f,x=a..b,d^i)-answer); error2[i]:=value(rightsum(f,x=a..b,d^i)-answer); od: > for i from 1 to 10 do evalf([i,error1[i],error2[i],error1[i]/error2[i]]); od; > for i from 1 to 9 do evalf([i,error1[i]/error1[i+1],error2[i]/error2[i+1]]);od; > for i from 1 to 10 do error1[i]:=value(trapezoid(f,x=a..b,d^i)-answer); error2[i]:=value(middlesum(f,x=a..b,d^i)-answer); od: > for i from 1 to 10 do evalf([i,error1[i],error2[i],error1[i]/error2[i]]); od; > for i from 1 to 9 do evalf([i,error1[i]/error1[i+1],error2[i]/error2[i+1]]);od; > for i from 1 to 10 do error1[i]:=value(simpson(f,x=a..b,d^i)-answer); od: > for i from 1 to 10 do evalf([i,error1[i]]); od; > for i from 1 to 9 do evalf([i,error1[i]/error1[i+1]]);od; >