Question

Let the mathematical function f(x) be defined as: f(x) = exp(-0.5x) cos(5x)-0.5 , x 〉 0 Write a Matlab function called NewtonTest the algorithm to find the zero as follows. >> [x,f,k-Newton! (O) → x-1.1641, f=-1.6653e-16, k = 7 >> [x,f,k-Newton! (0.1

The function should starts as:

function [x,fs,k]=Newton1(x0)

% enter your code here

end

>> [x,f,k]=Newton1(0)  x = 1.1641, f = -1.6653e-16, k = 7

>> [x,f,k]=Newton1(0.1)  x = 0.1972, f = 1.1102e-16, k = 5

>> [x,f,k]=Newton1(1.5)  x = 1.3111, f = -1.1102e-16, k = 6

>> [x,f,k]=Newton1(2)  Warning iteration diverged, x = 2.8808, f = -0.5624, k = 1000

Let the mathematical function f(x) be defined as: f(x) = exp(-0.5x) cos(5x)-0.5 , x 〉 0 Write a Matlab function called Newton1 that would find the zero based on a passing initial guess as an input argument x0. The function returns the estimated zero location x, the function value at the zero location (f) and the number of iteration k. The iteration function converges if f(%) 10000. When it diverges, it should state so using disp() command. The function should starts as: function [x,fs,k]-Newton1(xo) % enter your code here end
Test the algorithm to find the zero as follows. >> [x,f,k-Newton! (O) → x-1.1641, f=-1.6653e-16, k = 7 >> [x,f,k-Newton! (0.1) → x = 0.1972, f= 1.1102e-16, k :5 >> [x,f,k]-Newton1(1.5) → x= 1.3111, f=-1.1102e-16, k = 6 >> [x,f,k-Newton! (2) → Warning iteration diverged, x-2.8808, f=-0.5624, k = 10001
0 0
Add a comment Improve this question Transcribed image text
Answer #1

%%% Function %%

function [ xz fs k ]=Newton1(x0)
format long
tol=5*eps;
c(1)=x0;
syms x;
f=exp(-0.5*x)*cos(5*x)-0.5 ;
for k=1:1000
l1=subs(f,c(k));
l2=subs(diff(f),c(k));
c(k+1)=c(k)-l1/l2;
l3=(subs(f,c(k+1)));

fs=l3;
xz=c(k+1);
if (abs(l3) < tol)

break;
end
end
end

%%% Test %%%

[x fs k]=Newton1(0);
fprintf(' x= %f \n',x);
fprintf(' fx= %1.32f \n',fs);
fprintf(' k= %f \n',k);
if k>1000
fprintf('Iteration diverged');
end

OUTPUT:

x= 1.164097
fx= -0.00000000000000006861264023336157
k= 7.000000
>>

%%%Test

clc;
close all;
clear all;
format long;

[x fs k]=Newton1(1.5);
fprintf(' x= %f \n',x);
fprintf(' fx= %1.32f \n',fs);
fprintf(' k= %f \n',k);
if k>1000
fprintf('Iteration diverged');
end

OUTPUT:

x= 1.311127
fx= -0.00000000000000002916434802119459
k= 6.000000

%%%Test

clc;
close all;
clear all;
format long;

[x fs k]=Newton1(2);
fprintf(' x= %f \n',x);
fprintf(' fx= %1.32f \n',fs);
fprintf(' k= %f \n',k);
if k>1000
fprintf('Iteration diverged');
end

OUTPUT:

x= 2.399596
fx= -0.24611144691801684070142641758139
k= 1000.000000
Iteration diverged>>

Add a comment
Know the answer?
Add Answer to:
The function should starts as: function [x,fs,k]=Newton1(x0) % enter your code here end >> ...
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
  • Let the mathematical function f(x) be defined as: f(x) = exp(-0.5x) cos(5x)-0.5 , x 〉 0 Write a ...

    Let the mathematical function f(x) be defined as: f(x) = exp(-0.5x) cos(5x)-0.5 , x 〉 0 Write a Matlab function called Newton1 that would find the zero based on a passing initial guess as an input argument x0. The function returns the estimated zero location x, the function value at the zero location (f) and the number of iteration k. The iteration function converges if f(%) < 5*eps and it should diverge if the iteration number k>10000. When it diverges,...

  • Let the mathematical function flu) be defined as: f(x)-exp-0.5x)cos(5x) - 0.5 .x>0 Write a Matlab...

    Please follow the instructions without using other solutions. Thank you in advance Let the mathematical function flu) be defined as: f(x)-exp-0.5x)cos(5x) - 0.5 .x>0 Write a Matlab function called Newton1 that would find the zero based on a passing initial guess as an input argument x0. The function returns the estimated zero location x, the function value at the zero location (f) and the number of iteration k. The iteration function converges if f(%) < 5"eps and it should diverge...

  • in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge wh...

    in matlab -Consider the equation f(x) = x-2-sin x = 0 on the interval x E [0.1,4 π] Use a plot to approximately locate the roots of f. To which roots do the fol- owing initial guesses converge when using Function 4.3.1? Is the root obtained the one that is closest to that guess? )xo = 1.5, (b) x0 = 2, (c) x.-3.2, (d) xo = 4, (e) xo = 5, (f) xo = 27. Function 4.3.1 (newton) Newton's method...

  • 45-3. Modify the code used in Example 4 to find the root only at f(x)<0.01 using...

    45-3. Modify the code used in Example 4 to find the root only at f(x)<0.01 using Newton-Rephson Method without showing any iteration. Also find the root of equation, f(x) = x 9-3x -10, take initial guess, Xo=2 العقدة College of 9:05 mybb.qu.edu.ca Numerical Methods (Lab.) GENG 300 Summer 2020 5.1.2 Open Methods - Newton-Raphson Method f(x) *1+1 = x; - Matlab Code Example:4 function mynewtraph.t1.x0,-) XXO for ilin x - x - x)/1 x) disp 1 x) <0.01 break end...

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

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