Can someone with experience in matlab help me write a succes

Can someone with experience in matlab help me write a successful code that I can run in matlab without problem. Thank you very much
The function f(x) x e cosx has a unique zero a on the interval [-1,0]. With kmax 10, and tol 1 x 10 implement the Newton Method script appearing on Page 66 to obtain an approximation to a. In your solution include a copy of the Newton Method script, a copy of the relevant data table, and state a conclusion.

Solution

clc;
clear all;
f=@(x) x+exp(-x^2)*cos(x); %function

f1=@(x) 1-2*x*exp(-x^2)*cos(x)-exp(-x^2)*sin(x); %derivative of function


x(1)=-0.5;%initial condition
n=10;

for i=1:n
x(i+1)=x(i)-(f(x(i))/f1(x(i))); %Newton method
erorr=abs((x(i+1)-x(i))) %erorr

if abs(erorr<1e-8)
break
end

end
x

erorr =

3.4680e-009


x =

   -0.5000   -0.5892   -0.5884   -0.5884

solution is -0.5884

Can someone with experience in matlab help me write a successful code that I can run in matlab without problem. Thank you very much The function f(x) x e cosx h

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site