Question

Write a function named “NewtonRaphson” that implements the Newton-Raphson method. The inputs to this function are...

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 function’s 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)

  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function r = NewtonRaphson(f, df,x0,N,tol)
x=x0;
for i = 1:N
xl=x;
x = xl - f(xl)/df(xl);
if (abs(x - xl)/x) < tol
r = xl;
break
end
end
end

Add a comment
Know the answer?
Add Answer to:
Write a function named “NewtonRaphson” that implements the Newton-Raphson method. The inputs to this function are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5.1.2 Open Methods - Newton-Raphson Method Xi+1= xi – FOTO Matlab Code Example:4 function mynewtraph (f,...

    5.1.2 Open Methods - Newton-Raphson Method Xi+1= xi – FOTO Matlab Code Example:4 function mynewtraph (f, f1,x0,n) Xx0; for ilin x = x - f(x)/f1(x); disp (li if f(x) <0.01 f(x))) break end end end Matlab Code from Chapra function [root, ea, iter)=newtraph (func,dfunc, xr, es,maxit,varargin) newtraph: Newton-Raphson root location zeroes 8 [root, ea, iter)-newtraph (func, dfunc, xr, es,maxit,pl,p2, ...): $uses Newton-Raphson method to find the root of fune input: func- name of function 8dfunc = name of derivative of...

  • Newton-Raphson scheme ? Calculus Suppose you want to find zeros of the function f(x)102212 and plan to use the Newton-Raphson scheme. (a) Write down the Newton-Raphson algorithm for this. That is, wri...

    Newton-Raphson scheme ? Calculus Suppose you want to find zeros of the function f(x)102212 and plan to use the Newton-Raphson scheme. (a) Write down the Newton-Raphson algorithm for this. That is, write down explicitly a formula for computing your (n+1)st guess Tn+1 given your nth guess rn for a root. In other words, deter- mine the recurrence relation resulting from using this particular function f. (b) Modifying Algorithm 2.2 as required, find the values through x7 if you choose an...

  • Matlab problem using newton raphson to find square root of number

    Need help modifying my Matlab script below (myscript calculates the square root of a number. using a Newton-Raphson method with 1 as the initial guess, calculates true and estimated error, and shows each iteration).-I need to create three new functions each of which should be called in the main script. These functions are needed to replace code that is currently in my script shown below.-I need to create these functions:A function to find f(x)A function to find f '(x) ?A...

  • B. Implement the Newton-Raphson (NR) method for solving nonlinear equations in one dimension. The...

    B. Implement the Newton-Raphson (NR) method for solving nonlinear equations in one dimension. The program should be started from a script M-file. Prompt the user to enter an initial guess for the root. -Use an error tolerance of 107, -Allow at most 1000 iterations. .The code should be fully commented and clear 2. a) Use your NR code to find the positive root of the equation given below using the following points as initial guesses: xo = 4, 0 and-1...

  • Use the Newton-Raphson method to find the root of f(x) = e-*(6 - 2x) - 1...

    Use the Newton-Raphson method to find the root of f(x) = e-*(6 - 2x) - 1 Use an initial guess of xo = 1.2 and perform 3 iterations. For the N-R method: Xi+1 = x; - f(x;) f'(x;)

  • Xs 2x2 Use the MAT AB code for Newton-Raphson method to find a root of he function table. x 6x 4 ...

    xs 2x2 Use the MAT AB code for Newton-Raphson method to find a root of he function table. x 6x 4 0 with he nitial gues& xo 3.0. Perfonn the computations until relative error is less than 2%. You are required to fill the followi Iteration! 뵈 | f(x) | f(x) | Em(%) 1. Continue the computation of the previous question until percentage approximate relative error is less 2. Repeat computation uing theial guess o1.0 xs 2x2 Use the MAT...

  • Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube...

    Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube root (a)1/3 of a given number a with accuracy roughly within 10-8 using x0 = a/2. Use at most 100 iterations. Explain steps by commenting on them. Use f(x) = x3 − a. Choose a = 2 + w, where w = 3 Algorithm : Newton-Raphson Iteration Input: f(x)=x3−a, x0 =a/2, tolerance 10-8, maximum number of iterations100 Output: an approximation (a)1/3 within 10-8 or...

  • (Numerical analysis) Here's a challenging problem for those who know a little calculus. The Newton-Raphson method...

    (Numerical analysis) Here's a challenging problem for those who know a little calculus. The Newton-Raphson method can be used to find the roots of any equation0.n this method the (i + Dst approximation, xi-1, to a root ofy(x) = 0 İs given in terms of the ith approximation, xi by the following formula, where y' denotes the derivative of y(x) with respect tox: For example, if yx) 32+2x - 2, then y()-2, and the roots are found by making a...

  • Newton invented the Newton-Raphson method for solving an equation. We are going to ask you to...

    Newton invented the Newton-Raphson method for solving an equation. We are going to ask you to write some code to solve equations. To solve an equation of the form x2-3x + 2-0 we start from an initial guess at the solution: say x,-4.5 Each time we have the i'h guess x, we update it as For our equation,f(x) = x2-3x + 2 andf,(x) = 2x-3. Thus, our update equation is x2 - 3x, 2 2x, - 3 We stop whenever...

  • 6.5 Employ the Newton-Raphson method to determine a real root for 4x20.5 using initial guesses of...

    6.5 Employ the Newton-Raphson method to determine a real root for 4x20.5 using initial guesses of (a) 4.52 f(x) 15.5x Pick the best numerical technique, justify your choice and then use that technique to determine the root. Note that it is known that for positive initial guesses, all techniques except fixed-point iteration will eventually converge. Perform iterations until the approximate relative error falls below 2 %. If you use a bracket- ing method, use initial guesses of x 0 and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT