Write a function function [xroot, froot] = newtonroot (func, x, h) that takes a
ID: 3795841 • Letter: W
Question
Write a function function [xroot, froot] = newtonroot (func, x, h) that takes a function func and returns he approximate root xroot as well as the function value froot at the approximate root using the formula shown below. Newton-Raphson root formula x_root x f(x_/f(X) In your function, call the function funcderiv from the previous homework, Problem 1, to compute the function derivative f' (x). Test your function with the following input (define w(t), y(x) as anonymous functions in the workspace): Write a function function [xroot, froot] = newtonroot_anon (func, x, h) to solve Problem 1 The only change from Problem 1 is that your function should use the ANONYMOUS function from the previous homework, Problem 2, to compute the function derivative f (x) NSTEAD of using the function file funcderiv). Test your function for the three cases from above.Explanation / Answer
function [xroot,froot]=newtonroot(f, x, h)
dx=1; %the loop will run until dx is 1
while (dx > h || abs(f)>h)
fdash = diff(f,x);
xnew = x - (f./fdash); % evaluate x
dx=abs(x-xnew); % calculate delta x or change in x
x = xnew;
end
xroot=x
froot=f
end % end of newtonroot
x=5;
f=3*x;
h=10^-1;
newtonroot(f,x,h)
online octave is not working so i could not execute it please execute it and comment if you have any error
Good Luck!!
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.