15.11.2014 Views

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

MATLAB Mathematics - SERC - Index of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5 Differential Equations<br />

vectorized to improve solver performance. The additional parameter ε is<br />

represented by e and is shared with the outer function.<br />

function dydx = shockODE(x,y)<br />

pix = pi*x;<br />

dydx = [ y(2,:)<br />

-x/e.*y(2,:) - pi^2*cos(pix) - pix/e.*sin(pix) ];<br />

end % End nested function shockODE<br />

function res = shockBC(ya,yb)<br />

res = [ ya(1)+2<br />

yb(1) ];<br />

end % End nested function shockBC<br />

2 Provide analytical partial derivatives. For this problem, the solver<br />

benefits from using analytical partial derivatives. The code below represents<br />

the derivatives in functions shockJac and shockBCJac.<br />

function jac = shockJac(x,y)<br />

jac = [ 0 1<br />

0 -x/e ];<br />

end % End nested function shockJac<br />

function [dBCdya,dBCdyb] = shockBCJac(ya,yb)<br />

dBCdya = [ 1 0<br />

0 0 ];<br />

dBCdyb = [ 0 0<br />

1 0 ];<br />

end % End nested function shockBCJac<br />

shockJac shares e with the outer function.<br />

Tell bvp4c to use these functions to evaluate the partial derivatives by<br />

setting the options FJacobian and BCJacobian. Also set 'Vectorized' to<br />

'on' to indicate that the differential equation function shockODE is<br />

vectorized.<br />

options = bvpset('FJacobian',@shockJac,...<br />

'BCJacobian',@shockBCJac,...<br />

'Vectorized','on');<br />

5-74

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

Saved successfully!

Ooh no, something went wrong!