# Lab sheet 2

## Algebraic equations

Exercise 1.1

f(x) := 2*x^4-2222*x^3+224220*x^2-2222000*x+2000000;

solve([f(x)=0],[x]);

factor(f(x));

Exercise 1.2

y: x^4-x^3-x^2-x/8+1/64;

z:16*x^3-24*x^2-6*x+2;

sols: solve(y=0,x);

zvals: map(lambda([e],ratsimp(subst(e,z))),sols);

ev(zvals,numer);

kill(f,y,z)$;

Exercise 1.3

f(x) := x^3-3*x+1;

solve(f(x)=0);

realroots(f(x)),float;

x0: find_root(f,-2,-1);

subst(x=x0,diff(f(x),x));

wxplot2d(f(x),[x,-2,2]);

kill(f,x0)$;

Exercise 1.4

g(x) := (b^2-c^2+(1+c^2)*x)/(1-c^2+c^2*x);

sols: solve(g(x)=x,x);

g00:subst(c=0,g(x)); g0(x) := ''g00;

solve(g0(x)=x,x);

g10:subst(b=0,g0(x)); g1(x) := ''g10;

solve(g1(x)=x,x);

kill(g,g00,g0,g10,g1)$;

## Approximate solutions

f(x) := sin(%pi*x+exp(-x));

solve(f(x)=0,x);

wxplot2d(f(x),[x,0,10],[box,false],[axes,solid]);

find_root(f,1.9,2.1);

roots: makelist(find_root(f,i-0.2,i+0.2),i,1,10);

r(n) := n - exp(-n)/%pi-exp(-2*n)/%pi^2;

roots0: makelist(ev(r(n),numer),n,1,10);

map(abs,roots - roots0);

kill(f,roots,roots0);

Exercise 3.1

wxplot2d(tan(%pi*x)^2-3,[x,-2.5,2.5],[y,-10,10],[box,false],[axes,solid]);

solve(tan(%pi*x)^2=3,x);

Exercise 4.1

eqns: [x/2+y/3+z/4=1, x/3+y/4+z/5 = 2, x/4+y/5+z/6=3];

sols:solve(eqns,[x,y,z]);

subst(sols[1],x^2+y^2+z^2);

kill(eqns,sols)$;

Exercise 4.2

linsolve([p+q+r=0,p+2*q+3*r=1],[p,q,r]);

linsolve([u+v=1001,u+2*v=1002,u+3*v=1006],[u,v]);

linsolve([x+y+z=2,x+2*y+3*z=2,x+4*y+9*z=2],[x,y,z]);