> 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 := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...
fpi := proc (x, y, z) local e, i, x0, y0, z0, xp, y...

> fpi(1.3,1.3,0.3);

12, 1.442235689, 1.414200804, .4999792459

> fpi(1.6,1.7,0.8);

13, 1.442258688, 1.414220610, .4999841586

> fpi(1.45,1.5,0.5);

12, 1.442250346, 1.414221499, .5000000003

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

Question 5

> restart;

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

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

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

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

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

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

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

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

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

xarray := vector([.2, .4, .6, .8, 1.0, 1.2, 1.4, 1....

> 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);

F := matrix([[vector([x, u1(x), u2(x), u3(x), u4(x)...

> 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;

.2, 1.061521916

.4, 1.146663985

.6, 1.243384623

.8, 1.342351767

1.0, 1.435600076

1.2, 1.515664424

1.4, 1.574757529

1.6, 1.603418430

1.8, 1.587439906

2.0, 1.500000000

Question 7

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

A := array(sparse,1 .. 19,1 .. 19,[])

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

b := array(1 .. 19,[])

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

x := array(1 .. 19,[])

> alf:=1.0;

alf := 1.0

> bet:=1.5;h:=0.1;

bet := 1.5

h := .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);

matrix([[1.999001666, -.99, 0, 0, 0, 0, 0, 0, 0, 0,...

> op(b);

vector([1.0019, -.64e-2, -.49e-2, -.36e-2, -.25e-2,...
vector([1.0019, -.64e-2, -.49e-2, -.36e-2, -.25e-2,...

> linalg[linsolve](A,b);

vector([1.027226633, 1.062149243, 1.102874649, 1.14...
vector([1.027226633, 1.062149243, 1.102874649, 1.14...
vector([1.027226633, 1.062149243, 1.102874649, 1.14...

>

>

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.