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.

Boundary Value Problems for ODEs<br />

Note The demo mat4bvp contains the complete code for this example. The<br />

demo uses nested functions to place all functions required by bvp4c in a single<br />

M-file. To run this example type mat4bvp at the command line. See “BVP<br />

Solver Basic Syntax” on page 5-65 for more information.<br />

1 Rewrite the problem as a first-order system. To use bvp4c, you must<br />

rewrite the equations as an equivalent system <strong>of</strong> first-order differential<br />

equations. Using a substitution y 1 = y and y 2 = y′ , the differential<br />

equation is written as a system <strong>of</strong> two first-order equations<br />

y 1 ′ = y 2<br />

y 2 ′ = –( λ – 2 q cos 2x)y 1<br />

Note that the differential equations depend on the unknown parameter λ .<br />

The boundary conditions become<br />

y 1 ( 0) – 1 = 0<br />

y 2 ( 0) = 0<br />

y 2 ( π) = 0<br />

2 Code the system <strong>of</strong> first-order ODEs. Once you represent the equation as<br />

a first-order system, you can code it as a function that bvp4c can use.<br />

Because there is an unknown parameter, the function must be <strong>of</strong> the form<br />

dydx = odefun(x,y,parameters)<br />

The following code represents the system in the function, mat4ode. Variable<br />

q is shared with the outer function:<br />

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

dydx = [ y(2)<br />

-(lambda - 2*q*cos(2*x))*y(1) ];<br />

end % End nested function mat4ode<br />

See “Finding Unknown Parameters” on page 5-72 for more information<br />

about using unknown parameters with bvp4c.<br />

5-69

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

Saved successfully!

Ooh no, something went wrong!