In this problem you will use Newton's Method to find the root of the function f(x)...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this problem you will use Newton's Method to find the root of the function f(x) = ax - cos(x), where a is a random scalar value between 2 and 8. Newton's Method is a "simple" method for finding roots of a function. This method takes an existing estimate for the root, xold, and improves it by adding a quantity Ax to obtain a new estimate: Xnew = Xold + Ax, where Ax= The formula for Ax was obtained by approximating f(x) by its tangent line near xold, then solving for the root of the tangent line, Xnew. The value Xnew constitutes a new and (in most cases) improved estimate for the true root, as depicted in the figure below, which shows data for f(x) = x - cos(x): 1.5 0.5 0 -0.5 -1 -1.5 -0.5 -f(x) Ytan (2) Fold Inew Itrue Ar 0 f(xold) f'(Xold) 0.5 1 1.5 This process can be repeated, each time recomputing Ax and replacing the old estimate with the new estimate. Your task is to write a function called NewtonRoot that finds the root of the specified function. Your function should take in an initial guess for the root of the function and then output the value of the root and the numer of iterations required for the alrogithm to converge. An outline of an algorithm using Newton's Method to compute the root of f(x) = ax - cos(x) is provided in the solution template below. : 1. Define f and its derivative fprime corresponding to f(x) = ax cos(x). Do this using anonymous functions so that you can easily evaluate f and fprime for any desired value of x. 2. Set the initial guess for the root (x) equal to the user input to the function. This is the first value of xold- 3. Use the formula above to compute Ax and Xnew- 4. Repeat step 3 until |Ax| < 10-8. This is a reasonable condition for terminating the loop because it means there isn't much change between successive guesses of the root. Note that on successive loops, Xnew from the previous loop should become old for the current loop. You can do this by defining a single variable x and setting up your algorithm properly. Your function should have two inputs: . The first input is the initial guess of the root. . The second input is the variable a, for defining f(x) = ax - cos (x) and f'(x) within the function. Your function should have two outputs: The first output is the value of the root. The second output is the number of iterations required to find the root. For example, if your loop only runs once, the numer of iterations is 1. Notes: Use a while loop in your function. Do not use an existing MATLAB solver to compute the root! In this implementation we only use a single variable, x, to keep track of the current root estimate instead of storing both the new and old values. This is because the old value is no longer needed once the new estimate 1 function [x,iter] NewtonRoot (init_guess, a) 2 3 % Define your anonymous functions and any other necessary variables here 4 % Be sure to use the input variable a properly 5 % Define f and its derivative fprime 6 f = @(x) a*x - cos(x); 7 fprime = @(x) a + sin(x); 8 9 % Initialize variables 10 tolerance = 1e-10; 11 iter = 0; 12 x = guess; 13 14 % Implement Newton's Method 15 while true 16 17 18 19 20 iter iter + 1; fx = f(x); fxprime delta_x = 21 22 23 24 end 25 26 root = x; 27 28 end 29 30 end = = x = x + delta_x; if abs (delta_x) < tolerance break; fprime (x); -fx/ fxprime; In this problem you will use Newton's Method to find the root of the function f(x) = ax - cos(x), where a is a random scalar value between 2 and 8. Newton's Method is a "simple" method for finding roots of a function. This method takes an existing estimate for the root, xold, and improves it by adding a quantity Ax to obtain a new estimate: Xnew = Xold + Ax, where Ax= The formula for Ax was obtained by approximating f(x) by its tangent line near xold, then solving for the root of the tangent line, Xnew. The value Xnew constitutes a new and (in most cases) improved estimate for the true root, as depicted in the figure below, which shows data for f(x) = x - cos(x): 1.5 0.5 0 -0.5 -1 -1.5 -0.5 -f(x) Ytan (2) Fold Inew Itrue Ar 0 f(xold) f'(Xold) 0.5 1 1.5 This process can be repeated, each time recomputing Ax and replacing the old estimate with the new estimate. Your task is to write a function called NewtonRoot that finds the root of the specified function. Your function should take in an initial guess for the root of the function and then output the value of the root and the numer of iterations required for the alrogithm to converge. An outline of an algorithm using Newton's Method to compute the root of f(x) = ax - cos(x) is provided in the solution template below. : 1. Define f and its derivative fprime corresponding to f(x) = ax cos(x). Do this using anonymous functions so that you can easily evaluate f and fprime for any desired value of x. 2. Set the initial guess for the root (x) equal to the user input to the function. This is the first value of xold- 3. Use the formula above to compute Ax and Xnew- 4. Repeat step 3 until |Ax| < 10-8. This is a reasonable condition for terminating the loop because it means there isn't much change between successive guesses of the root. Note that on successive loops, Xnew from the previous loop should become old for the current loop. You can do this by defining a single variable x and setting up your algorithm properly. Your function should have two inputs: . The first input is the initial guess of the root. . The second input is the variable a, for defining f(x) = ax - cos (x) and f'(x) within the function. Your function should have two outputs: The first output is the value of the root. The second output is the number of iterations required to find the root. For example, if your loop only runs once, the numer of iterations is 1. Notes: Use a while loop in your function. Do not use an existing MATLAB solver to compute the root! In this implementation we only use a single variable, x, to keep track of the current root estimate instead of storing both the new and old values. This is because the old value is no longer needed once the new estimate 1 function [x,iter] NewtonRoot (init_guess, a) 2 3 % Define your anonymous functions and any other necessary variables here 4 % Be sure to use the input variable a properly 5 % Define f and its derivative fprime 6 f = @(x) a*x - cos(x); 7 fprime = @(x) a + sin(x); 8 9 % Initialize variables 10 tolerance = 1e-10; 11 iter = 0; 12 x = guess; 13 14 % Implement Newton's Method 15 while true 16 17 18 19 20 iter iter + 1; fx = f(x); fxprime delta_x = 21 22 23 24 end 25 26 root = x; 27 28 end 29 30 end = = x = x + delta_x; if abs (delta_x) < tolerance break; fprime (x); -fx/ fxprime;
Expert Answer:
Answer rating: 100% (QA)
Solutions Step 1 In this problem we are tasked with implementing Newtons method in MATLAB to find the root of a given function The function is defined ... View the full answer
Related Book For
Numerical Methods For Engineers
ISBN: 9780071244299
5th Edition
Authors: Steven C. Chapra, Raymond P. Canale
Posted Date:
Students also viewed these mechanical engineering questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Figure 20.3 describes the Medicare Part D prescription drug benefi t. Look at the Web page www.partd-medicare.com/ in your area and determine the marginal coinsurance rates applicable in each...
-
Lorance Corporation issued $400,000, 7%, 20-year bonds on January 1, 2019, for $360,727. This price resulted in an effective-interest rate of 8% on the bonds. Interest is payable annually on January...
-
a. Determine IC and VCE for the network of Fig. 4.108. In Figure 4.108 b. Change β to 135 and determine the new value of IC and VCE for the network of Fig. 4.108. c. Determine the...
-
List three variables, and how they are measured, for which you would use the mode as the most appropriate measure of central tendency.
-
Product mix, relevant costs (N. Melumad, adapted) Pendleton Engineering makes cutting tools for metalworking operations. It makes two types of tools: R3, a regular cutting tool, and HP6, a...
-
12 8.) A lens with focal length f = 5.5 cm is mounted on an optics bench. A second lens with focal length f2 = 4.0 cm is mounted 2.0 cm behind lens #1. We observe a 4.0 cm tall virtual image at 7.0...
-
You bought 100 strike $30 American put options for $0.08 each exactly 270 days ago. Today you exercised the options while the underlying asset was trading for $29.82/share. What is your net...
-
Using the diagram below, calculate the depth of penetration of skin for the average and maximum beta energies emitted by cobalt-60. Provide your final answers in millimeters. How does this compare...
-
The results achieved in the targeting stage with ATmin = 20C include = 40 MW = 38 MW = 150C Minimum hot utility Minimum cold utility Pinch temperature (a) Draw the network design for the problem to...
-
frictionless track is given by the acceleration due to gravity of a cart down a a = g sine, where is the angle that the track makes with the horizontal. (This hopefully makes some intuitive sense:...
-
Assume p = 1000 kg/m; %= 9.8 kN/m; g = 9.8 m/s for all questions in this assignment. You have completed a drilling investigation for a site proposed for a proposed development for a new housing...
-
Write a sub procedure to calculate the total heat required to vaporize given amount or ice. Specific details of the problem are as follows: a. User should enter the mass of ice (grams), initial...
-
Create a Java program that prints out this kind of figure using asterisks. ********** ********** ********** ********** ********** ********** **********
-
Use the information given about the angles and to find the exact value of: (a) sin( + ) (b) cos( + ) (c) sin( - ) (d) tan ( + ) (e) sin(2) (f) cos (2) (g) sin /2 (h) cos/2 cos = 4/5, 0 < < /2; cos =...
-
Roller bearings are subject to fatigue failure caused by large contacts loads F (Figure). The problem of finding the location of the maximum stress along the x axis can be shown to be equivalent to...
-
Economic formulas are available to compute annual payments for loans. Suppose that you borrow an amount of money P and agree to repay it in n annual payments at an interest rate of i. The formula to...
-
Develop well-structured programs to (a) Determine the square root of the sum of the square of the elements of a two-dimensional array (i.e., a matrix) and (b) Normalize a matrix by dividing each row...
-
An electronic instrument is to be isolated from a panel that vibrates at frequencies ranging from \(25 \mathrm{~Hz}\) to \(35 \mathrm{~Hz}\). It is estimated that at least 80 percent vibration...
-
An exhaust fan, having a small unbalance, weights \(800 \mathrm{~N}\) and operates at a speed of \(600 \mathrm{rpm}\). It is desired to limit the response to a transmissibility of 2.5 as the fan...
-
The armature of a variable-speed electric motor, of mass \(200 \mathrm{~kg}\), has an unbalance due to manufacturing errors. The motor is mounted on an isolator having a stiffness of \(10 \mathrm{kN}...
Study smarter with the SolutionInn App