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).
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Newton-Raphson Method in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!