23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

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.

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

dydx = [ y(2)<br />

-abs(y(1))];<br />

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

res = [ ya(1)<br />

yb(1) + 2];<br />

bvp4c<br />

Form a guess structure consisting of an initial mesh of five equally spaced<br />

points in [0,4] and a guess of constant values y1( x)<br />

≡ 1 and y2( x)<br />

≡ 0 with the<br />

command<br />

solinit = bvpinit(linspace(0,4,5),[1 0]);<br />

Now solve the problem with<br />

sol = bvp4c(@twoode,@twobc,solinit);<br />

Evaluate the numerical solution at 100 equally spaced points and plot<br />

with<br />

x = linspace(0,4);<br />

y = deval(sol,x);<br />

plot(x,y(1,:));<br />

2.5<br />

2<br />

1.5<br />

1<br />

0.5<br />

0<br />

−0.5<br />

−1<br />

−1.5<br />

−2<br />

0 0.5 1 1.5 2 2.5 3 3.5 4<br />

You can obtain the other solution of this problem with the initial guess<br />

yx ( )<br />

2-177

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

Saved successfully!

Ooh no, something went wrong!