Professional Documents
Culture Documents
Expt 1
Expt 1
1
1)Bisection Method (Iteration Based)
Input
f=inline('-0.9*(x*x)+1.7*x+2.5');
x1=input('initial guess x1=');
x2=input('initial guess x2=');
n=input('Enter no. of iterations=');
y1=f(x1);
y2=f(x2);
while (y1*y2>0)
x1=input('initial guess x1=');
x2=input('initial guess x2=');
y1=f(x1);
y2=f(x2);
end
for i=1:n
x3=(x1+x2)/2;
y3=f(x3);
if((y1*y3)<0)
x2=x3;
y2=y3;
else
x1=x3;
y1=y3;
end
end
fprintf('root of equation=%f',x3);
Output
initial guess x1=2.8
initial guess x2=3
Enter no. of iterations=3
root of equation=2.875000>>
Syntax
>> x=fzero('(-0.9*(x*x)+1.7*x+2.5)',2.8,3)
x =2.8601
output
initial guess x1=.5
initial guess x2=1
Enter acc=.01
root of equation=0.617188>>
Syntax
>> x=fzero(('cos(x)-1.3*x'),0.01)
x =0.6242
Output
enter initial guess x1=0
no of iterations=3
root of equation=0.655102>>
Syntax
>> x=fzero('(x*x*x-5*x+3)',0,3)
x = 0.6566
Output
enter initial guessx1=1
no. of iterations=4
root of equation=1.127750
syntax
x=fzero('(1+0.3*cos(x)-x)',1)
x = 1.1284
output
enter initial guess x1=1
enter the acc=0.001
root of equation=1.059460>>
Syntax
>> x=fzero('(x*x*x-20*x+20)',0.001)
x =1.0595
Input
g=inline('(1+0.3*cos(X))');
dg=inline('(-0.3*sin(x))');
x1=input('enter initial guessx1=');
acc=input('enter the acc=');
a=dg(x1);
while(abs(a)>1)
x1=input('enter initial guessx1=');
a=dg(x1);
end
x2=g(x1);
while(abs(x2-x1)>acc)
x1=x2;
x2=g(x1);
end
fprintf('root of equation=%f',x2);
output
enter initial guessx1=0.5
enter the acc=0.0001
root of equation=1.128410
syntax
x=fzero('(1+0.3*cos(x)-x)',0.5)
x = 1.128410