Numerical Analysis EE305 Jan-Apr 2019: Matlab
Numerical Analysis EE305 Jan-Apr 2019: Matlab
Matlab
Numerical Analysis EE305
Jan-Apr 2019
Dr. Ramez
Source:
• Text book
• Dr. M. Iwan Solihin
• Dr. Zuliani Binti Zulkoffli
• Internet
1
3/8/2019
Introduction
• Command Window:
The Command Window is the main window in MATLAB. Use the Command
Window to enter variables and to run functions and M-files scripts (more about
m-files later). Its like an advanced calculator!
•
2
3/8/2019
• MATLAB is case sensitive! The variables x and X are not the same.
3
3/8/2019
Try this:
4
3/8/2019
5
3/8/2019
6
3/8/2019
Index x y
Roots- Graphical Methods 1 0
2 1
3 2
2 +4 −3 4 3
5 4
6 5
Find y(x=3)
7 6
7
3/8/2019
Interpolation
f=@(x)sin(x).*cos(x)+2.*cos(x)+2;
iter=0;xr=xl;ea=100;
while(1)
xrold=xr;
Given the function: xr=(xl+xu)/2;
iter=iter+1;
= sin cos + 2 cos + 2.
if xr~=0
ea=abs((xr-xrold)/xr)*100;
Use bisection method to find the value of x for interval [2, 3] end
test=f(xl)*f(xr);
which gives = 0, with a relative error ≤ 0.01%. if test <0
Solution: xu=xr;
elseif test>0
For relative error 0.01%, value of x= 2.4222 xl=xr;
else
ea=0;
end
if ea<=es|iter>=maxit
ea target error break
es current error end
While: while loop to repeat when condition is true end
root=xr
8
3/8/2019
xl = -2; xu = 1;
= +3 −6 −8 xrold = xr;
xr = xu - (f(xu)*(xl-xu))/(f(xl) - f(xu));
if xr ~= 0
ea = abs((xr - xrold/xr))*100;
end
Use False-Position method to find iter = iter + 1;
9
3/8/2019
Cramer’s Rule
10
3/8/2019
11
3/8/2019
• A(3,1)= 8
• A(3,1)= 4 (to change from 8 to 4)
• A(3,:) = [8 1 0]
12