You are on page 1of 7

Taylors University

School of Engineering

Computing Applications for Engineers


(ENG2314)

Dr Thein Chung Ket

SOLUTION PRACTICE 3 System of Linear Algebraic Equation & Root finding method
Part A
Q1
a) 1 = 9.6 and 2 = 6.2

b)

Q2
A=[0 2 5; 2 1 1; 3 1 0];
S=[1;1;2];
%Method 1 - Using the equation to calculate the determinant
%Method 2 - Using the det(A) command to calculate the determinant
D=det(A)
x11=[S A(:,2) A(:,3)];
x1=det(x11)/D

Page 1 of 7

Taylors University
School of Engineering

Computing Applications for Engineers


(ENG2314)

x22=[A(:,1) S A(:,3)];
x2=det(x22)/D
x33=[A(:,1) A(:,2) S];
x3=det(x33)/D

X1 = -2 ; X2 = 8 ;X3 = -3

Q3
By using hand calculation
X1 = 0.1525
X2 = 10.0922
X3 = -5.2909

Q4
%Let x1=number of hectares logged in West region
%Let x2=number of hectares logged in North region
%Let x3=number of hectares logged in East region
%Hectar in different region (m3/ha)
W=330;
%West
N=390;
%North
E=290;
%East
%(0.7W)x1+(0.1N)x2+(0.05E)x3=1000
%(0.2W)x1+(0.6N)x2+(0.2E)x3=800
%(0.1W)x1+(0.3N)x2+(0.75E)x3=600
r1=[0.7*W 0.1*N 0.05*E];
r2=[0.2*W 0.6*N 0.2*E];
r3=[0.1*W 0.3*N 0.75*E];
A=[r1;r2;r3];
S=[1000;800;600];
k=A\S;
x1=k(1,1)
x2=k(2,1)
x3=k(3,1)

x = 3.92, y = 2.05, and z = 1.06


Page 2 of 7

Dr Thein Chung Ket

Taylors University
School of Engineering

Computing Applications for Engineers


(ENG2314)

Q5

x = 1.5 ; y = 3.1 ; z = 2.2

Page 3 of 7

Dr Thein Chung Ket

Taylors University
School of Engineering

Computing Applications for Engineers


(ENG2314)

Part A
Question 1
You can check your solution in Question 2.

Question 2
a) Bisection Method
%A matlab program illustrating the Bisection method.
%%%%%%%%%%%%%%%%%%%%%%%%%%
% Written by Dr Thein C K
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
xl=1;
xu=3;

%lower guess value


%upper guess value

fxl=xl^3-20;
fxu=xu^3-20;
it=0;
error= (xu-xl)/xu;
if fxl*fxu<0

%Step 1

while error>0.00001
it=it+1;
fxl=xl^3-20;
fxu=xu^3-20;
%Step 2
fxl=xl^3-20;
fxu=xu^3-20;
xr=(xl+xu)/2;
fxr=xr^3-20;
if fxl*fxr <0
xu=xr;
elseif fxl*fxr > 0
xl=xr;
else
break
end
error=(xu-xl)/xu;
result(it,1)=it;result(it,2)=xr;
end
else
disp('Please enter correct guess value');

Page 4 of 7

Dr Thein Chung Ket

Taylors University
School of Engineering

Computing Applications for Engineers


(ENG2314)

end
disp(' Iteration
disp(result)

Root')

(b) False Position Method


%A matlab program illustrating the False Position method.
%%%%%%%%%%%%%%%%%%%%%%%%%%
% Written by Dr Thein C K
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
xl=1;
xu=3;

%lower guess value


%upper guess value

fxl=xl^3-20;
fxu=xu^3-20;
it=0;
error= (xu-xl)/xu;
if fxl*fxu<0

%Step 1

while error>0.00001
it=it+1;
fxl=xl^3-20;
fxu=xu^3-20;
%Step 2
%False Position Method
%fxl=xl^3-20;
%fxu=xu^3-20;
xr=xu-((fxu*(xl-xu))/(fxl-fxu));
fxr=xr^3-20;
if fxl*fxr <0
xu=xr;
elseif fxl*fxr > 0
xl=xr;
else
break
end
error=(xu-xl)/xu;
result(it,1)=it;result(it,2)=xr;
end
else
disp('Please enter correct guess value');
end
disp(' Iteration
disp(result)

Root')

Page 5 of 7

Dr Thein Chung Ket

Taylors University
School of Engineering

Computing Applications for Engineers


(ENG2314)

Dr Thein Chung Ket

(c) Newton Raphson


clc
clear all
xi=3;
%Initial guess value
fxi=xi^3-20;
it=0;
while fxi>0.0001
it=it+1;
fxi=xi^3-20;
dfxi=3*xi^2;
%Newton Raphson Formula
xi=xi-fxi/dfxi;
result(it,1)=it;result(it,2)=xi;
end
disp(' Iteration
Root ')
disp(result)

(d) Secant Method


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%A matlab program illustrating the Secant method.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Written by Dr Thein C K
%
% Date 7 April 2014
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Secant Method
clc
clear all
xu=3;
xl=1;
fxl=xl^3-20;
fxu=xu^3-20;
fxi=xl^3-20;
it=0;
while abs(fxi)>0.00001
it=it+1;
%Secant Formula
xi=xu-(fxu)*((xu-xl)/(fxu-fxl));
fxi=xi^3-20;
if (fxl*fxi)<0
xu=xi;
elseif (fxl*fxi)>0

Page 6 of 7

Taylors University
School of Engineering

Computing Applications for Engineers


(ENG2314)

xl=xi;
else
break
end
result(it,1)=it;result(it,2)=xi;
end
disp(' Iteration
Root')
disp(result)

Challenging Question
1.

Iterations
1
2
3

Bisection
2.2500
2.1250
2.0625

Roots
Newton Raphson
2.0273
2.0288
2.0288

Since the exact answer is 2.0288, Newton Raphson converges faster.

Page 7 of 7

Dr Thein Chung Ket

You might also like