15.11.2014 Views

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Initial Value Problems for ODEs and DAEs<br />

tspan = [0; 10];<br />

y0 = [1+sin((2*pi/(N+1))*(1:N));<br />

repmat(3,1,N)];<br />

options = odeset('Vectorized','on','JPattern',jpattern(N));<br />

[t,y] = ode15s(@f,tspan,y0,options);<br />

u = y(:,1:2:end);<br />

x = (1:N)/(N+1);<br />

surf(x,t,u);<br />

view(-40,30);<br />

xlabel('space');<br />

ylabel('time');<br />

zlabel('solution u');<br />

title(['The Brusselator for N = ' num2str(N)]);<br />

% --------------------------------------------------------------<br />

function dydt = f(t,y)<br />

c = 0.02 * (N+1)^2;<br />

dydt = zeros(2*N,size(y,2)); % preallocate dy/dt<br />

% Evaluate the two components <strong>of</strong> the function at one edge <strong>of</strong><br />

% the grid (with edge conditions).<br />

i = 1;<br />

dydt(i,:) = 1 + y(i+1,:).*y(i,:).^2 - 4*y(i,:) + ...<br />

c*(1-2*y(i,:)+y(i+2,:));<br />

dydt(i+1,:) = 3*y(i,:) - y(i+1,:).*y(i,:).^2 + ...<br />

c*(3-2*y(i+1,:)+y(i+3,:));<br />

% Evaluate the two components <strong>of</strong> the function at all interior<br />

% grid points.<br />

i = 3:2:2*N-3;<br />

dydt(i,:) = 1 + y(i+1,:).*y(i,:).^2 - 4*y(i,:) + ...<br />

c*(y(i-2,:)-2*y(i,:)+y(i+2,:));<br />

dydt(i+1,:) = 3*y(i,:) - y(i+1,:).*y(i,:).^2 + ...<br />

c*(y(i-1,:)-2*y(i+1,:)+y(i+3,:));<br />

% Evaluate the two components <strong>of</strong> the function at the other edge<br />

% <strong>of</strong> the grid (with edge conditions).<br />

i = 2*N-1;<br />

dydt(i,:) = 1 + y(i+1,:).*y(i,:).^2 - 4*y(i,:) + ...<br />

c*(y(i-2,:)-2*y(i,:)+1);<br />

5-27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!