Matlab equation solve code
please show me the code for how to solve x=1-e^-2x in Matlab with explanation
show me the code and result
clc;
close all;
clear all;
syms x;
f=@(x) x+exp(-2*x)-1; %Enter the Function here
g=@(x) 1-2*exp(-2*x)+5; %The Derivative of the Function
n=7;
epsilon = 1*10^-(n+1);
x0 = 1;
for i=1:100
f0=vpa(subs(f,x,x0));
f0_der=vpa(subs(g,x,x0));
y=x0-f0/f0_der; % The Formula
err=abs(y-x0);
if err<epsilon %checking the amount of error at each
iteration
break
end
x0=y;
end
y = y - rem(y,10^-n) %Displaying upto required decimal
places
Get Answers For Free
Most questions answered within 1 hours.