Section 46-02.mws

Unit 9: Calculus of Variations

Chapter 46: Basic Formalisms

Section 46.2: direct methods

Copyright

Copyright * 2001 by Addison Wesley Longman, Inc.

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America.

Initializations

> restart;

> with(plots):

Warning, the name changecoords has been redefined

>

Introduction

In this section we present two methods for approximating y(x) , the extremal which satisfies the endpoint conditions

y(a) = A

y(b) = B

and which stationarizes the functional

J = Int(f(x,y(x),`y'`(x)),x = a .. b)

First, we examine a finite difference technique of Euler, and then, we consider the Rayleigh-Ritz procedure. Such methods are called direct methods , as opposed to the indirect method of forming and solving the Euler-Lagrange differential equation, which will be seen in the next section.

>

Euler's Method of Finite Differences

Euler's method of finite differences begins by discretizing the interval [a, b] with n+1 equispaced nodes

x[k] = a+k*Delta*x, k = 0, `...`, n

where Delta*x = (b-a)/n . The function-values y(x[k]) are designated as the unknowns y[k] . The derivatives y' ``(x[k]) are replaced with the quotients

(y(x[k+1])-y(x[k]))/Delta/x = (y[k+1]-y[k])/Delta/x...

The integral is then approximated by the finite sum

