I need the solution to question 1(d) in terms of codes in matlab. I know how to
ID: 3281879 • Letter: I
Question
I need the solution to question 1(d) in terms of codes in matlab. I know how to do the iterations by hand but i cant debug my own codes on matlab hence i need your help. Thank you
1. (All students!) We want to use Newton's method to calculate the smallest positive root x* of the function f(x)sin -…) , x0 . (a) Draw a graph of y-sinx and 1/(1+x) , and use this to explain why the equation sin x = 1/(1 + x), can be expected to have infinitely many positive real solutions. (b) Explain why, as x gets larger, we expect the roots ~ integer× (c) Use the intermediate value theorem to show there must be at least one root in the interval [0,/2] (d) Write a Newton's method routine to calculate the smallest positive root of fix)Explanation / Answer
clc;
clear all;
f=@(x)sin(x)-1/(1+x)^3;%function
f1=@(x)cos(x)+3*(1/(1+x)^4); %derivative of function
x0=0;%initial guess
n=1;
erorr=0.1;
del=1e-10;
x(1)=x0;
m=2;
while (abs(erorr>del))
y1=x0-(f(x0)/f1(x0));% Newton method
erorr(n+1)=abs((y1-x0)); %erorr
% if abs(erorr<1e-3)
% break
%end
x0=y1; % update xold
x(n+1)=x0;
n=1+n;
end
if (n<100)
disp('Root is')
x(end)
disp('num_iter x_value erorr')
disp('_______________________________________________________________________________')
for i=1:n-1
fprintf('%d %20f %20f ',i ,x(i),erorr(i))
end
else
fprintf('The required accuracy is not reached in 100 iteration')
end
%%%%%%%% Solution %%%%%%%
Root is
ans =
0.3855
num_iter x_value erorr
_______________________________________________________________________________
1 0.000000 0.100000
2 0.250000 0.250000
3 0.370396 0.120396
4 0.385304 0.014908
5 0.385483 0.000179
6 0.385483 0.000000
>>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.