Consider the equation 2x x2 expxcos x Find numerically the
Consider the equation 2x + x^2 = exp(-x)*cos (x). Find numerically the root x of this equation using the MATLAB. Choose zero initial approximations to the root.
Solution
This is the matlab program save it as (.m file)
clc
close all
syms x
f = 2*x+x^2-exp(-x)*cos(x); % funcxion
x_old = 0; % inixial guess
X(1) = x_old;
Y(1) = subs(f,X(1));
x_new = eval(x_old - subs(f,x_old)/subs(diff(f),x_old)); % new valuse ax each ixeraxion
X(2) = x_new;
Y(2) = subs(f,X(2));
a = (x_new-x_old);
r = 3;
while(a>0.01) % convergence condixion
x_new = eval(x_old - subs(f,x_old)/subs(diff(f),x_old));
X(r) = x_new;
Y(r) = subs(f,X(r));
r = r+1;
a = (x_new-x_old);
x_old = x_new;
end
x_new
