Section46-02.mws

Unit Nine: Calculus of Variations

Chapter 46: Basic Formalisms

Section 46.2:  Direct Methods

Copyright

R Lopez, ADVANCED ENGINEERING MATHEMATICS,  © 2001.    Reproduced by permission of Addison Wesley Longman Inc.  All rights reserved.  No copying or transmitting of this material is allowed without the prior written permission of Addison Wesley Longman Inc.

Initializations

>    restart;

>    with(plots):
with(CurveFitting):

Warning, the name changecoords has been redefined

>   

Introduction

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

  y(a) = A  

  y(b) = B  

and 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[k])/Delta/x)*Delta*x,k = 0 .. n-1)  

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'(x,y,`y'`) = f(x,y,`y'`);

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

>   

where the symbol yp  is used to represent the derivative y ' upon input, and `y'` is used to display the derivative upon output.

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.

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

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,y[k],(y[k+1]-y[k])*n)/n,k = 0 .. n-1) end proc

>   

where we have made it a function of the index n .  Thus, for example, if n = 2 , the sum that 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/2*(2*y[2]-2*y[1])^2+y[1]*exp(1/2)

>   

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/2)

>   

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 .  Writing these points as

>    P0 := [0,0];
P1 := [1/2,q1];
P2 := [1,exp(1)];

P0 := [0, 0]

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

P2 := [1, exp(1)]

>   

we can obtain a representation of the approximating spline as

>    YY := Spline([P||(0..2)],x,degree=1);

YY := PIECEWISE([2*x*(4/9*exp(1)-1/9*exp(1/2)), x < 1/2],[-1/9*exp(1)-2/9*exp(1/2)+2*x*(5/9*exp(1)+1/9*exp(1/2)), otherwise])

>   

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

>    plot([YY,Y],x=0..1,color=[red,black], labels=[x,y], labelfont=[TIMES,ITALIC,12], tickmarks=[2,3], title=`Figure 46.5`);

[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)));
`` = evalf(J1);

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

`` = 10.05090848

>   

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 := simplify(int(f(x,YY,diff(YY,x)),x=0..1));
`` = evalf(J2);

J2 := 1/486*(533*exp(3/2)-exp(1)+1322*exp(1/2)-216)*exp(1/2)

`` = 14.75582304

>   

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);
`` = evalf(J3);

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

`` = 14.55773900

>   

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

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

10.05090848

14.75582304

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(1/3)+1/3*y[2]^2+1/3*(3*exp(1)-3*y[2])^2+2/3*y[2]*exp(2/3)

>   

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[1] = -19/280*exp(1/3)+81/280*exp(1)-9/280*exp(2/3), y[2] = -9/280*exp(1/3)+171/280*exp(1)-19/280*exp(2/3)}

>   

The extremal y(x)  is being approximated by a linear spline connecting the four points ``(x[k],y[k]), k = 0, `...`, 3 .  Writing these points as

>    P0;
P1 := [1/3,eval(y[1],q1)];
P2 := [2/3,eval(y[2],q1)];
P3 := [1,exp(1)];

[0, 0]

P1 := [1/3, -19/280*exp(1/3)+81/280*exp(1)-9/280*exp(2/3)]

P2 := [2/3, -9/280*exp(1/3)+171/280*exp(1)-19/280*exp(2/3)]

P3 := [1, exp(1)]

>   

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

>    YY := Spline([P||(0..3)],x,degree=1);

YY := PIECEWISE([3*x*(-19/280*exp(1/3)+81/280*exp(1)-9/280*exp(2/3)), x < 1/3],[-29/280*exp(1/3)-9/280*exp(1)+1/280*exp(2/3)+3*x*(1/28*exp(1/3)+9/28*exp(1)-1/28*exp(2/3)), x < 2/3],[-27/280*exp(1/3)-47...

>   

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

>    plot([YY,Y],x=0..1,color=[red,black], labels=[x,y], labelfont=[TIMES,ITALIC,12], tickmarks=[2,3], title=`Figure 46.6`);

[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)));
`` = evalf(J4);

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

`` = 11.32849776

>   

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 := simplify(int(f(x,YY,diff(YY,x)),x=0..1));
`` = evalf(J5);

J5 := 1/705600*exp(1/3)*(691489*exp(5/3)-442*exp(4/3)+453827*exp(1)+1209358*exp(2/3)+318089*exp(1/3)-287280)

`` = 14.64679263

>   

Once again, we look at the floating-point equivalents

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

11.32849776

14.64679263

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)  that satisfies the endpoint conditions

  y(a) = A  

  y(b) = B  

and stationarizes the functional

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

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

  phi[0](a) = A  

  phi[0](b) = B  

but 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 that stationarize J(c[1],`...`,c[n]) .  (Note that the same Phi(x)  was used in Section 15.3.)

>   

Example 46.2

To approximate the extremal of Example 46.1, that is, 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) , 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+(exp(x)+x*exp(x)+c[1]*(x-1)+c[1]*x+c[2]*(x^2-1)+2*c[2]*x^2)^2+2*(x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1))*exp(x),x = 0 .. 1)
Jc := Int((x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1))^2+(exp(x)+x*exp(x)+c[1]*(x-1)+c[1]*x+c[2]*(x^2-1)+2*c[2]*x^2)^2+2*(x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1))*exp(x),x = 0 .. 1)
Jc := Int((x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1))^2+(exp(x)+x*exp(x)+c[1]*(x-1)+c[1]*x+c[2]*(x^2-1)+2*c[2]*x^2)^2+2*(x*exp(x)+c[1]*x*(x-1)+c[2]*x*(x^2-1))*exp(x),x = 0 .. 1)

>   

with value

>    Q := value(Jc);

Q := -2*exp(1)*c[1]+4*exp(1)*c[2]+92/105*c[2]^2+11/30*c[1]^2+11/10*c[1]*c[2]+2*exp(1)^2+6*c[1]-10*c[2]

>   

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[2] = -2940/43*exp(1)+7980/43, c[1] = 49800/473*exp(1)-135540/473}

>   

Hence, the Rayleigh-Ritz approximation becomes

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

Phi[1] := x*exp(x)+(49800/473*exp(1)-135540/473)*x*(x-1)+(-2940/43*exp(1)+7980/43)*x*(x^2-1)

>   

In Figure 46.7 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 (red for the approximate solution, and black for the exact) 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=[red,black], thickness=[3,5], labels=[x,y], labelfont=[TIMES,ITALIC,12], tickmarks=[2,3], title=`Figure 46.7`);

[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.