16.12.2012 Views

Computer Algebra Recipes

Computer Algebra Recipes

Computer Algebra Recipes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

192 CHAPTER 4. NONLINEAR ODE MODELS<br />

and the integrands F and G are entered.<br />

> F:=y(x); G:=sqrt(1+diff(y(x),x)^2);<br />

s<br />

μ<br />

d<br />

F := y(x) G := 1+<br />

dx y(x)<br />

2<br />

Then FF = F + ¸G is formed.<br />

> FF:=F+lambda*G;<br />

s<br />

μ<br />

d<br />

FF := y(x)+¸ 1+<br />

dx y(x)<br />

2<br />

The EulerLagrange commandisappliedtoFF .<br />

> eq:=EulerLagrange(FF,x,y(x));<br />

8<br />

μ<br />

d<br />

>< ¸<br />

dx<br />

eq := 1+<br />

>:<br />

y(x)<br />

2 μ <br />

2 d<br />

y(x)<br />

dx2 Ã μ<br />

d<br />

1+<br />

dx y(x)<br />

μ <br />

2 d<br />

¸ y(x)<br />

dx2 ! ¡ s<br />

2<br />

(3=2) μ<br />

d<br />

1+<br />

dx y(x)<br />

<br />

;<br />

2<br />

s<br />

μ<br />

d<br />

y(x)+¸ 1+<br />

dx y(x)<br />

μ<br />

d<br />

2<br />

dx<br />

¡<br />

y(x)<br />

2<br />

¸<br />

s<br />

μ<br />

d<br />

1+<br />

dx y(x)<br />

9<br />

>=<br />

<br />

= K1<br />

2<br />

>;<br />

The ¯rst integral is extracted from eq by selecting the term that has K1 in it,<br />

and removing the brackets that would otherwise appear in ode.<br />

> ode:=select(has,eq,K[1])[];<br />

s<br />

μ<br />

d<br />

ode := y(x)+¸ 1+<br />

dx y(x)<br />

μ<br />

d<br />

2<br />

dx<br />

¡<br />

y(x)<br />

2<br />

¸<br />

s<br />

μ<br />

d<br />

1+<br />

dx y(x)<br />

<br />

= K1<br />

2<br />

A general analytic solution to the ¯rst-order nonlinear ode is sought, yielding<br />

two answers that di®er by the sign in front of the square root.<br />

> sol:=dsolve(ode,y(x));<br />

p<br />

sol := y(x) =K1 + ¸2 ¡ C1 2 ¡ x2 +2x C1 ;<br />

p<br />

y(x) =K1 ¡ ¸2 ¡ C1 2 ¡ x2 +2x C1<br />

The rhs of, say, the negative square root result (second one) is chosen.<br />

> Y:=rhs(sol[2]);<br />

p<br />

Y := K1 ¡ ¸2 ¡ C1 2 ¡ x2 +2x C1

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

Saved successfully!

Ooh no, something went wrong!