I try to solve this equation with secant method in MATLAB.
fn=40*n^1.5-875*n+35000
my initial guess is n1=60; n2=68; I want to find root and absolute relative approximate
error at the end of each iteration. Can you help me repair my file?
This is my m-file:
Code:clc clear n1=60; n2=68; tol=1e-3; err0=3; iter=0; fprintf('iteration n relative approximate error\n') while err0>=tol iter=iter+1; fn1=40*(n1).^1.5-875*(n1)+35000; fn2=40*(n2).^1.5-875*(n2)+35000; nnew=n2-fn2*((n2-n1)/(fn2-fn1)); fnnew=40*(nnew).^1.5-875*(nnew)+35000; err(iter)=(abs((nnew-n2)/nnew))*100; fprintf('%2d %f %f\n',iter,nnew,err(iter)) if nnew>n1 n1=nnew; else n2=nnew; end end nnew iter


LinkBack URL
About LinkBacks
