I need to find all roots for this function f(x)=-2x^4+x^3-2x+3 in given interval [-1.5 ; 1.5] with accuracy being <0.0001. Then i have to plot the relative mistakes. So i got this code but it's not working.
deff('y=f(x)','y=-2x^4+x^3-2x+3')
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
There are 2 pbs in your code;
The definition of f function must be
deff('y=f(x)','y=-2*x^4+x^3-2*x+3')
You did not define the z function in your code. It should compute the derivative of f at x
deff('y=z(x)','y=-8*x^3+3*x^2-2')