Download
<< Back
OutputCode
%% Question 4 - Blow-up Example
% We investigate the blow-up behaviour of the following ODE:
%
% $$
% \begin{array}{rl}
% x'(t) &= x^2, \\
% x(0) &= 1
% \end{array}
% $$
%% 4(a) - Direction field
% We first plot the direction field of the ODE over $t\in[-1,1]$ and
% $x\in[-2,2]$:
dirfield(@blowupex, -1, 1, -2, 2);
%% 4(b) - Simulation over various time periods
% We first simulate the ODE over the time period $t\in[0,0.99]$ (which
% stops before the blowup will occur)
[t,x] = ode23(@blowupex, [0, 0.99], 1);
figure;
plot(t, x);
xlabel('t');
ylabel('x');
%%
% We now simulate the ODE over the time period $t\in[0,1]$
[t,x] = ode23(@blowupex, [0, 1], 1);
figure;
plot(t, x);
xlabel('t');
ylabel('x');
%%
% We now simulate the ODE over the time period $t\in[0,2]$ (which hits the
% blowup behaviour), we note that an error occurs when trying to solve
[t,x] = ode23(@blowupex, [0, 2], 1);
figure;
plot(t, x);
xlabel('t');
ylabel('x');