You are on page 1of 3

Assignment: Numerical Methods(Matlab)

Submitted to :

 Sir Irfan Mustafa

Submitted by :

 Kanwal Raza (BR570733)

 Javeria Suman (BR)

 Sawera Sultan
Program:01
function [ y ] = Bisection_Method ( x1,x2)
y = @(x) x^3-x-11;
x1 = input('Enter x1: ');
x2 = input('Enter x2: ');
if y(x1)*y(x2) > 0
disp('No root lies within the given interval')
return
end
for i = 1:100
m = (x1+x2)/2;
if y(x1)*y(m) < 0
x2 = m;
else
x1 = m;
end
if abs(y(m)) < 1e-4
disp('Root:')
disp(m)
disp('Number of bisections:')
disp(i)
break;
end
i
m
end
Program:02
function f = Simple_iteration(x)
f = @(x) 1 / sqrt(x + 1);
x = 0.5;
tol = 0.0001;
for iteration = 1:10
xnew = f(x);
if abs(xnew - x) > tol
x = xnew;
end
iteration
x
end
fprintf('The root = %.4f at iteration no.% d\n', xnew, iteration)

Program:03
function [ f] = Regula_Falsi_7
% Matlab program for Regula-Falsi Method
f = @(x) x*exp(x) - 3;
x0 = input('Enter the first approximation x0:');
x1 = input('Enter the second approximation x1:');
tol = 1e-6;
while f(x0)*f(x1)>0
x0 = input('Enter the first approx. again x0:');
x1 = input('Enter the second approx. again x1:');
end
for iteration=1:10
if abs(x0 - x1) > 1e-6
xnew = x0 - (((x1-x0)/(f(x1)-f(x0)))*f(x0));
end
if f(x0)*f(x1)<0
x1 = xnew;
else
x0 = xnew;
end
iteration
xnew
fprintf('At Iteration No.%d the root = %.3f\n',iteration,xnew)

You might also like