Obtain an estimate to the solution of this equation (Use Radian) X-0.8 = 0.2 sin
ID: 644455 • Letter: O
Question
Obtain an estimate to the solution of this equation (Use Radian)
X-0.8 = 0.2 sin (X)
(e) Using Newton-Raphson method. Start with x=0.9 as an initial guess and do four iterations. Give an estimate of the absolute error.
(f) Using Simple fixed point iteration. Start with x=0.9 as an initial guess and do four iterations. Give an estimate of the absolute error.
(g) using Secant method. Use the following an initial points x0 = 0.8; x1 = 0.9 and do four iterations. Give an estimate of the relative error.
Explanation / Answer
e)
i = 1;
p0 = 0.9; %initial conditions
N = 4; %maximum number of iterations
error = 0.01; %precision required
syms 'x'
f(x) = x -0.8 - 0.2*sin(x); %function we are solving
df = diff(f); %differential of f(x)
while i <= N
p = p0 - (f(p0)/df(p0)); %Newton-Raphson method
if (abs(p - p0)/abs(p)) < error %stopping criterion when difference between iterations is below tolerance
fprintf('Solution is %f ', double(p))
return
end
i = i + 1;
p0 = p; %update p0
end
fprintf('Solution after %d iterations is %f and absolute error is %f ', N, eval(p), abs(eval(p)-0.9531)) %error for non-convergence within N iterations
f)
i = 1;
p0 = 0.9; %our guess is p = 1.5.
error = 0.0001; %the precision we want to find our solution in.
N = 4; %max number of iterations.
syms 'x'
g(x) = 0.8 + 0.2*sin(x); %i.e. what we are trying to solve
while i <= N
p = g(p0); %the next p value
if abs((p - p0)) < error %stopping criterion using the required precision
fprintf('Solution is %f ', double(p)) %the output p is symbolic so need ot force it into a decimal
return
end
i = i + 1;
p0 = p; %update the value of i and p to continue the loop with
end
fprintf('Solution is %f after %d iterations and absolute error is %f ', eval(p), N, abs(eval(p)-0.9531))
g)
error = 0.0001; %predefine some tolerance.
N = 4; %number of steps
i = 2;
p0 = 0.8; %the two guesses
p1 = 0.9;
syms 'x'
f(x) = x-0.8-0.2*sin(x); %what we are solving for f(x) = 0
q0 = f(p0); %two coressponding values of the function evaluated at po and p1
q1 = f(p1);
while i <= N
p = p1 - (q1*((p1 - p0)/(q1 - q0))); %actual Secant Method (finds x axis intercept between two guesses)
if abs(p - p1) < error %stopping criterion
fprintf('Solution is %f ', double(p))
return
end
i = i + 1;
p0 = p1; %update all the new parameters, po, p1, q0, q1
p1 = p;
q0 = q1;
q1 = f(p);
end
fprintf('Solution is %f after %d iterations and error is %f ',eval(p), N, abs(eval(p)-0.9531))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.