Professional Documents
Culture Documents
secondSemODE PDF
secondSemODE PDF
% Dn/Dt = -(k+1)N
% with initial conditions n0 = 17^7 and k=3.5
clear screen
format long
k = 3.5;
eqn='Dn+(k+1)*n=0';
inits='n(0)=17^7';
n=dsolve(eqn,inits,'t');
t=linspace(0,3,100);
z=eval(vectorize(n));
plot(t,z);
title('Exponential Decay Problem');
xlabel('t')
ylabel('y')
clear screen
format long
for n=1:50
if mod(n,2)==1
a(n)=0;
else
a(n)=1;
end
end
plot(a(1:50),'b.');
axis([0,50,-1,2])
% Plotting of solution of 2nd order differential equation
% y" + y = 0
% With initial conditions y(0)=0 and y'(0)=0
% In the interval [0,20]
clear screen
format long
eqn='D2y+y=0';
inits='y(0)=0,Dy(0)=0';
y=dsolve(eqn,inits,'x');
x=linspace(0,20,500);
z=eval(vectorize(y));
plot(x,z);
title('Solution of 2nd Order Differential Equation');
xlabel('x');
ylabel('y');
clear screen
format long
sum=0;
for n=1:50
sum = sum + ((n-1)^2)/(2^(n-1));
partialSum(n) = sum;
end
plot(partialSum(1:50));
% System of ODE
function c_cp_predprey
global beta1 alpha2 c1 c2;
beta1=2.0; alpha2=0.7;
c1=0.01; c2=0.003;
tend = 20; %se the end time to run the simulation
u0 = [400; 80]; % set initial conditions as column vector
[tsol, usol] = ode45(@rhs, [0, tend], u0);
Xsol = usol(:, 1);
Ysol = usol(:, 2);
plot(tsol, Xsol, 'b'); hold on;
plot(tsol, Ysol, 'r--'); hold off;
title('Predatory-Prey Model')
xlabel('time t (years)')
ylabel('Population Density')
legend('Prey','Predators')
clear screen
format long
for n=1:200
ratio(n) = 2*(n./(n+1)).^10;
end
plot(ratio(1:200));
END