half the matches they play. NOTE: IF POSSIBLE INCLUDING MATLAB PROGRAM WILL BE H
ID: 3586431 • Letter: H
Question
half the matches they play. NOTE: IF POSSIBLE INCLUDING MATLAB PROGRAM WILL BE HELPFUL
it should look something like this (but is incomplete)
function xn = secant3(x0,x1,tol,Nmax)
%SECANT METHOD: Enter f(x), x0, x1, tol, Nmax
f = @(x) ((1+x)/2).*(x./(1-x+x.^2)).^21;
xn = x1 - f(x1)*(x1-x0)/(f(x1)-f(x0));
i = 1;
%yn=f(xn)
%fprintf ('yn=%f',yn);
while (abs(xn - x1) >= tol)
x0 = x1;
x1 = xn;
xn = x1 -f(x1)*(x1-x0)/(f(x1)-f(x0));
i = i + 1;
%c=f(xn);
if (i >= Nmax)
fprintf('Fail after %d iterations ',Nmax);
break
end
%ii=i;
%y=f(xn);
%fprintf('ii=%d,xn=%f,y=%f ',ii,xn,y);
end
end
%i need to find x2,x3,...with number of iterations
Explanation / Answer
tolerance=0.01;
f = @(x) ((1+x)/2).*(x./(1-x+x.^2)).^21;
x0=1;
x1=2;
iterations=1;
maximumIterations=30;
c=(x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
while abs(f(c))>tolerance
x0=x1;
x1=c;
c=(x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
iterations=iterations+1;
if(iterations==maximumIterations)
break;
end
end
if iterations<maximumIterations
disp(['Root of this Equation = ' num2str(c)]);
fprintf('Number of iterations taken: %d ', iterations);
else
disp('Error! Cannot find Root of this equation.');
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.