########################## ### Lecture Slide Examples ########################## interface(echo=2); interface(screenwidth=60); ### Exact calculations 12315/35; (22431)*(832748)*(387281); sqrt(27); evalf(%,10); 8^(2/3); simplify(%); ### Order of operations (-27/64)^2/3; (-27/64)^(2/3); ### The surd function simplify((-27/64)^(2/3)); surd((-27/64),3); surd((-27/64),3)^2; ### Transforming expressions factor(12*x^2+27*x*y-84*y^2); expand((x+y)^2*(3*x-y)^3); simplify(cos(x)^5+sin(x)^4+2*cos(x)^2); normal((x^2-y^2)/(x-y)^3); normal((x^2-y^2)/(x-y)^3,`expanded`); convert(1/((x-3)*(x-1)),parfrac); convert(sin(x),exp); ### Defining expressions exp1:=x^2; exp1:=x^3; exp:=x^2; f:=(x^3+2*x^2)/(x^3+x^2-4*x-4); subs(x=4,f); eval(f,x=4); ### Expressions x:=2; exp1:=x^2; exp1:='x^3'; exp1; unassign('exp1'); exp1; unassign('x'); ### Functions f:=x->x/(x^2+1); f(3); f(3+h); n1:=simplify((f(3+h)-f(3))/h); subs(h=0,n1); map(f,[0,1,2,3]); [seq(f(n),n=0..3)]; ### Solving equations solve(x^3+x^2+x+1=0); solve(y=(x-5)^3/8,x); solve(y=(x-5)^3/8,x)[1]; sys:={3*x-y=4,x+y=2}; sols:=solve(sys); subs(sols,sys); ### Limits limit(sin(x)/x,x=0); limit((1+a/x)^x,x=infinity); ### Differentiation diff(x^4+4/3*x^3-3*x^2,x); diff(x^4+4/3*x^3-3*x^2,x\$2); ### Integration int(1/x^2*exp(1/x),x); int(sin(x)/x,x); int(exp(-x^2)*ln(x),x); int(1/sqrt(2*Pi)*exp(-(1/2)*x^2),x=-infinity..a); int(1/sqrt(2*Pi)*exp(-(1/2)*x^2),x=-infinity..1.96); ### Procedures fib:= proc(n::nonnegint) if n<2 then n else fib(n-1)+fib(n-2) end if end proc: seq(fib(n),n=0..10); ### Producing computer code polyeqn:=x^3-a*x-1; sols:=solve(polyeqn,x); sol1:=sols[1]; with(CodeGeneration); C(sol1,optimize=true,declare=[a::float]); ### latex example expr:=int(exp(-x^2)*ln(x),x); latex(expr);