> restart;

MATH3242/COSC3122 - FW03

Solutions to Assignment 5

Question 4 - fixed point interation

> fpi:=proc(x,y,z) local e, i, x0, y0, z0, xp, yp, zp;

> e:=1;i:=0;x0:=x;y0:=y;z0:=z;

> while e > 0.00005 do

> xp:=(2*z0+2)^(1/3);

> yp:=sqrt((x0^3+7)/5);

> zp:=1/y0^2;

> e:=max(abs(x0-xp),abs(y0-yp),abs(z0-zp));

> x0:=xp;y0:=yp;z0:=zp;i:=i+1;

> od;print(i,x0,y0,z0);end;

> fpi(1.3,1.3,0.3);

> fpi(1.6,1.7,0.8);

> fpi(1.45,1.5,0.5);

The number of iterations required does not depend stronly on the initial point.

Question 5

> restart;

> ode1:=diff(u1(x),x)=u2(x);

> ode2:=diff(u2(x),x)=2*x*u2(x)-sin(x)*u1(x)+(1-x)^2;

> ode3:=diff(u3(x),x)=u4(x);

> ode4:=diff(u4(x),x)=2*x*u4(x)-sin(x)*u3(x);

> xarray:=array([0.2*k\$k=1..10]);

> F:=dsolve({ode1,ode2,ode3,ode4,u1(0)=1,u2(0)=0,u3(0)=0,u4(0)=1},{u1(x),u2(x),u3(x),u4(x)},type=numeric,value=xarray);

> for k from 1 to 10 do

> F[2,1][k,1],F[2,1][k,2] + (1.5-F[2,1][10,2])/F[2,1][10,4]*F[2,1][k,4] od;

Question 7

> A:=array(sparse,1..19,1..19);

> b:=array(1..19);

> x:=array(1..19);

> alf:=1.0;

> bet:=1.5;h:=0.1;

> for i from 1 to 19 do

> x[i]:=i*h;

> A[i,i]:=2-h^2*sin(x[i]);

> b[i]:=-h^2*(1-x[i])^2;

> if i = 1 then b[i]:=b[i]+(1+h*x[i])*alf fi;

> if i = 19 then b[i]:=b[i]+(1-h*x[i])*bet fi;

> if i > 1 then A[i,i-1]:=-1-h*x[i] fi;

> if i < 19 then A[i,i+1]:=-1+h*x[i] fi;

> od:

> op(A);

> op(b);

> linalg[linsolve](A,b);

>

>

Compare these to the results from question 5. The present results should be more accurate becasue the step size is smaller and the method is more stable.