Consider the problem sinxx 1 Set up newtons method to obtain

Consider the problem sin(x)=x

1. Set up newtons method to obtain a numerical approximation using X0= 1 obtain at least x > 0

2. In newtons method, you have the term f(x)/f\'(x) and simplify to get N(x)/M(x) =f(x)/f\'(x) after simplification

3. Consider Xn+1 = Xn - N(Xn)/M(Xn)

Implement the method in using matlab and obtain several iterations using X0=0.05 on a table list: n, Xn, f(Xn), f\'(Xn), N(Xn) and M(Xn)

What can you say about this approach?

Solution

% Function Given As Sin(x)=x that can be write as f(x) = sin(x)-x
% Now Solve f(x) using newton Raphson Method
clc;
clear all;
x0 = 1;% initial guess
syms x
func=sin(x)-x; % function definition
df_func=diff(func,x); % function differentiation
iter = 1; % initialize iteration as 1
maxIters=30; % initialize maxIters = 30
fprintf(\'n\\t\\t x0\\t\\t\\t\\t\\t Xnew\\t\\t Func(Xn)\\t\\t Diff(Func(Xn)) \\t N(x_new) \\t\\t\\t M(x_new) \ \ \');
while(iter<=maxIters) % loop till iterations exceeds
func_val=double(subs(func,x0)); % function value calculations
func_dff_val=double(subs(df_func,x0)); % function differentiation calculations
x_new=x0-(func_val/func_dff_val); % new value of x updated
fprintf(\'%d\\t\\t %.6f\\t\\t %.6f\\t\\t %.6f\\t\\t %.6f \\t\\t\\t %.6f \\t\\t\\t%.6f \ \',iter,x0,x_new,double(subs(func,x0)),double(subs(df_func,x0)),double(subs(func,x_new)),double(subs(df_func,x_new)));
x0=x_new;
iter=iter+1; %increment in iteration
end


% this approach minimize the value of given function f=sinx -x, this value tends to zero and we have to calculate the value of x.

%results

n       x0                   Xnew       Func(Xn)       Diff(Func(Xn))    N(x_new)            M(x_new)

1       1.000000       0.655145       -0.158529       -0.459698            -0.045871            -0.207040
2       0.655145       0.433590       -0.045871       -0.207040            -0.013459            -0.092537
3       0.433590       0.288148       -0.013459       -0.092537            -0.003971            -0.041228
4       0.288148       0.191832       -0.003971       -0.041228            -0.001174            -0.018343
5       0.191832       0.127810       -0.001174       -0.018343            -0.000348            -0.008157
6       0.127810       0.085183       -0.000348       -0.008157            -0.000103            -0.003626
7       0.085183       0.056782       -0.000103       -0.003626            -0.000031            -0.001612
8       0.056782       0.037853       -0.000031       -0.001612            -0.000009            -0.000716
9       0.037853       0.025234       -0.000009       -0.000716            -0.000003            -0.000318
10       0.025234       0.016823       -0.000003       -0.000318            -0.000001            -0.000141
11       0.016823       0.011215       -0.000001       -0.000141            -0.000000            -0.000063
12       0.011215       0.007477       -0.000000       -0.000063            -0.000000            -0.000028
13       0.007477       0.004984       -0.000000       -0.000028            -0.000000            -0.000012
14       0.004984       0.003323       -0.000000       -0.000012            -0.000000            -0.000006
15       0.003323       0.002215       -0.000000       -0.000006            -0.000000            -0.000002
16       0.002215       0.001477       -0.000000       -0.000002            -0.000000            -0.000001
17       0.001477       0.000985       -0.000000       -0.000001            -0.000000            -0.000000
18       0.000985       0.000656       -0.000000       -0.000000            -0.000000            -0.000000
19       0.000656       0.000438       -0.000000       -0.000000            -0.000000            -0.000000
20       0.000438       0.000292       -0.000000       -0.000000            -0.000000            -0.000000
21       0.000292       0.000194       -0.000000       -0.000000            -0.000000            -0.000000
22       0.000194       0.000130       -0.000000       -0.000000            -0.000000            -0.000000
23       0.000130       0.000086       -0.000000       -0.000000            -0.000000            -0.000000
24       0.000086       0.000058       -0.000000       -0.000000            -0.000000            -0.000000
25       0.000058       0.000038       -0.000000       -0.000000            -0.000000            -0.000000
26       0.000038       0.000026       -0.000000       -0.000000            -0.000000            -0.000000
27       0.000026       0.000017       -0.000000       -0.000000            -0.000000            -0.000000
28       0.000017       0.000011       -0.000000       -0.000000            -0.000000            -0.000000
29       0.000011       0.000008       -0.000000       -0.000000            -0.000000            -0.000000
30       0.000008       0.000005       -0.000000       -0.000000            -0.000000            -0.000000
>>

For x0=0.05

n       x0                   Xnew       Func(Xn)       Diff(Func(Xn))    N(x_new)            M(x_new)

1       0.050000       0.033332       -0.000021       -0.001250            -0.000006            -0.000555
2       0.033332       0.022221       -0.000006       -0.000555            -0.000002            -0.000247
3       0.022221       0.014814       -0.000002       -0.000247            -0.000001            -0.000110
4       0.014814       0.009876       -0.000001       -0.000110            -0.000000            -0.000049
5       0.009876       0.006584       -0.000000       -0.000049            -0.000000            -0.000022
6       0.006584       0.004389       -0.000000       -0.000022            -0.000000            -0.000010
7       0.004389       0.002926       -0.000000       -0.000010            -0.000000            -0.000004
8       0.002926       0.001951       -0.000000       -0.000004            -0.000000            -0.000002
9       0.001951       0.001301       -0.000000       -0.000002            -0.000000            -0.000001
10       0.001301       0.000867       -0.000000       -0.000001            -0.000000            -0.000000
11       0.000867       0.000578       -0.000000       -0.000000            -0.000000            -0.000000
12       0.000578       0.000385       -0.000000       -0.000000            -0.000000            -0.000000
13       0.000385       0.000257       -0.000000       -0.000000            -0.000000            -0.000000
14       0.000257       0.000171       -0.000000       -0.000000            -0.000000            -0.000000
15       0.000171       0.000114       -0.000000       -0.000000            -0.000000            -0.000000
16       0.000114       0.000076       -0.000000       -0.000000            -0.000000            -0.000000
17       0.000076       0.000051       -0.000000       -0.000000            -0.000000            -0.000000
18       0.000051       0.000034       -0.000000       -0.000000            -0.000000            -0.000000
19       0.000034       0.000023       -0.000000       -0.000000            -0.000000            -0.000000
20       0.000023       0.000015       -0.000000       -0.000000            -0.000000            -0.000000
21       0.000015       0.000010       -0.000000       -0.000000            -0.000000            -0.000000
22       0.000010       0.000007       -0.000000       -0.000000            -0.000000            -0.000000
23       0.000007       0.000004       -0.000000       -0.000000            -0.000000            -0.000000
24       0.000004       0.000003       -0.000000       -0.000000            -0.000000            -0.000000
25       0.000003       0.000002       -0.000000       -0.000000            -0.000000            -0.000000
26       0.000002       0.000001       -0.000000       -0.000000            -0.000000            -0.000000
27       0.000001       0.000001       -0.000000       -0.000000            -0.000000            -0.000000
28       0.000001       0.000001       -0.000000       -0.000000            -0.000000            -0.000000
29       0.000001       0.000000       -0.000000       -0.000000            -0.000000            -0.000000
30       0.000000       0.000000       -0.000000       -0.000000            -0.000000            -0.000000
>>

Consider the problem sin(x)=x 1. Set up newtons method to obtain a numerical approximation using X0= 1 obtain at least x > 0 2. In newtons method, you have t
Consider the problem sin(x)=x 1. Set up newtons method to obtain a numerical approximation using X0= 1 obtain at least x > 0 2. In newtons method, you have t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site