CS计算机代考程序代写 matlab clear all;

clear all;
close all;

epsilon=0.00001;

Delta_t=1;
t=0:Delta_t:2.0/epsilon;

%Preallocating memory
x=zeros(size(t));

x(1)=epsilon;
for n=1:length(t)-1
x(n+1)=x(n)+f(t(n),x(n))*Delta_t;
end

%
%Computing Matlab solution
%
[tmat,xmat]=ode23(@f,[0 2/epsilon],epsilon);

plot(t,x,’ko-‘,tmat,xmat,’bs-‘)
hold on
xlabel(‘t’);
ylabel(‘x’);
legend(‘Explicit Euler’,’MATLAB’);

function dxdt=f(t,x)
dxdt=x*(x-x^2);
end