phi(y[1],`...`,y[n-1]) = Sum(f(x[k],y[k],(y[k+1]-y[...

which becomes a function of the n-1 unknowns y[1], `...`, y[n-1] . Of course, y[0] = y(a) = A , and y[n] = y(b) = B .

The variables y[1], `...`, y[n-1] are then determined by the techniques of calculus.

>

Example 46.1

Consider the function

f(x,y,`y'`) = y^2+``(`y'`)^2+2*y*exp(x)

implemented in Maple as

> f := (x,y,yp) -> y^2+yp^2+2*y*exp(x);

f := proc (x, y, yp) options operator, arrow; y^2+y...

>

where the symbol yp is used to represent the derivative y '.

Let the functional J be given by

J = Int(f(x,y,`y'`),x = 0 .. 1)

with the endpoint conditions being

y(0) = 0

y(1) = exp(1)

The exact solution to this calculus of variations problem is the function

> Y := 1/2*exp(1)*csch(1)*sinh(x)+x/2*exp(x);

Y := 1/2*exp(1)*csch(1)*sinh(x)+1/2*x*exp(x)

>

a solution we will learn to calculate in Sections 46.3 and 46.4. (See Example 46.7.)

The graph of the exact solution is given by

> plot(Y,x=0..1, color=black);

[Maple Plot]

>

That this solution satisfies the endpoint conditions is seen from the following calculations.

> simplify(subs(x=0,Y));
simplify(subs(x=1,Y));

0

exp(1)

>

Since b-a = 1-0 = 1, we have Delta*x = 1/n , and x[k] = k/n . For the moment, n is left unspecified to allow for increasingly more accurate solutions as n is increased.

The function phi is given by

> phi := n -> sum(f(k/n,y[k],(y[k+1]-y[k])/(1/n))*(1/n),k=0..n-1);

phi := proc (n) options operator, arrow; sum(f(k/n,...

>

where we have made it a function of the index n . Thus, for example, if n = 2 , the sum which approximates the functional J is

> phi(2);

1/2*y[0]^2+1/2*(2*y[1]-2*y[0])^2+y[0]+1/2*y[1]^2+1/...

>

Notice that the sum includes the endpoint values y[0] = y(a) and y[n] = y[2] = y(b) . These endpoint values are know, so the approximating sum becomes

> q := subs(y[0]=0,y[2]=exp(1),phi(2));

q := 5/2*y[1]^2+1/2*(2*exp(1)-2*y[1])^2+y[1]*exp(1/...

>

There is but the one unknown, namely, y[1] , corresponding to x[1] = 1/2 . It is determined by setting to zero the derivative with respect to y[1] . This yields

> q1 := solve(diff(q,y[1]),y[1]);

q1 := 4/9*exp(1)-1/9*exp(1/2)

>

The extremal y(x) is being approximated by a linear spline connecting the three points ``(x[k],y[k]), k = 0, 1, 2 . If the x and y coordinates of these points are entered into the lists

> Lx := [0,1/2,1];
Ly := [0,q1,exp(1)];

Lx := [0, 1/2, 1]

Ly := [0, 4/9*exp(1)-1/9*exp(1/2), exp(1)]

>

we can obtain a representation of the approximating spline as

> YY := spline(Lx,Ly,x,linear);

YY := PIECEWISE([(8/9*exp(1)-2/9*exp(1/2))*x, x < 1...

>

A graph of the approximate extremal, in cyan, is compared to the exact extremal, in black, in Figure 46.5.

> plot([YY,Y],x=0..1,color=[cyan,black], labels=[x,y], labelfont=[TIMES,ITALIC,12], xtickmarks=2, ytickmarks=3);

[Maple Plot]

>

There are two ways the value of the functional J might be approximated. First, its value can be taken as the value of the discrete sum phi(y[1]) , obtained in Maple with

> J1 := simplify(subs(y[0]=0,y[1]=q1,y[2]=exp(1),phi(2)));

J1 := 10/9*exp(2)+4/9*exp(3/2)-1/18*exp(1)

>

Since the known values of y[0] and y[n] = y[2] appear in the sum phi(y[1]) , it is necessary to supply those values when evaluating the sum.

An alternate approximation of J can be computed by evaluating it along the piecewise linear path just computed as the approximating linear spline. In this event, we would compute

> J2 := int(f(x,YY,diff(YY,x)),x=0..1);

J2 := 661/243*exp(1)-1/486*exp(3/2)+533/486*exp(2)-...

>

We can also obtain the value of J along the exact extremal. This turns out to be

> J3 := collect(int(f(x,Y,diff(Y,x)),x=0..1),csch);

J3 := (-1/16+1/16*exp(4))*csch(1)^2+(1/2*exp(3)-1/2...

>

The floating-point equivalents for all three values of J are

> evalf(J1);
evalf(J2);
evalf(J3);

10.05090848

14.75582303

14.55773900

>

The first is least accurate. That is because in the passage from J to phi , the extremal y(x) is approximated by a degree zero spline. The value J[1] reflects this use of a lower-degree approximation of the extremal. After the values of the approximating extremal are obtained at the nodes, a linear spline is formed. Hence, J[2] will clearly be a better approximation to the exact stationary value given by J[3] because J[2] is computed by integrating along the more accurate linear spline, and not the degree zero spline used to obtain J[1] .

If we next take n = 3 , we will have two interior nodes at which to compute the solution. The approximating sum for the case n = 3 is

> q := subs(y[0]=0,y[3]=exp(1),phi(3));

q := 10/3*y[1]^2+1/3*(3*y[2]-3*y[1])^2+2/3*y[1]*exp...

>

where we have supplied the known values y[0] = 0 and y[n] = exp(1) . The two unknowns y[1] and y[2] are determined by the ordinary techniques of multivariable calculus. Thus, set to zero the derivatives with respect to each of the unknowns, and solve, obtaining'

> q1 := solve({diff(q,y[1]),diff(q,y[2])},{y[1],y[2]});

q1 := {y[2] = -9/280*exp(1/3)+171/280*exp(1)-19/280...

>

The extremal y(x) is being approximated by a linear spline connecting the four points ``(x[k],y[k]), k = 0, `...`, 3 . If the x and y coordinates of these points are entered into the lists

> Lx := [0,1/3,2/3,1];
Ly := [0,op(subs(q1,[y[1],y[2]])),exp(1)];

Lx := [0, 1/3, 2/3, 1]

Ly := [0, -19/280*exp(1/3)+81/280*exp(1)-9/280*exp(...

>

we can obtain the following representation of the approximating linear spline.

> YY := spline(Lx,Ly,x,linear);

YY := PIECEWISE([(-57/280*exp(1/3)+243/280*exp(1)-2...

>

A comparison between this more accurate spline and the exact extremal is given in Figure 46.6, where the spline is drawn in cyan, and the exact extremal, in black.

> plot([YY,Y],x=0..1,color=[cyan,black], labels=[x,y], labelfont=[TIMES,ITALIC,12], xtickmarks=2, ytickmarks=3);

[Maple Plot]

>

Approximating the value of the functional J with the discrete sum phi(y[1],y[2]) gives

> J4 := simplify(subs(y[0]=0,op(q1),y[3]=exp(1),phi(3)));

J4 := 143/840*exp(4/3)+327/280*exp(2)+57/140*exp(5/...

>

where again, the values y[0] = 0 and y[3] = exp(1) are needed in this sum.

If we evaluate J along the linear spline, we obtain

> J5 := int(f(x,YY,diff(YY,x)),x=0..1);

J5 := 691489/705600*exp(2)+604679/352800*exp(1)-221...

>

Once again, we look at the floating-point equivalents

> evalf(J4);
evalf(J5);
evalf(J3);

11.32849776

14.64679262

14.55773900

>

to see that evaluating the functional along the linear spline gives a more accurate value than phi(y[1],y[2]) , obtained by evaluating the functional along a degree-zero spline.

>

The Rayleigh-Ritz Technique

The Rayleigh-Ritz technique for approximating extremals in the calculus of variations bears some resemblance to the Rayleigh-Ritz approximation scheme (Section 15.3) for solving differential equations. Texts such as [1] point out that the name is sometimes shortened to just the Ritz method since W. Ritz greatly generalized, in 1908 and 1909, the earlier work of Lord Rayleigh.

To approximate the extremal y(x) which stationarizes the functional

J = Int(f(x,y(x),`y'`(x)),x = a .. b)

with respect to curves satisfying the conditions

y(a) = A

y(b) = B

replace y(x) with the sum Phi(x) = phi[0](x) + Sum(c[k]*phi[k](x),k = 1 .. n) , where phi[0](x) satisfies the nonhomogeneous boundary conditions

phi[0](a) = A

phi[0](b) = B

and phi[k](a) = phi[k](b) = 0, k = 1, `...`, n . This makes J become a function of the parameters c[k], k = 1, `...`, n , and the ordinary techniques of multivariable calculus are used to determine values which starionarize J(c[1],`...`,c[n]) . (Note that the same Phi(x) was used in Section 15.3.)

>

Example 46.2

To approximate the extremal which stationarizes the functional

J = Int(f(x,y,`y'`),x = 0 .. 1)

with endpoint conditions

y(0) = 0

y(1) = exp(1)

where f(x,y,`y'`) = y^2+``(`y'`)^2+2*y*exp(x) , that is, the functional of the previous section, we take Phi(x) as

> Phi := x*exp(x)+add(c[k]*x*(x^k-1),k=1..2);

Phi := x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1)

>

The function phi[0](x) = x*exp(x) satisfies the nonhomogeneous boundary conditions, and the functions phi[k](x) = x*(x^k-1), k = 1, 2 , satisfy the homogeneous conditions phi[k](0) = phi[k](1) = 0, k = 1, 2 . This converts the functional J to

> Jc := Int(f(x,Phi,diff(Phi,x)),x=0..1);

Jc := Int((x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1))^2+...
Jc := Int((x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1))^2+...
Jc := Int((x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1))^2+...

>

with value

> Q := value(Jc);

Q := 11/10*c[1]*c[2]+2*exp(1)^2+4*exp(1)*c[2]-2*exp...

>

To determine the parameters c[1] and c[2] , set to zero the derivatives with respect to each parameter, and solve, obtaining

> q := solve({diff(Q,c[1])=0,diff(Q,c[2])=0},{c[1],c[2]});

q := {c[1] = 49800/473*exp(1)-135540/473, c[2] = -2...

>

Hence, the Rayleigh-Ritz approximant becomes

> Phi[1] := subs(q,Phi);

Phi[1] := x*exp(x)+(49800/473*exp(1)-135540/473)*x*...

>

A graph of the exact solution

> Y;

1/2*exp(1)*csch(1)*sinh(x)+1/2*x*exp(x)

>

along with the approximate solution Phi[1] , shows little difference between the two solutions. We have used color (cyan for the approximate solution, and black for the exact) and varied the line thickness (thick for Phi[1] ) to distinguish one curve from the other. However, they are so close as to appear as virtually the same curve.

> plot([Phi[1],Y],x=0..1, color=[cyan,black], thickness=[3,1], labels=[x,y], labelfont=[TIMES,ITALIC,12], xtickmarks=2, ytickmarks=3);

[Maple Plot]

>

The values of J on each curve are computed by

> Je := evalf(Int(f(x,Y,diff(Y,x)),x=0..1));
Jc := evalf(Int(f(x,Phi[1],diff(Phi[1],x)),x=0..1));

Je := 14.55773901

Jc := 14.55784045

>

The functional J , computed on the approximate extremal, is marginally larger than the value on the exact extremal.

>

References

[1] Marvin J. Forray, Variational Calculus in Science and Engineering, McGraw-Hill Book Company, 1968.

>