Question

Programming Language: MATLAB Problem 3: (5 Points) Write a function with the header: function [R] -myNewtonRaphson (f, fp, x0, tol) which takes as input f: a function handle fp: a function handle to the derivative of f (note how I do it in the test case). x0: the initial guess of the root tol: a tolerance above which the algorithm will keep iterating. Tips: . Be sure to include an iteration counter which will stop the while-loop if the number of iterations get greater than 1000 It is not necessary to print out a convergence table within the while loop. (l.e., there should be no fprintf statements in your code) Test Case: >> format longg fQ(x) 2* (1-cos (x) )+4* (1-sqrt (1- (0.5*sin(x)) .*2)) - 1.2; >>df Q(x) (f (x 1e-8) - f (x) / 1e-8; >>[root, nIter]myNewtonRaphson (f, df ,1, 1e-8) root 0.958192178746275 nIter

0 0
Add a comment Improve this question Transcribed image text
Answer #1
function [R,i]=myNewtonRaphson(f,fp,x0,tol)
i=1;
while abs(f(x0))>tol && i<1000
    x0=x0-f(x0)/fp(x0);
    i=i+1;
end
R=x0;

>>format long >>f-e (x) 2* (1-cos (x))+4 (1-srt (1-(.5 sin(x))- *2))-1.2; >>df-e (x) (f (xtle-8)-f (x))/le-8: >[root,nIter]-m

Add a comment
Know the answer?
Add Answer to:
Programming Language: MATLAB Problem 3: (5 Points) Write a function with the header: function [R] -myNewtonRaphson...
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
  • I'm working on the newton's method on matlab, could someone help me and show what two...

    I'm working on the newton's method on matlab, could someone help me and show what two lines are needed to be added in the codes in order to make this function work? function sample_newton(f, xc, tol, max_iter) % sample_newton(f, xc, tol, max_iter) % finds a root of the given function f over the interval [a, b] using Newton-Raphson method % IN: % f - the target function to find a root of % function handle with two outputs, f(x), f'(x)...

  • Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any a...

    Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any arbitrary function f given an initial guess xo, an absolute error tolerance e and a maximum number of iterations max iter. Follow mynewton.m template posted in homework 2 folder on TritonED for guidance. You are not required to use the template. The function should return the approximated root ^n and the number of steps n taken to reach the solution. Use function mynewton.m to perform...

  • [USING R] Write a function bisect(f, lower, upper, tol = 1e-6) to find the root of...

    [USING R] Write a function bisect(f, lower, upper, tol = 1e-6) to find the root of the univariate function f on the interval [lower, upper] with precision tolerance =< tol (defaulted to be 10-6 ) via bisection, which returns a list consisting of root, f.root (f evaluated at root), iter (number of iterations) and estim.prec (estimated precision). Apply it to the function f(x) = x3 - x - 1 on [1, 2] with precision tolerance 10-6 . Compare it with...

  • This program has to be written in matlab 2. Write a function to find a root...

    This program has to be written in matlab 2. Write a function to find a root of f(c) using the secant method. Call this routine secant, call the file secant.m; its first line should be function [x,nf] = secant (fname, x0, x1, tol) fname is the name of the m-file which evaluates the function f(x), 20 and 21 are initial approximations to .c", and tol is a stopping tolerance. Your code should return an approximation x = 2X+1 to 3*...

  • MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts...

    MATLAB help! I have some MATLAB Assignment to do, the proffesor requires all the small parts in order to get full credit. Help me out, thank you f LAB SECTION NAME HW6P3 (30 points) following are infinite series representations of the function, un pra i a script file HW6P3 that determines the value of the function from the sum of the series for a given value of x. The program (1 pt) must prompt the user to enter a value...

  • Part B (Based off Week 3 Content) Newtons Method approximates a root of a function by iterating t...

    must be done in matlab Part B (Based off Week 3 Content) Newtons Method approximates a root of a function by iterating through the equation where n is the nth estimate for the root of the function f(z). In order to it- erate through this method, we need to provide an initial guess for the root, For example, if we apply this method to f(z) = sin(z) using note that f(cos(r) = 1, we sin(1) =-0.5574 cos(1) sin(-0.5574 ) cos(-0.5574)...

  • MATLAB Write a function with the header function [s, count] = myMonteCarlo(f, xLeft, xRight, tol) which uses bracketing...

    MATLAB Write a function with the header function [s, count] = myMonteCarlo(f, xLeft, xRight, tol) which uses bracketing logic and random numbers to solve for the root of f. Start from your code for Problem 1, then modify the update equation to randomly choose a number between xLeft and xRight. That is your xNew. Note your code will take a different number of iterations to find the root every time you run it, even for the exact same initial bracket,...

  • (a) (4 points) Fill in the blanks in the following MATLAB function M file trap so...

    (a) (4 points) Fill in the blanks in the following MATLAB function M file trap so that it implements the composilu trapezidul rulo, using a soquence of w -1,2, 4, 8, 16,... trapezoids, to approximatel d . This M file uses the MATLAB built-in function trapz. If 401) and y=() f(!)..... fr. 1)). 3= ($1, then the execution of z = trapz(x, y) approximates using the composite trapezoidal rule (with trapezoids). (Note that the entries of are labeled starting at...

  • This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable...

    This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable to transcribe this imageNewton's Method We have already seen the bisection method, which is an iterative root-finding method. The Newton Rhapson method (Newton's method) is another iterative root-finding method. The method is geometrically motivated and uses the derivative to find roots. It has the advantage that it is very fast (generally faster than bisection) and works on problems with double (repeated) roots, where the...

  • clearvars close all clc tol = 0.0001; % this is the tolerance for root identification xold...

    clearvars close all clc tol = 0.0001; % this is the tolerance for root identification xold = 0.5; % this is the initial guess test = 1; % this simply ensures we have a test value to enter the loop below. %If we don't preallocate this, MATLAB will error when it trys to start the %while loop below k = 1; %this is the iteration counter. Similar to "test" we need to preallocate it %to allow the while loop to...

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