Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this exercise, you will use Newton’s method to approximate a real zero of a g

ID: 3199124 • Letter: I

Question

In this exercise, you will use Newton’s method to approximate a real zero of a given function. Theory:A number x is a zero of a function f if f(x)=0. A real zero is an x-intercept of the function. Also, the zeros of a function f are the roots of the equation f ( x ) = 0 . In this exercise, you are estimating a root of the equation f (x) = 0 . You will graph the function and, in part (a), you will choose the initial approximation x0 of the specified zero of f (x). In part (b), the initial approximations will be assigned to you. The number N will represent the number of consecutive iterations for the desired root. The iterations are given by the formula: (1) ?xn+1=xn =n , n 0:N. f (x ) f '(xn ) Note: when f ' is close to zero at the initial point, the process does not work properly. It may converge very slow or may not converge at all. It makes Newton’s method sensitive to the value of the initial approximation. You will be working with two functions: (a)f(x)=arctanx x 1+and?(b)-(c) f(x)=x3 ?x ?1. Part (a) Approximation of the zero of f (x) = arctan x x 1.+ ? **To find the initial approximation x0 , you will create a 2-D line plot interactively using the Plots tab in the MATLAB toolstrip (below is the link to the MATLAB page): https://www.mathworks.com/help/matlab/creating_plots/example--choosing-a-graph- type.html *Open up your diary file and type: x=linspace(0,4,8); y=atan(x)+x-1; Then follow the instruction specified in the link above to create a plot (use the first option under Plots in MATLAB toolstrip). It should give you an output: plot(x,y); figure(gcf). **Save the figure as a JPEG image and place it later in the word document, in which you copy your diary file. **From the graph, choose the initial approximation x of the root of the equation y=0. **Input the function f and its derivative g in your diary file. Type: syms x f=atan(x)+x-1 (Hit: “Enter”) g=diff(f) (Hit: “Enter”) 6 **Create the function function root=newtons(N,x) that outputs the N-th approximation of the actual root with the initial approximation x. **Use format long and program N iterations of the root by formula (1). You can employ “for loop” in your code. Output all N iterations (N will be given comparatively small). Note: You will have to type the actual functions in your code to get their numerical values. For example, if f=atan(x)+x-1 and g=diff(f)=1/(x^2+1)+1, then a consecutive iteration x1 according to the formula (1) is x1=x - (atan(x+x-1))/(1/(x^2+1)+1). **Type the function newtons in your diary file. **InputN=5; **Input your initial approximation x chosen from the plot. **Run the function root=newtons(N,x) . %Compare the intermediate outputs and give an approximation of the root correct to 8 decimal places. (b) ** Create the function function root=newtons_1(N,x) that will approximate the zero of the function f (x)= x3 ?x ?1 which is located on the positive x-axis. **Perform all steps that were outlined in part (b) except do not choose an initial approximation – it will be assigned to you. Note: The plot settings for this function should be x=linspace(0,4,8); y=x .^3-x-1; that is, elementwise power ( . ^) is used to plot the points; however, to type the function f we use the usual power ( ^ ), that is, syms x f=x^3-x-1 (Hit: “Enter”) g=diff(f) (Hit: “Enter”) **Run the function root=newtons_1(N,x) for N=5 (make sure to output all iterations) and for each of the following initial values. (Please use format compact). (1) x=1.5; (2) x=1; (3) x=0.6; (4) x=0.57; 7 %Analyze the outputs for each initial value and give what you think will be an approximation for the root correct to 8 decimal places. (c) **Re-run the function root=newtons_1(N,x) for the initial approximations in parts (3) - (4) and for N=10. Get all intermediate outputs. **Slightly modify the function root=newtons_1(N,x) by suppressing the intermediate outputs and displaying only the N-th approximation of the root – the root itself (put “; “after the corresponding command in the “for loop”). **Re-run the modified function root=newtons_1(N,x) for parts (3) - (4) and for N=100. (Please do not display intermediate outputs!) % Based on the outputs, make a comment in your diary file whether the process converges for the initial values in parts (3) and (4), and, if yes, whether it converge fast or slow. Explain the reason for that. (You might take a look at the plot).

Explanation / Answer

Solution:-

Newton’s Method

a)

function root = newton(N,initital )
   tol = 0.5*10^-5;
   syms x
   f = atan(x)+x-1;
   df = diff(f);
   err = []
root(1) = initital - (f(initital)/df(initital));
err(1) = abs(root(1)-initital);
k = 2;
while (err(k-1) >= tol) && (k <= N)
root(k) = root(k-1) - (f(root(k-1))/df(root(k-1)));
err(k) = abs(root(k)-root(k-1));
k = k+1;
end
end
res = newton(5,1);

-------------------------------------------------------------------------------
b)
function root = newtons_1(N,initital )
   tol = 0.5*10^-5;
   x = linspace(0,4,8);
   f = x.^3-x-1;
   df = diff(f);
   err = []
root(1) = initital - (f(initital)/df(initital));
err(1) = abs(root(1)-initital);
k = 2;
while (err(k-1) >= tol) && (k <= N)
root(k) = root(k-1) - (f(root(k-1))/df(root(k-1)));
err(k) = abs(root(k)-root(k-1));
k = k+1;
end
end
res0 = newtons_1(5,1.5);
res1 = newtons_1(5,1);
res2= newtons_1(5,0.6);
res3= newtons_1(5,0.57);

------------------------------------------------------------------------------------------------
c)
function root = newtons_1(N,initital )
   tol = 0.5*10^-5;
   x = linspace(0,4,8);
   f = x.^3-x-1;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote