You are on page 1of 3

TP4 : ROOTS OF EQUATION

1. Find the roots of the equation below by graphical method


F(x) = x3 - 4x + 1
Code
x=-5:0.1:5
y=x.^3-4*x+1
plot(x,y)
grid on ; hold on
plot(x,zeros(size(x)),'m')

Figure

From the figure the roots of equation are X1 = -2.1 ; X2 = 0.1 ; X3 = 1.7

2. Find the roots of the equation below by bisection method


F(x) = x3 - 4x + 1
Code
f=@(x) x.^3-4.*x+1
x1=-4
x2=0
xr=(x1+x2)/2
while f(xr)>0.001
if f(x1)*f(xr)<0
x2=xr
else x1=xr
end
xr=(x1+x2)/2
end
fprintf('the root of equation is :%f',xr)

The root of equation is : -3.000000

3. Find the roots of the equation below by bisection method


F(x) = x3 - 4x + 1
Code
f=@(x) x.^3-4.*x+1
x1=input('value x1:')
x2=input('value x2:')
if f(x1)*f(x2)>0
fprintf('no roots')
return
end
if f(x1)==0
fprintf('x1 is one of the roots')
return
elseif f(x2)==0
fprintf('x2 is one of the roots')
return
end
for i=0:100
xr=[x2*f(x1)-x1*f(x2)]./(f(x1)-f(x2))
if f(x1)*f(x2)<0
x2=xr
else x1=xr
end
if abs (f(xr))<0.01
break
end
end
fprintf ('the root is :%f',xr)
Suppose X1 = -3 ; X2 = 0

So The root of this equation is -2.114092

𝐦𝐦𝐦𝐦
4. The parachute velocity is V = 𝐜𝐜 (1-e-ct/m) . what is the drag coefficient of
“ C ” needed to reach velocity of 40 m/s if m=68.1 kg; t=10s ;g=9.8m/s2.

Code
f=@(x)40-(((68.1)*(9.8))./x)+exp(-10*x./68.1)
x1=input('value x1:')
x2=input('value x2:')
if f(x1)*f(x2)>0
fprintf('no roots')
return
end
if f(x1)==0
fprintf('x1 is one of the roots')
return
elseif f(x2)==0
fprintf('x2 is one of the roots')
return
end
for i=0:100
xr=[x2*f(x1)-x1*f(x2)]./(f(x1)-f(x2))
if f(x1)*f(x2)<0
x2=xr
else x1=xr
end
if abs (f(xr))<0.01
break
end
end
fprintf ('the root is :%f',xr)

Suppose X1 = 1 ; X2 = 20

So The root of this equation is 16.654990

You might also like