PART 1 INSTRUCTIONS 1 write a user defined void method named
PART 1:
INSTRUCTIONS:
(1) write a user defined void method named newrap to find the root(s) of a non-linear function/equation. This method should call upon user defined methods to:
a. evaluate the function/equation @ (x,y)
b. calculate the derivative
c. calculate the root
(2) write a main method driver to test you newrap method.
(3) run your program for three non-linear functions/equations of your choice using three different starting points.
(4) displays (appropriately formatted/tabulated):
a. the function/being solved
b. the values of n, xn> f(xn), f\'(xn), x,w, as the solution converges
c. the root(s), if found, or a message indicating non-convergence, a singularity, or iteration limit reached.
NOTES:
(1) You may linearize your function if you so desire.
(2) Stop iterating when the difference in successive approximations is <=le-06 or 50 iterations max, whichever comes first.
PART 2:
Same as part 1 but you must use another/different iterative method/algorithm to find the root(s).
Solution
function root = iterative(f,interval)
root = fzero(f,interval)
end
f = @x.^3 - 2*x - 5;
interval = [0,5]
root = iterative(f,interval);
disp(\'Root: \',root);
----------------------------------------------------------
function root = bisection(f,firstInterval,secondInterval)
if f(firstInterval)*f(secondInterval)>0 %if no roots
disp(\'Wrong choice\')
else
root = (firstInterval + secondInterval)/2; %getting mid root value
err = abs(f(root));
while err > 1e-7
if f(firstInterval)*f(p)<0
secondInterval = root;
else
firstInterval = root;
end
root = (firstInterval + secondInterval)/2;
err = abs(f(root));
end
end
end
f = @x.^3 - 2*x - 5;
root = bisection(f,0,5);
disp(\'Root: \',root);
