我如何在Scilab中使用牛顿Rapshon方法找到函数的所有根?

问题描述 投票:0回答:1

我需要在给定的时间间隔[-1.5;中找到此函数f(x)=-2x ^ 4 + x ^ 3-2x + 3的所有根。 1.5],准确度为<0.0001。然后,我必须绘制相对错误。所以我得到了这段代码,但是它不起作用。

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
function scilab
1个回答
0
投票

您的代码中有2 pbs;

  • f函数的定义必须是

    deff('y = f(x)','y = -2 * x ^ 4 + x ^ 3-2 * x + 3')

  • 您未在代码中定义z函数。应该在x

    处计算f的导数

    deff('y = z(x)','y = -8 * x ^ 3 + 3 * x ^ 2-2')

© www.soinside.com 2019 - 2024. All rights reserved.