Question

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

function [xn, n] mynewt on (f, fp, x0, epsilon, maxiter) % MYNEWTON : solves for the root of f(x) = 0 using Newtons method.

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 the following exercises. (a, b) Find the root of f(x32 36z+31 with zo 1.5, 10-3 and a maximum number of iterations equal to 25. Put the root in p4a and the corresponding number of steps in p4b. (c, d) Find the root of f(x 23+3z2-36x+31 with zo 2, 10-3 and a maximum number of iterations equal to 250. Put the root in p4c and the corresponding number of steps in p4d.
function [xn, n] mynewt on (f, fp, x0, epsilon, maxiter) % MYNEWTON : solves for the root of f(x) = 0 using Newton's method. % Inputs are anonymous function f, anonymous function fp for % the derivative, initial guess x0, error tolerance epsilon and the maximum % number of iterations max-iter. Outputs are the approximated root xn and the number of iterations n taken. % Call format: [xn, n] -mynewton(f, fp, x0, epsilon, maxiter) % Initialize: E while n
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

close all
clear all
clc
f=@(x) 2*x^3+3*x^2-36*x+31;
fp=@(x) 6*x^2+6*x-36;
x0=1.5;
epsilon=1e-3;
max_iter=25;
[p4a,p4b]=mynewton(f,fp,x0,epsilon,max_iter)
x0=2;
epsilon=1e-3;
max_iter=250;
[p4c,p4d]=mynewton(f,fp,x0,epsilon,max_iter)
function [xn,n]=mynewton(f,fp,x0,epsilon,max_iter)
n=0;
xn=x0;
while(n<=max_iter)
xn=x0-f(x0)/fp(x0);
x0=xn;
  
n=n+1;
if(abs(f(x0))<epsilon)
break;
end
end
  
end

MATLAB R2018a EDITOR ② ▼| rch Documentation Log In Find Files Compare Print Run Section New Open Save Advance Run and Find In

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any a...
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
  • 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 the...

  • DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the...

    DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the following calculations. Your script will use the functions you create. Label all graphs appropriately. For this project, do not have your homemade functions fprintf anything, instead have all your fprintf commands within your script. Attach your published script file along with .m files for your functions. Exercise 1. A fundamental iterative method for finding the roots of equations of one-variable is known as Newton's...

  • Page 73, as mentioned in the stated question, is provided below 1. Consider a new root-finding...

    Page 73, as mentioned in the stated question, is provided below 1. Consider a new root-finding method for solving f(x) = 0. Successive guesses for the root are generated from the following recurrence formula: Xn+1 = In f(xn) fhen + f(xn)] – F(Xn) (1) Write a user-defined function with the function call: [r, n] = Root fun (f, xl, tol, N) The inputs and outputs are the same as for the user-defined function Newton described on page 73 of Methods....

  • Programming Language: MATLAB Problem 3: (5 Points) Write a function with the header: function [R] -myNewtonRaphson...

    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...

  • MATLAB QUESTION please include function codes inputed Problem 3 Determine the root (highest positive) of: F(x)=...

    MATLAB QUESTION please include function codes inputed Problem 3 Determine the root (highest positive) of: F(x)= 0.95x.^3-5.9x.^2+10.9x-6; Note: Remember to compute the error Epsilon-a after each iteration. Use epsilon_$=0.01%. Part A Perform (hand calculation) 3 iterations of Newton's Raphson method to solve the equation. Use an initial guess of x0=3.5. Part B Write your own Matlab function to validate your results. Part C Compare the results of question 1 to the results of question 2, what is your conclusion ?

  • 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...

  • Write a MATLAB function newtonRaphson(fx, x0, sigfig, maxIT) that will return a root of the funct...

    Write a MATLAB function newtonRaphson(fx, x0, sigfig, maxIT) that will return a root of the function f(x) near x=x0 using the Newton-Raphson method, where sigfig is the accuracy of the solution in terms of significant figures, and maxIT is the maximum number of iterations allowed. In addition to the root (xr), the function newtonRaphson is expected to return the number of iterations and an error code (errorCode). As such, the first line of the function m file newtonRaphson.m must read...

  • 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...

  • . (25 points) The recurrence relation for the Newton's Raphson method is a)0.1.2 f(r.) F(z.) The ...

    . (25 points) The recurrence relation for the Newton's Raphson method is a)0.1.2 f(r.) F(z.) The derivative of the function can be approximately evaluated using finite-difference method. Consider the Forward and Centered finite-difference formulas Forward Finite-Difference Centered Finite-Difference 2h It is worthwhile to mention that modified secant method was derived based on the forward finite- difference formula. Develop a MATLAB functions that has the following syntax function [root,fx,ea,iter]-modnetraph (func,x0,h,es,maxit,sethod, varargin) % modnevtraph: root location zeroes of nonlinear equation f (x)...

  • 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;...

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