//Newton Raphson Method
deff('y=f(x)','y=x^3-100')
deff('y=z(x)','y=3*x^2')
a=input("Enter value of interval a:")
b=input("Enter value of interval b:")
n=input("Enter the number of iteration n:")
x0=(a+b)/2
for i=1:n
disp([i,x0])
x1=x0-f(x0)/z(x0)
if abs(x1-x0)<0.00001 then
disp("We get required accuracy")
break;
end
x0=x1
end
Output
-->exec('D:\Scilab prog by me\Newton Raphson.sce', -1)
Enter value of interval a:4
Enter value of interval b:5
Enter the number of iteration n:15
1. 4.5
2. 4.6460905
3. 4.6415932
We get required accuracy
deff('y=f(x)','y=x^3-100')
deff('y=z(x)','y=3*x^2')
a=input("Enter value of interval a:")
b=input("Enter value of interval b:")
n=input("Enter the number of iteration n:")
x0=(a+b)/2
for i=1:n
disp([i,x0])
x1=x0-f(x0)/z(x0)
if abs(x1-x0)<0.00001 then
disp("We get required accuracy")
break;
end
x0=x1
end
Output
-->exec('D:\Scilab prog by me\Newton Raphson.sce', -1)
Enter value of interval a:4
Enter value of interval b:5
Enter the number of iteration n:15
1. 4.5
2. 4.6460905
3. 4.6415932
We get required accuracy
This is Bisection Method... In NR Method, we only meed to input one value, ie. initial guess
ReplyDeleteS, NR method need only one value
ReplyDelete