































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
In this document has matlab programming
Typology: Study notes
1 / 71
This page cannot be seen from the preview
Don't miss anything!
































































Let f(x)=0 -------------(1)
Be the given equation can be written as
x= (x) …………..(2) ,where |'(x) |<
consider the first approximation root is 𝑥
1
=a
and the second approximation root 𝑥
2
putting x= 𝑥
1
in right hand side of
equation (2),we get
2
1
Similarly, 𝑥
3
2
2
𝑛− 1
Find the root of the equation 𝑥
3
Solution:
Let f(x)= 𝑥
3
Here, f(0)= - 1<
f(1)= 1>
so the root lies between 0 and 1
then the first approximation
0
0 + 1
2
Now from equation (1)
clc
all clear
g=@(x) x.^3+x-1;
f=@(x) 1/(x.^2+1);
df=@(x) - 2*x/(x.^2+1)^2;
x=input('Enter the initial value: ');
t=input('Tolerence:');
n=input('Enter the iteration number:');
while(df(x)>1)
fprintf('There is no root');
end
for i=1:n
x1=f(x);
fprintf('\n x%d= %.4f\n',i,x1);
if abs(x1-x)<t
break;
end
x=x1;
end
fprintf('\n\n The root is %f',x1);
x=-20:0.01:20;
plot(x,g(x),'b','linewidth',2)
hold on
plot(x1,f(x1),'or')
hold on
plot([-5,5],[0,0])
hold on
plot([0,0],[-5,5])
legend('f(x)=x.^3+x-1','root');
xlabel('x-axis','fontsize',14);
ylabel('y-axis','fontsize',14);
grid on
hold off
ans =
logical
The curve AB cut the x-axis at Q point.The approximation root equation (1) is
Let A[a,f(a)] B[b,f(b)] be the extremities of the chord AB.Now the equation of
the chord AB.
y-f(a)=
𝑓(𝑏)−𝑓(𝑎)
( 𝑏−𝑎
)
To find OQ put y=
0 - f(a)=
𝑓(𝑏)−𝑓(𝑎)
( 𝑏−𝑎
)
(x-a)= -
𝑓(𝑎)(𝑏−𝑎)
𝑓(𝑏)−𝑓(𝑎)
(x-a)=
𝑓(𝑎)(𝑎−𝑏)
𝑓(𝑏)−𝑓(𝑎)
x=a+
𝑓(𝑎)(𝑎−𝑏)
𝑓(𝑏)−𝑓(𝑎)
x=
𝑎𝑓(𝑏)−𝑏𝑓(𝑎)
𝑓
( 𝑏
) −𝑓(𝑎)
This is the required equation.
Find a root of the equation 𝑥
3
− 3 𝑥 − 5 = 0 by the method of false position.
Let f(x)=𝑥
3
Since f(2)= - 3<
f(3)= 13>
The root lies between 2 and 3.
0
Now f (𝑥
0
) = f (2.18756) = - 1.095<
clc
clear all
f=@(x)x.^3-3*x-5;
x1=input('Enter the upper interval a=');
x2=input('Enter the lower interval b=');
t=input('Tollerence T=');
fx1=f(x1);
fx2=f(x2);
if (fx1*fx2>0)
disp('There are no roots');
elseif(fx1*fx2<0)
disp('There is a root');
for i=1:
m=((x1fx2)-(x2fx1))/(fx2-fx1);
fm=f(m);
fprintf('\n %f %f %f \n',i,m,fm);
if abs(fm)<t
break
end
if(fx1*fm<0)
x2=m;
else
x1=m;
end
end
end
fprintf('\n\n The root is %f',x1)
hold on
grid on
plot(x,f(x),'m','linewidth',5)
plot(m,f(m),'o')
plot([-5,5],[0,0])
plot([0,0],[-5,5])
legend('f(x)=x.^3-3*x-5;');
xlabel('x-axis','fontsize',14);
ylabel('y-axis','fontsize',14);
hold off
0
(𝑎+𝑏)
2
In this case two possibilities will b
(1).f (𝑥
0
(2). f (𝑥
0
Now if (1) occure then 𝑥
0
is the root of the equation f(x)=0 and the
process will be terminated.
If (2) occure the root either lies between the 𝑥
0
and a or 𝑥
0
and b
Accordingly f(𝑥
0
) .f(a)<0 or 𝑓(𝑥
0
). 𝑓(b)<0 .So we have the second
approxition ,
1
(𝑥
0
+𝑎)
2
or 𝑥
1
( 𝑥
0
+𝑏
)
2
similar process of this method
Find the root of the equation 𝑥
3
− 𝑥 − 1 = 0 by using bisection method.
Let f(x)= 𝑥
3
f(1)=1- 1 - 1=-1<
and
f(2)=8- 2 - 1=5>
f(𝑥
6
)= f(1. 3203 ) =
3
The root lies between 1.3203 and 1. 3281
7
f(𝑥
7
)= f(1. 3242 ) = ( 1. 3242 )
3
The root lies between 1.3242 and 1. 3281
8
f(𝑥
8
)= f(1. 3261 ) = ( 1. 3261 )
3
The required root lies between 1.3242 and 1.3261.
clc
clear all
f=@(x)x.^3-x-1;
x1=input('Enter the upper interval a=');
x2=input('Enter the lower interval b=');
t=input('Tollerence T=');
fx1=f(x1);
fx2=f(x2);
if (fx1*fx2>0)
disp('There are no roots');
else
disp('There is a root');
for i=1:
m=(x1+x2)/2;
fm=f(m);
fprintf('\n %f %f %f\n',i,m,fm);
if abs(fm)<t
break
end
if(fx1*fm<0)
x2=m;
else
x1=m;
end
end
end
fprintf('\n\n The root is %f',x1)
x1=-20:0.01:20;
hold on
grid on
plot(x1,f(x1),'m','linewidth',5)
plot(m,f(m),'o')
plot([-5,5],[0,0])
plot([0,0],[-5,5])
legend('f(x)=3x.^3+8x.^2+8*x+5;');
xlabel('x-axis','fontsize',14);
ylabel('y-axis','fontsize',14);
hold off
output:
Enter the upper interval a=
Enter the lower interval b=
There is a root
f(a) + hf'(a)=
hf'(a) = - f(a)
h= -
𝑓(𝑎)
𝑓′(𝑎)
So, the first approximation
1
𝑓(𝑎)
𝑓
′
( 𝑎
)
2
1
1
𝑓(𝑎
1
)
𝑓′(𝑎
1
)
𝑛+ 1
𝑛
𝑛
𝑓(𝑎
𝑛
)
𝑓′(𝑎
𝑛
)
By repeating this method we get the close approximation deseired root.
Solve for a real root of the eqution 𝑥
4
2
− 80 = 0 by using Newton -
Rophson method.
Given equation
4
2
Let f(x)= 𝑥
4
2
f'(x)= 4𝑥
3
Here f(2) = - 60 <
f(3) = 10 >
The root lies between 2 and 3
The initial approximation value of the root ,
0
2 + 3
2
Now ,we get from Newton-Rophson method
1
0
𝑓(𝑥
0
)
𝑓′(𝑥
0
)
2
1
𝑓(𝑥
1
)
𝑓′(𝑥
1
)
3
2
𝑓(𝑥
2
)
𝑓′(𝑥
2
)
4
3
𝑓(𝑥
3
)
𝑓′(𝑥
3
)
5
4
𝑓(𝑥
4
)
𝑓′(𝑥
4
)
The required root is 2.
clc
clear all
f=@(x)x.^4+x.^2-80;
df=@(x)4x.^3-2x;
x=input('Intial value=');
t=input('tollerence=');
n=input('Number of iteration=');
if df(x)==
fprintf('there is no root');
else
fprintf('there is root');
for i=1:n
x1=x-f(x)/df(x);
fprintf('\n x%d = %.4f\n',i,x1);
if (df(x1)==0)
fprintf('there is no root');
end
if(abs(x-x1)<t)