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!