I need to write a program that a user inputs a function, the function's derivative, and their initial guess of the root, and then with the Newton Raphson method find the root (or a number with a very small error close to the root).
显示 更早的评论
I need to write a program that a user inputs a function, the function's derivative, and their initial guess of the root, and then with the Newton Raphson method find the root (or a number with a very small error close to the root). We were told to use inline(), but I'm completely lost, any help would be great.
func = inline('f','x');
dfunc = inline('df','x');
f = input('Enter a function (MATLAB COMPATIBLE) in terms of x:\n', 's');
df = input('Enter the derivative of that function (MATLAB COMPATIBLE):\n', 's');
xr = input('Enter your initial guess of the root:\n');
iter=0;
while(1)
xold=xr;
xr= xr-func(xr)/dfunc(xr);
iter=iter+1;
if xr~=0, ea=abs((xr-xrold)/xr)*100;end
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Newton-Raphson Method 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!