Question: Write a function named NewtonRaphson that implements the Newton-Raphson method. The inputs to this function are the name of the function, name of the functions
Write a function named NewtonRaphson that implements the Newton-Raphson method. The inputs to this function are the name of the function, name of the functions derivative function, initial guess, maximum number of iterations, and tolerance for the relative convergence error. The output is the root. Use the problem in Homework #3 to test your function.
Hw 3 that we are pulling from
%Newton-Raphson method to find upward velocity of a rocket clear all; clc; u=2200; %m/s m0=160000; %kg q=2680; %kg/s g=9.81; %m/s^2 e=1; %Starting error t=(0:1:50); x0=25;%initial guess f=u*log(m0./(m0-(q*x0)))-g*x0-1000; %Given Function fd=(q*u)./((m0-q.*x0)-g); plot(t,f) %Used to determine x0 valuebelow while e>10^(-8) xi=x0-(f/fd); e=abs((xi-x0)/xi)*100; if e<=10^(-8) root=xi; break else x0=xi; end f=u*log(m0./(m0-(q*x0)))-g*x0-1000; fd=(q*u)./((m0-q.*x0)-g); end disp('Time when v=1000 m/s is') disp(xi)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
