Question

This is Matlab Problem and I'll attach problem1 and its answer for reference.

Newtons Method We have already seen the bisection method, which is an iterative root-finding method. The Newton Rhapson methFlrst Iteratlon Initial Guess 4 3 3 2 2 1 0 -1 1 3 0 3 2 -1 0 1 -1 Third Iteration Second Iteration 4 3 2 1 0 C 1 1 2 1 3 -1Problem 1 (Scorelator) Consider the function 5. (2) This function is a transcendental function whose root cannot be solved foEditor - /home/manauwar/newton.m newton.m function r = newton (f,xo, tol, N) symbolic function xl is the initial point % tolEditor /home/manauwar/newton.m Command Window syms x f = x * »r = newton (f , 3, [],10) exp (x) 5; r = 1.3267

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

MATLAB Script:

close all
clear
clc

syms x
f = x*exp(x) - 5;
[r, x_save] = newton(f,3,[],10)
fid = fopen('A2.dat', 'w');
for i = 1:length(x_save)
fprintf(fid, '%f\n', x_save(i));
end
fclose(fid);

function [r, x_save] = newton(f,x0,tol,N)
if nargin < 3 || isempty(tol), tol = 1e-4; end
fp = matlabFunction(diff(f));
f = matlabFunction(f);
x = zeros(1, N+1);
x(1) = x0;
x_save = x(1);
for n = 1:N
if fp(x(n)) == 0
r = 'failure';
end
x(n+1) = x(n) - f(x(n))/fp(x(n));
x_save = [x_save x(n+1)];
if abs(x(n+1) - x(n)) < tol
r = x(n+1);
break
end
end
x_save = x_save(:);
end

Output:

r =
1.3267
x_save =
3.0000
2.3122
1.7637
1.4356
1.3347
1.3268
1.3267

Contents of the file 'A2.dat':

A2.dat 3.000000 2.312234 1.763651 4 1.435621 5 1.334709 1.326770 7 1.326725

Add a comment
Know the answer?
Add Answer to:
This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable...
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)...

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

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

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

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

  • MATLAB Given a table like this one: i xLeft xRightyLeftyRight xNew yNew 3 8.75 10.000 173.05 -200.0. 9.3750 -12.7441 4 8.75 9.3750 173.05 -12.74 9.0625 80.4260 On iteration 5 of Bisection, what is xL...

    MATLAB Given a table like this one: i xLeft xRightyLeftyRight xNew yNew 3 8.75 10.000 173.05 -200.0. 9.3750 -12.7441 4 8.75 9.3750 173.05 -12.74 9.0625 80.4260 On iteration 5 of Bisection, what is xLeft? xRight? Complete the Newton's Method Root Finding code below: function [out] = myNewton (p, x0, tol) % p is a function handle to a non-linear function of x % x0 is an initial guess of the root of p % tol is a tolerance around the...

  • Consider the following function with a real variable, x: ?(?) = ?3 - 3?2 + 6?...

    Consider the following function with a real variable, x: ?(?) = ?3 - 3?2 + 6? + 10 a. Write a Python function for the derivative of f(x) that takes x and returns the derivative of f(x). Take the derivative of f(x) analytically with respect to x before writing the function. b. Write a Python code that approximately finds the real root, x0, of f(x) such that f(x0)~0 using the Newton-Raphson method. The code is expected to get an initial...

  • 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 only What is the function value at the estimated root after one iteration of the...

    Matlab only What is the function value at the estimated root after one iteration of the bisection method for the root finding equation: f(x) = x^3 -x -11 with xl = -4 and xu = 2.5? Select one: a.-0.7500 x O b.-3.2500 o co d. -10.6719 Which of the following statements is false? All open methods for root finding: Select one: a. Is sensitive to the shape of the function X b. Require two initial guesses to begin the algorithm...

  • 13. Write a MATLAB program to find all the roots of a given, twice continuously differentiable,...

    13. Write a MATLAB program to find all the roots of a given, twice continuously differentiable, function f e C2la,b]. on the given interval to find out where it Your program should first probe the function f(x) changes sign. (Thus, the program has, in addition to f itself, four other input arguments: a, b, the number nprobe of equidistant values between a and b at which f is probed, and a tolerance tol.) For each subinterval [a,b;] over which the...

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