Use matlab Growth of biological samples can me modeled using an autonomous first
ID: 671393 • Letter: U
Question
Use matlab Growth of biological samples can me modeled using an autonomous first order differential equation dy/dt=y(1-y/3),y(0)=1 Obtain a solution to this DE using (a) Euler's method using At=.2 and (b) ODE with At=0.2. The analytical solution is given as y(3)=3-6/exp(t)+2 Estimate the MSE in each case. Use a time window from t=0 to t=6. lot the Euler's solutions, ODE solution and analytical solution on a single plot, annotated. The MSE values must also be displayed. Use Matlab to get the EQUILIBRIUM value and determine the time instant when it is reached. Find how long does it take the growth to double from 1.2 to 2.4? Provide answers to part (2) and (3) as comments or display them on the plot.Explanation / Answer
1.
function sequence = eulers(f,a,b,y0,n)
h=(b-a)/n; % interval length
x(1)=a;
y(1)=y0;
for K=1:n
x(n+1)=x(n)+h;
y(n+1)=y(n)+h*f(x(n),y(n));
end
sequence = [x(n),y(n)]
end
clear;
S = [5, 10, 30, 200]; % n-values
numx = length(S);
Y = zeros(1,numx);
for T = 1:numx
Y(T) = eulers(@(x,y) 2*x*y*(1-y),0,2,2, S(T));
end
% calculate the exact solution
fdash = @(x,y) 2*x*y*(1-y);
tspan = [0,2];
yzero = 2;
[xexact,yexact] = ode45(fdash,tspan,yzero);
plot(x,y,'g',xexact,yexact, 'k')
title(['Eulers Method vs Exact Solution'])
legend('Approximate','Exact');
a=0;
b=2;
y0=2;
n=50;
f=@(x,y) 2*x*y*(1-y);
h=(b-a)/n; % interval length
x(1)=a;
y(1)=y0;
for K=1:n
x(K+1)=x(K)+h;
y(K+1)=y(K)+h*f(x(K),y(K));
end
plot (x,y);
2.
step(sys)
step(sys,Tfinal)
step(sys,t)
step(sys1,sys2,...,sysN)
step(sys1,sys2,...,sysN,Tfinal)
step(sys1,sys2,...,sysN,t)
y = step(sys,t)
[y,t] = step(sys)
[y,t] = step(sys,Tfinal)
[y,t,x] = step(sys)
[y,t,x,ysd] = step(sys)
[y,...] = step(sys,...,options)
t = (0:0.1:10)';
[y1, ~, ~, ysd1] = step(sys1,t);
[y2, ~, ~, ysd2] = step(sys2,t);
plot(t, y1, 'b', t, y1+3*ysd1, 'b:', t, y1-3*ysd1, 'b:')
hold on
plot(t, y2, 'g', t, y2+3*ysd2, 'g:', t, y2-3*ysd2, 'g:')
u0 = 1;
[X,~,r] = findop(nlsys, 'steady', 1);
y0 = r.SignalLevels.Output;
sys = linearize(nlsys,u0,X);
opt = stepDataOptions;
opt.InputOffset = u0;
opt.StepAmplitude = 0.1;
t = (0:0.1:10)';
ynl = step(nlsys, t, opt);
plot(t, ynl, t, yl+y0)
legend('Nonlinear', 'Linear with offset')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.