

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


I found out that Matlab m-files cannot run indefinite differentiation. Thus, I made 2 programs.
% Newton-Raphson Method fprintf('Note: This program is using Symbolic Math Toolbox from Mathworks. \n Thus, make sure to install the toolbox before using this code.\n -Clint\n'); a=input('[Note: Set f(x)=0 then x=g(x)], Enter g(x)\n', 's'); f=inline(a); syms f(x); f(x)=str2sym(a); g=diff(f); tol=input('Enter Acceptable Error in Percent\n'); iter=0; x=0;
fprintf('Attempt Root Error\n');
for i=2: xr=x-(f(x)/g(x)); iter=iter+1; format longg if xr~= e=abs(xr-x)/xr100; end if xr~= e=abs(xr-x)/xr100; end if e<tol; break,end
fprintf('\t%d\t\t%.9f\t%.2f\n',i-1, xr, e) x=xr; end fprintf('Final Attempt Root Error\n'); fprintf('\t%d\t \t%.9f\t\t%.2f\n',i-1, xr, e)
% Newton-Raphson Method fprintf('Note: This code is not using Symbolic Math ToolBox.\n Thus,find the First Order Derivative of your function first\n -Clint \n'); a=input('Enter Function if f(x)= \n', 's'); f=inline(a); df=input('Enter First Derivative of Function \n', 's'); g=inline(df); tol=input('Enter Acceptable Error in Percent\n'); iter=0; x=0;
fprintf('Attempt Root Error\n');
for i=2: xr=x-(f(x)/g(x)); iter=iter+1; format longg if xr~= e=abs(xr-x)/xr*100; end if e<tol; break,end
fprintf('\t%d\t\t%.9f\t%.2f\n',i-1, xr, e) x=xr; end fprintf('Final Attempt Root Error\n'); fprintf('\t%d\t \t%.9f\t\t%.2f\n',i-1, xr, e)