64
Solution to Ordinary Differential Equations using Maxima In this chapter we present examples of solutions to ordinary differential equations (ODes) using Maxima. Review of ODE solution methods from the wxMaxima interface In the introduction of menu options and interface buttons for the wxMaxima interface in previous chapters, we came across some simple examples of ODE solutions including general solutions, initial value problems, and boundary value. We review them next. Function ode2 ( Equations > Solve ODE … or [Solve ODE...] button) – General solution to ODE In Chapter 1 (Introduction to Maxima) we introduced a simple ODE solution when illustrating the use of the [ Solve ODE...] button in the wxMaxima interface. This solution is repeated here. Press the [ Solve ODE...] button, or use the menu item “Equations > Solve ODE ...” in the wxMaxima interface, and try the following input: Press the [ OK ] button to obtain: The [ Solve ODE... ] button can be used, therefore, to activate function ode2 to produce the general solution of first and second order ODEs. For example, the 2 nd order ODE: d 2 y dx 2 y =sin 3x , can be solved by using the input: 9 - 1 (c) Gilberto Urroz / Luigi Marino - 2009

Maxima Book Chapter 9

Embed Size (px)

Citation preview

Page 1: Maxima Book Chapter 9

Solution to Ordinary Differential Equations using MaximaIn this chapter we present examples of solutions to ordinarydifferential equations (ODes) using Maxima.

Review of ODE solution methods from the wxMaxima interfaceIn the introduction of menu options and interface buttons for the wxMaxima interface inprevious chapters, we came across some simple examples of ODE solutions includinggeneral solutions, initial value problems, and boundary value. We review them next.

Function ode2 ( Equations > Solve ODE … or [Solve ODE...] button) – General solution to ODE In Chapter 1 (Introduction to Maxima) we introduced a simple ODE solution whenillustrating the use of the [ Solve ODE...] button in the wxMaxima interface. This solutionis repeated here. Press the [ Solve ODE...] button, or use the menu item “Equations >Solve ODE ...” in the wxMaxima interface, and try the following input:

Press the [ OK ] button to obtain:

The [ Solve ODE... ] button can be used, therefore, to activate function ode2 to producethe general solution of first and second order ODEs. For example, the 2nd order ODE:

d 2 y

dx2 y=sin3x ,

can be solved by using the input:

9 - 1 (c) Gilberto Urroz / Luigi Marino - 2009

Page 2: Maxima Book Chapter 9

The result is the following:

The constant of integration in the first solution is referred to as %c, while the two constantsof integration in the second example are %k1 and %k2.

An attempt to find a general solution to a third-order ODE fails:

This input produces a false result:

Function ic1 - Solving an initial value, first-order ODE problem To solve an initial value, first-order ODE problem, you can use the menu item Equations >Initial value problem (1), after you have used function ode2 (see above) to produce ageneral solution. The procedure, thus, requires two steps as illustrated in this example.

Solve the ODE

dydx

y=x

subject to the initial condition

y(0) = 1.

First, use Equations > Solve ODE... to produce the general solution:

9 - 2 (c) Gilberto Urroz / Luigi Marino - 2009

Page 3: Maxima Book Chapter 9

which produces:

Next, use Equations > Initial Value Problem(1) :

which produces:

Alternatively, you could just enter the two inputs directly into an input cell in thewxMaxima 0.8.2 interface, e.g.,

Attempting the solution of a second-order ODE followed by an initial value evaluationproduces an error, e.g.,

9 - 3 (c) Gilberto Urroz / Luigi Marino - 2009

Page 4: Maxima Book Chapter 9

Function ic2 - Solving an initial value, second-order ODE problem The solution to an initial value, second-order ODE problem requires two initial conditions atthe initial point, one is a value of the function, and the second one is a value of thederivative at the same initial point. To solve an initial value, second-order ODE problem inMaxima, first solve the general solution, and then use the menu option Equations > InitialValue Problem(2), as illustrated next.

Solve the ODEd 2 y

dx2 dydx y=0

subject to the initial conditions

y(0) = 1, and dydx

=−1 .

First, select Equations > Solve ODE... and enter:

This produces:

9 - 4 (c) Gilberto Urroz / Luigi Marino - 2009

Page 5: Maxima Book Chapter 9

Then, select Equations > initial Value Problem(2) and enter:

The result is now:

Function bc2 - Solving a boundary value, second-order ODE problem To solve a boundary value, second-order ODE problem it is necessary to provide values ofthe function at two different values of the independent variable. To obtain the solution toa boundary value, second-order ODE problem in Maxima, first obtain a general solution, andthen replace the boundary values using the menu item: “ Equations > Boundary ValueProblem ...”

For example, solve the ODEd 2 ydx2

12

dydx

3y=0

subject to the boundary conditions

y(0) = 1, and y(5) = -1.

First, obtain a general solution by using the menu item Equations > Solve ODE … and enter:

9 - 5 (c) Gilberto Urroz / Luigi Marino - 2009

Page 6: Maxima Book Chapter 9

This produces the general solution:

Next, select the menu item Equations > Boundary Value Problem … and enter:

The result is:

Function desolve - Solving an ODE using Laplace transforms The menu item Equations > Solve ODE with Laplace uses Laplace transforms to obtain thegeneral solution of an ODE of any order. The solutions thus provided could be quite involvedsince they are shown in terms of derivatives of the solution at the initial value of zero forthe independent variable. For example:

That is, the solution to the ODEd 3 y

dx3 y=0

is:

9 - 6 (c) Gilberto Urroz / Luigi Marino - 2009

Page 7: Maxima Book Chapter 9

Replacing initial conditionsIf the initial conditions are known, you can replace them into the general solution by usingfunction subst, available, for example, through the [Subst...] button in the wxMaximainterface. However, in order to produce this substitutions you should be able to writeexpressions for the derivatives at x = 0. For example, to produce the result

use the command:

Thus, if you have produced a general solution such as the one shown above, you canproceed to produced the required substitutions as indicated below. First, produce thesolution using the command:

9 - 7 (c) Gilberto Urroz / Luigi Marino - 2009

Page 8: Maxima Book Chapter 9

Then, substitute the values of the second and first derivatives, and of the function, at x= 0,in that order:

The final result is easier to understand, showing only missing constant such as D2y0, Dy0,and y0, instead of the full expressions for the derivatives.

If you have specific values for these constants, you could substitute them at once using, forexample:

Using initial conditions with the atvalue function If you want to solve an ODE using Laplace transforms, and provide the initial conditionsfrom the start, rather than substituting them after obtaining the solution, you can loadthose initial conditions using function atvalue. This function can be obtained by using themenu item Equations > At Value …

Consider the solution to the second order equation:

d 2 ydx2 2

dydx

5y=0

9 - 8 (c) Gilberto Urroz / Luigi Marino - 2009

Page 9: Maxima Book Chapter 9

subject to the initial conditions

y(0) = 1, and dydx

=−1 .

To solve this problem we could solve this problem as follows. First, define the ODE:

Then, use function atvalue to provide the initial conditions as listed above:

These two entries can be obtained by using the menu item Equations > At Value..., e.g.,

Finally, use function desolve to obtain the solution to the ODE initial value problem:

which produces:

9 - 9 (c) Gilberto Urroz / Luigi Marino - 2009

Page 10: Maxima Book Chapter 9

Additional examples of first-order, initial value ODE solutions (*)This section illustrates the use of functions ode2, and ic1, in the solution of 1st-order ODEs.The examples in this section, and in all sections of this chapter whose titles are markedwith an asterisk (*), were generously contributed by:

Dr. Luigi MarinoProfessor of Informatics and MathematicsLiceo “Camilo Golgi” BRENO, Brescia, Italy

All the examples shown in this section start with a given differential equation (ODE) and aninitial condition y = y0, at x = x0. The general solution consists in using function ode2 toproduce the general solution, followed by a call to function ic1 to substitute the initialcondition into the solution. Plots of the solution then follow.

Example 1 – Solve dydx

=−xy2 x , subject to the initial conditions: y(0) = 3. The solution

using wxMaxima, including a plot y(x), is accomplished as follows:

9 - 10 (c) Gilberto Urroz / Luigi Marino - 2009

Page 11: Maxima Book Chapter 9

Notice that the solution can be simplified algebraically by using function expand, namely:

Example 2 - Solve dydx

=−cos x yexp sin x , subject to the initial conditions: y(0) = 3.

Solution and plot:

Example 3 - Solve dydx

=− yxx , subject to the initial conditions: y(1) = 3.

Solution and plot:

9 - 11 (c) Gilberto Urroz / Luigi Marino - 2009

Page 12: Maxima Book Chapter 9

Example 3 - Solve dydx

=−y 2−1 , subject to the initial conditions: y(0) = 0.

The solution results in an implicit expression:

9 - 12 (c) Gilberto Urroz / Luigi Marino - 2009

Page 13: Maxima Book Chapter 9

An attempt to solve for y, out of this expression produces:

These can be re-written as:

Now we can solve for y:

and produce a plot of the solution:

9 - 13 (c) Gilberto Urroz / Luigi Marino - 2009

Page 14: Maxima Book Chapter 9

Example 4 - Solve dydx

=− x2 y2

2 x y, subject to the initial conditions: y(0) = 0. Also, solve

the ODE using the initial conditions y(2) = 3.

First, we obtain a general solution:

This result includes y(x) in an implicit expression. We can use function ic1 to substitutethe initial condition y(0) = 0, i.e.,

Solving for y indicates that the solutions are imaginary:

Next, we use function ic1 to substitute the second initial condition proposed, y(2) = 3, i.e.,

Solving for y we now find two real solutions:

9 - 14 (c) Gilberto Urroz / Luigi Marino - 2009

Page 15: Maxima Book Chapter 9

A plot of the positive solution is shown next:

Example 5 - Solve dydx

=4 x y4 x y1x2 , subject to the initial conditions: y(0) = 1.

Solution:

A plot is produced using:

9 - 15 (c) Gilberto Urroz / Luigi Marino - 2009

Page 16: Maxima Book Chapter 9

Example 6 - Solve dydx

=−y 2, subject to the initial conditions: y(0) = 0. Also, solve the

ODE using the initial conditions y(1) = 1.

Solution:

Additional examples of second order, initial value ODE solutions (*)This section illustrates the use of functions ode2, and ic2, in the solution of initial-value,2nd-order ODEs. The examples in this section were also generously contributed by:

Dr. Luigi MarinoProfessor of Informatics and MathematicsLiceo “Camilo Golgi” BRENOBrescia, Italy

All the examples shown in this section start with a given differential equation (ODE) and aninitial conditions y = y0 and diff(y,x) = y0p, at x = x0. The general solution consists in usingfunction ode2 to produce the general solution, followed by a call to function ic2 tosubstitute the initial condition into the solution. Plots of the solution then follow.

9 - 16 (c) Gilberto Urroz / Luigi Marino - 2009

Page 17: Maxima Book Chapter 9

Example 1 – Solve d 2 ydx2 −2

dydx

2 y=0 , subject to the initial conditions: y = 2, and

dydx

=−1 , at x = 0.

Solution:

Example 2 – Solve d 2 ydx2 =2

dydx

− y=0 , subject to the initial conditions: y = 1, and

dydx

=0 , at x = 0.

Solution:

9 - 17 (c) Gilberto Urroz / Luigi Marino - 2009

Page 18: Maxima Book Chapter 9

Example 3 – Solve d 2 ydx2 =6

dydx−13 y=0 , subject to the initial conditions: y = 4, and

dydx

=0 , at x = 0.

Solution:

The plot of the solution is shown next:

9 - 18 (c) Gilberto Urroz / Luigi Marino - 2009

Page 19: Maxima Book Chapter 9

Example 4 – Solve d 2 ydx2 =6

dydx−13 y=0 , subject to the initial conditions: y = 4, and

dydx

=0 , at x = 0.

Solution:

A plot of the solution is shown next:

9 - 19 (c) Gilberto Urroz / Luigi Marino - 2009

Page 20: Maxima Book Chapter 9

Example 5 – Solve d 2 ydx2 6

dydx8 y=0 , subject to the initial conditions: y = 1, and

dydx

=1 , at x = 1.

Solution:

A plot of the solution follows:

9 - 20 (c) Gilberto Urroz / Luigi Marino - 2009

Page 21: Maxima Book Chapter 9

Example 6 – Solve 9d 2 ydx2 6

dydx

y=0 , subject to the initial conditions: y = 4, and

dydx

=2 , at x = 0.

Solution:

A plot of the solution is shown next:

9 - 21 (c) Gilberto Urroz / Luigi Marino - 2009

Page 22: Maxima Book Chapter 9

Example 7 – Solve d 2 ydx2 −10

dydx25 y=0 , subject to the initial conditions: y = 3, and

dydx

=−3 , at x = 1.

Solution:

A plot of the solution is shown next:

9 - 22 (c) Gilberto Urroz / Luigi Marino - 2009

Page 23: Maxima Book Chapter 9

Example 8 – Solve d 2 ydx2 −2

dydx

2 y=0 , subject to the initial conditions: y = 2, and

dydx

=−1 , at x = 0.

Solution:

A plot of the solution is shown next:

9 - 23 (c) Gilberto Urroz / Luigi Marino - 2009

Page 24: Maxima Book Chapter 9

Example 9 – Solve 4d 2 ydx2 −8

dydx5 y=0 , subject to the initial conditions: y = 6, and

dydx

=−9 , at x = 0.

Solution:

A plot of the solution follows:

9 - 24 (c) Gilberto Urroz / Luigi Marino - 2009

Page 25: Maxima Book Chapter 9

Example 10 – Solve d 2 ydx2 =−y , subject to the initial conditions: y = 0.5, and

dydx

=1 , at

x = 1.

Solution:

A plot of the solution follows:

9 - 25 (c) Gilberto Urroz / Luigi Marino - 2009

Page 26: Maxima Book Chapter 9

Solutions to systems of ODEs(*)Function desolve can be used to solve systems of ODEs, in combination with functionatsolve to evaluate initial/boundary conditions. The general procedure consists of thefollowing steps (Use the command kill(all) to clear Maxima's memory):

1 - Define the various differential equations that constitute the system by assigning them tovariables, e.g., ode1, ode2, etc., for example:

ode1 : 'diff(f(x), x) + f(x) = …;ode2 : 'diff(g(x),x) + g(x) = …;

2 – Put together all the equations thus defined into a single variable, e.g.,

ode_syst : [ ode1, ode2, ... ];

3 – Use function atvalue to load initial/boundary conditions for the ODEs, e.g.,

atvalue( f(x), x = a, b);atvalue( g(x), x = c, d);

4 – Call function desolve with the form: desolve(ode_syst, [f(x),g(x), …]), where f(x), g(x),…, etc., are the functions we are solving for in the system of equations.

The following examples were provided by Dr. Luigi Marino, Professor of Informatics andMathematics, Liceo “Camilo Golgi” BRENO, Brescia, Italy.

9 - 26 (c) Gilberto Urroz / Luigi Marino - 2009

Page 27: Maxima Book Chapter 9

031ode_systems.wxm 1 / 6

Example 1 - A system of two second order ODEs

(%i1) kill(all);(%o0) done

(%i1) diff_eq1: 'diff(f(x),x,2) + 'diff(g(x),x) + 3*f(x) = 15*exp(-x);

(%o1) d

d xg x( )+

d2

d x 2f x( )+ 3 f x( )= 15 %e- x

(%i2) diff_eq2: 'diff(g(x), x, 2) - 4*'diff(f(x), x) + 3*g(x) = 15*sin(2*x);

(%o2) d2

d x 2g x( )- 4

d

d xf x( )

+ 3 g x( )= 15 sin 2 x( )

(%i3) ode_syst: [diff_eq1, diff_eq2];

(%o3) [d

d xg x( )+

d2

d x 2f x( )+ 3 f x( )= 15 %e- x ,

d2

d x 2g x( )- 4

d

d xf x( )

+ 3 g x( )= 15 sin 2 x( )]

(%i4) atvalue (f(x), x=0, 35);(%o4) 35

(%i5) atvalue ('diff(f(x),x),x=0, -48);(%o5) - 48

(%i6) atvalue (g(x), x=0, 27);(%o6) 27

(%i7) atvalue ('diff(g(x), x), x=0, -55);(%o7) - 55

(%i8) desolve(ode_syst, [f(x), g(x)]);

(%o8) [ f x( )= - 15 sin 3 x( )+ 2 cos 2 x( )+ 30 cos x( )+ 3 %e- x , g x( )= 30 cos 3 x( )+ sin 2 x( )- 60

sin x( )- 3 %e- x ]

Example 2 - A system of three first-order ODEs

(%i9) kill(all);(%o0) done

(%i1) eq1:'diff(f(x),x)=g(x)+m(x)-3*f(x);

(%o1) d

d xf x( )= m x( )+ g x( )- 3 f x( )

9 - 27 (c) Gilberto Urroz / Luigi Marino - 2009

Page 28: Maxima Book Chapter 9

031ode_systems.wxm 2 / 6

(%i2) eq2:'diff(g(x),x)=f(x)+m(x)-3*g(x);

(%o2) d

d xg x( )= m x( )- 3 g x( )+ f x( )

(%i3) eq3:'diff(m(x),x)=f(x)+g(x)-3*m(x);

(%o3) d

d xm x( )= - 3 m x( )+ g x( )+ f x( )

(%i4) sist:[eq1,eq2,eq3];

(%o4) [d

d xf x( )= m x( )+ g x( )- 3 f x( ),

d

d xg x( )= m x( )- 3 g x( )+ f x( ),

d

d xm x( )= - 3 m x( )+ g x( )+

f x( )]

(%i5) atvalue(f(x),x=0,1);(%o5) 1

(%i6) atvalue(g(x),x=0,2);(%o6) 2

(%i7) atvalue(m(x),x=0,-1);(%o7) - 1

(%i8) desolve(sist,[f(x),g(x),m(x)]);

(%o8) [ f x( )=2 %e - x

3+%e - 4 x

3, g x( )=

2 %e - x

3+4 %e - 4 x

3, m x( )=

2 %e - x

3-5 %e - 4 x

3]

(%i9) wxplot2d([(2*%e^(-x))/3+%e^(-4*x)/3,(2*%e^(-x))/3+(4*%e^(-4*x))/3,(2*%e^(-x))/3-(5*%e^(-[y,-5,5], [gnuplot_preamble, "set grid;"])$

plot2d: expression evaluates to non-numeric value somewhere in plotting range.plot2d: expression evaluates to non-numeric value somewhere in plotting range.plot2d: expression evaluates to non-numeric value somewhere in plotting range.

(%t9)

9 - 28 (c) Gilberto Urroz / Luigi Marino - 2009

Page 29: Maxima Book Chapter 9

031ode_systems.wxm 3 / 6

Example 3 - A system of 2 first-order ODEs

(%i10) eq1:'diff(f(x),x)=f(x)+g(x)+sin(x);

(%o10) d

d xf x( )= sin x( )+ g x( )+ f x( )

(%i11) eq2:'diff(g(x),x)=-f(x)+3*g(x);

(%o11) d

d xg x( )= 3 g x( )- f x( )

(%i12) sist:[eq1,eq2];

(%o12) [d

d xf x( )= sin x( )+ g x( )+ f x( ),

d

d xg x( )= 3 g x( )- f x( )]

(%i13) atvalue(f(x),x=0,-9/25);

(%o13) -9

25

(%i14) atvalue(g(x),x=0,-4/25);

(%o14) -4

25

(%i15) desolve(sist,[f(x),g(x)]);

(%o15) [ f x( )= -13 sin x( )

25-9 cos x( )

25, g x( )= -

3 sin x( )

25-4 cos x( )

25]

(%i16) wxplot2d([-(13*sin(x))/25-(9*cos(x))/25,-(3*sin(x))/25-(4*cos(x))/25], [x,-5,5], [gnuplot_preamble, "set grid;"])$

(%t16)

9 - 29 (c) Gilberto Urroz / Luigi Marino - 2009

Page 30: Maxima Book Chapter 9

031ode_systems.wxm 4 / 6

Example 4 - A system of two second-order ODEs

(%i17) kill(all);(%o0) done

(%i1) eq1:'diff(f(x),x,2)=-4*f(x)-3*g(x);

(%o1) d2

d x 2f x( )= - 3 g x( )- 4 f x( )

(%i2) eq2:'diff(g(x),x,2)=-8*f(x)-2*g(x);

(%o2) d2

d x 2g x( )= - 2 g x( )- 8 f x( )

(%i3) sist:[eq1,eq2];

(%o3) [d2

d x 2f x( )= - 3 g x( )- 4 f x( ),

d2

d x 2g x( )= - 2 g x( )- 8 f x( )]

(%i4) atvalue(f(x),x=0,3);(%o4) 3

(%i5) atvalue('diff(f(x),x),x=0,0);(%o5) 0

(%i6) atvalue(g(x),x=0,4);(%o6) 4

(%i7) atvalue('diff(g(x),x),x=0,0);(%o7) 0

(%i8) desolve(sist, [f(x), g(x)]);

(%o8) [ f x( )= 3 cos 23 2/ x( ), g x( )= 4 cos 23 2/ x( )]

9 - 30 (c) Gilberto Urroz / Luigi Marino - 2009

Page 31: Maxima Book Chapter 9

031ode_systems.wxm 5 / 6

(%i9) wxplot2d([3*cos(2^(3/2)*x),4*cos(2^(3/2)*x)], [x,-5,5],[y,-5,5] ,[gnuplot_preamble, "set grid;"])$

(%t9)

Example 5 - A system of two first-order ODEs

(%i10) kill(all);(%o0) done

(%i1) eq1:'diff(f(x),x)=-g(x)+x*sin(x);

(%o1) d

d xf x( )= x sin x( )- g x( )

(%i2) eq2:'diff(g(x),x)=-f(x)+x*cos(x);

(%o2) d

d xg x( )= x cos x( )- f x( )

(%i3) sist:[eq1,eq2];

(%o3) [d

d xf x( )= x sin x( )- g x( ),

d

d xg x( )= x cos x( )- f x( )]

(%i4) atvalue(f(x),x=0,1);(%o4) 1

(%i5) atvalue(g(x),x=0,1);(%o5) 1

(%i6) desolve(sist, [f(x), g(x)]);

(%o6) [ f x( )= -sin x( )

2+%e x

4+3 %e - x

4, g x( )= x sin x( )+

cos x( )

2-%e x

4+3 %e - x

4]

9 - 31 (c) Gilberto Urroz / Luigi Marino - 2009

Page 32: Maxima Book Chapter 9

031ode_systems.wxm 6 / 6

(%i7) wxplot2d([-sin(x)/2+%e^x/4+(3*%e^(-x))/4,x*sin(x)+cos(x)/2-%e^x/4+(3*%e^(-x))/4], [x,-5,[y,-10,10] ,[gnuplot_preamble, "set grid;"])$

plot2d: expression evaluates to non-numeric value somewhere in plotting range.plot2d: expression evaluates to non-numeric value somewhere in plotting range.

(%t7)

(%i8) f1:-sin(t)/2+%e^t/4+(3*%e^(-t))/4;f2:t*sin(t)+cos(t)/2-%e^t/4+(3*%e^(-t))/4;

(%o8) -sin t( )

2+%e t

4+3 %e - t

4

(%o9) t sin t( )+cos t( )

2-%e t

4+3 %e - t

4

(%i10) wxplot2d([['parametric, f1, f2, [t, 0, 2], [nticks, 300]]], [x,0.45,0.78],[y,0.695,0.715], [gnuplot_preamble, "set grid;"])$

(%t10)

9 - 32 (c) Gilberto Urroz / Luigi Marino - 2009

Page 33: Maxima Book Chapter 9

Converting higher order ODEs to a system of first-order ODEsA couple of examples presented earlier demonstrate that it is possible to solve higher-orderODEs using functions desolve and atvalue directly. It is also possible to convert a higher-order ODE into a system of first-order ODEs and solved the system as indicated in thesection immediately above.

To illustrate the second approach, consider the following equation:

d 3 ydx3 4

d 2 ydx2 −8

dydx

5 y=0 ,

subject to y(0) = 1, y'(0) = -1, y''(0) = 0.5.

The equation can be written also as

y''' = -5y – 8y' – 4y'',

and the following substitutions made:

u1 = y, u2 = y ' = u1', u3 = y'' = u2'

Next, replace y''' with u3' = y''' in the ODE, together with the other variable replacements, toget:

u3' = -5 u1 -8 u2 – 4 u3.

The variable conversions defined above can be re-written as: u1' = u2, u2' = u3, whichtogether with u3' = -5 u1 -8 u2 – 4 u3., produce the following system of first-order ODEs:

u1' = u2

u2' = u3

u3' = -5 u1 -8 u2 – 4 u3.

which can be written as a single, first-order, vector ODE:

ddx [u1

u2

u3]=[ u2

u3

−5u1−8u2−4u3] .

The initial conditions get converted to u1(0) = 1, u2(0) = -1, u3 (0)= 0.5.

The following Maxima commands show the solution to this system of equations, includingplots of the three functions solved for, namely, u1, u2, and u3, representing the solutiony(x) and its first two derivatives, respectively.

9 - 33 (c) Gilberto Urroz / Luigi Marino - 2009

Page 34: Maxima Book Chapter 9

ThirdOrderToLinearSystem.wxm 1 / 3

Example 1 - Solving a 3rd-order ODE as a system of 1st-order ODEs

First, define the three ODEs:

(%i3) ode1: diff(u1(x),x)=u2(x);

(%o3) d

d xu1 x( )= u2 x( )

(%i4) ode2: diff(u2(x),x)=u3(x);

(%o4) d

d xu2 x( )= u3 x( )

(%i5) ode3: diff(u3(x),x)=-5*u1(x)-8*u2(x)-4*u3(x);

(%o5) d

d xu3 x( )= - 4 u3 x( )- 8 u2 x( )- 5 u1 x( )

Next, create the system:

(%i6) ode_syst : [ode1,ode2,ode3];

(%o6) [d

d xu1 x( )= u2 x( ),

d

d xu2 x( )= u3 x( ),

d

d xu3 x( )= - 4 u3 x( )- 8 u2 x( )- 5 u1 x( )]

Replace the initial conditions:

(%i7) atvalue(u1(x),x=0,1);(%o7) 1

(%i8) atvalue(u2(x),x=0,-1);(%o8) - 1

(%i9) atvalue(u3(x),x=0,0.5);(%o9) 0.5

Solve for the ODE system, store solution into variable 'solns':

9 - 34 (c) Gilberto Urroz / Luigi Marino - 2009

Page 35: Maxima Book Chapter 9

ThirdOrderToLinearSystem.wxm 2 / 3

(%i12) solns : desolve(ode_syst,[u1(x),u2(x),u3(x)]);rat: replaced -0.5 by -1/2 = -0.5

(%o12) [ u1 x( )= %e-3 x

2

sin11 x

2

6 11+

cos11 x

2

6

+

5 %e - x

6, u2 x( )= %e

-3 x

2

-

7 sin11 x

2

6 11-

cos11 x

2

6

-

5 %e - x

6, u3 x( )= %e

-3 x

2

8 sin11 x

2

3 11-

cos11 x

2

3

+

5 %e - x

6]

Extract solution components using function "rhs" (right-hand side):

(%i14) wxplot2d(rhs(solns[1]),[x,-5,5], [y,-5,5],[gnuplot_preamble, "set grid;"])$plot2d: expression evaluates to non-numeric value somewhere in plotting range.

(%t14)

9 - 35 (c) Gilberto Urroz / Luigi Marino - 2009

Page 36: Maxima Book Chapter 9

ThirdOrderToLinearSystem.wxm 3 / 3

(%i15) wxplot2d(rhs(solns[2]),[x,-5,5], [y,-5,5],[gnuplot_preamble, "set grid;"])$plot2d: expression evaluates to non-numeric value somewhere in plotting range.

(%t15)

(%i16) wxplot2d(rhs(solns[3]),[x,-5,5], [y,-5,5],[gnuplot_preamble, "set grid;"])$plot2d: expression evaluates to non-numeric value somewhere in plotting range.

(%t16)

9 - 36 (c) Gilberto Urroz / Luigi Marino - 2009

Page 37: Maxima Book Chapter 9

Numerical solutions to ODEs – Function rkFunction rk (runge-kutta) is used to obtain the numerical solution of a single ODE or of asystem of ODEs using a fourth-order Runge-Kutta numerical approach. Find informationabout function rk by opening the Maxima manual, using Help > Maxima Help, and typing rkin the index search box, then pressing [Enter]. The following information is provided:_______________________________________________________________________________

_______________________________________________________________________________The following examples illustrate the use of rk for the numerical calculation of single ODEsor systems of ODEs. The single ODE or the system of ODEs must be represented by a first-order equation of the form dx/dt = f(t,x). Follow the examples to understand the differentfunctions involved in their solutions.

The results of function rk are presented in the form of a list of points, each containing twoor more elements. These lists can be manipulated to produce lists of points for plotting.Some of the list functions that you will see used in these examples include: makelist, first,second, third, length, and rest. Information on these functions is available through theMaxima manual (Help > Maxima Help). Select the Contents tab and find the Lists chapter.Click on it to open it, and then click on each of the two sections therein contained:Introduction to Lists, and Functions and Variables for Lists.

Plots of the solutions are presented using functions wxplot2d or wxdraw2d (see Chapter 4).

9 - 37 (c) Gilberto Urroz / Luigi Marino - 2009

Page 38: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 1 / 24

Load "draw" package to use for plotting solutions.

(%i11) load(draw)$

Example 1

dx/dt = t - x^2, x(0)=1, 0 < t < 8, Dt = 0.1

rk solution:

(%i2) sol: rk(t-x^2,x,1,[t,0,8,0.1])$

Plot using "wxplot2d"

(%i3) wxplot2d([discrete,sol], [x,0,8], [gnuplot_preamble, "set grid;"])$

(%t3)

Prepare a list of values to plot using "wxdraw2d" from the "draw" package

(%i4) sol_pts: makelist( rest(sol[i]),i,1,length(sol))$

9 - 38 (c) Gilberto Urroz / Luigi Marino - 2009

Gilberto E. Urroz
Text Box
All the examples presented below were provided by Dr. Luigi Marino, Professor of Informatics and Mathematics, Liceo "Camillo Golgi" BRENO, Brescia, Italy.
Page 39: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 2 / 24

(%i5) wxdraw2d( color=magenta,point_size=0,points_joined=true, points(sol))$

(%t5)

Example 2

Cooling law: dx/dt = -k*(T-Ta)

(%i6) kill(all);(%o0) done

(%i1) dx/dt=-0.0866188656*(x-75);

(%o1) dx

dt= - 0.0866188656 x - 75( )

(%i2) sol:rk(-0.0866188656*(x-75) ,x ,350,[t,0,65,0.5] )$

(%i3) wxdraw2d(grid=true,color=magenta,point_size=0.1,points_joined=true, points(sol))$

9 - 39 (c) Gilberto Urroz / Luigi Marino - 2009

Page 40: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 3 / 24

(%i4) wxplot2d([discrete,sol], [x,0,65], [y,0,350], [gnuplot_preamble, "set grid;"])$

(%t4)

Example 3:

dy/dx = cos(x)+exp(sin(x))

(%i5) sol:rk(cos(x)*y+exp(sin(x)),y,3,[x,0,15,0.1])$

(%i6) wxdraw2d(grid=true,yrange=[-1,35],color=green,point_size=0.1,points_joined=true, points

(%t6)

Example 4 - System of equations:

9 - 40 (c) Gilberto Urroz / Luigi Marino - 2009

Page 41: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 4 / 24

dx/dt =4-x^2-4*y^2, dy/dt = y^2-x^2+1x(0)=-1.25, y(0)=0.75, 0<t<4, Dt=0.02

(%i7) sol: rk([4-x^2-4*y^2,y^2-x^2+1],[x,y],[-1.25,0.75],[t,0,4,0.02])$

"sol1" = list of x-vs-t, "sol2" = list of y-vs-t, "sol3" = list of y-vs-x

(%i8) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

(%i9) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

(%i10) sol3:makelist([second(sol[i]),third(sol[i])],i,1,length(sol))$

Drawing the three lists produced above. Click off graph to continue.

(%i11) load("draw");(%o11) C:/PROGRA~2/MAXIMA~1.1/share/maxima/5.18.1/share/draw/draw.lisp

(%i12) wxdraw2d(grid=true,yrange=[-1,2],color=red,point_size=0.1,points_joined=true, points(so

(%t12)

9 - 41 (c) Gilberto Urroz / Luigi Marino - 2009

Page 42: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 5 / 24

(%i13) wxdraw2d(grid=true,yrange=[-1,2],color=blue,point_size=0.1,points_joined=true, points

(%t13)

(%i14) wxdraw2d(grid=true,yrange=[-1,2],color=green,point_size=0.1,points_joined=true, points

(%t14)

Example 5 - 2nd-order equation into a system

Solve: y''=(2*(y')^2+y^2)/y with init. conds: x=4, y=2, y'=-2*tan(1)= -3.114815 producing a system of ODEs by sustitution u1 = y, u2 = y'. The system now is:du1/dx = u2du2/dx = (2*u2^2+u1^2)/u1with u1 = 2, u2 = -3.114815 at x = 4

(%i15) kill(all); sol : rk([u2,(2*u2^2+u1^2)/u1],[u1,u2],[2,-3.114815],[t,4,6,0.1])$

(%o0) done

9 - 42 (c) Gilberto Urroz / Luigi Marino - 2009

Page 43: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 6 / 24

(%i2) sol_m:transpose(sol)$

(%i3) sol_pts: makelist( rest(sol[i]),i,1,length(sol))$

(%i4) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

(%i5) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

(%i6) wxdraw2d(grid=true,yrange=[0,2],color=green,point_size=0.1,points_joined=true, points(so

(%t6)

(%i7) wxdraw2d(points_joined = true, yrange=[0,2], grid=true, line_width = 1, color = "light-red", points(sol) )$

9 - 43 (c) Gilberto Urroz / Luigi Marino - 2009

Page 44: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 7 / 24

(%i8) wxplot2d([discrete,sol1],[style,[lines,1,6]],[gnuplot_preamble, "set grid;"]);

(%t8)

(%o8)

(%i9) wxplot2d([discrete,sol2],[style,[lines,1,2]],[gnuplot_preamble, "set grid;"]);

(%t9)

(%o9)

(%i10) wxdraw2d(grid=true,yrange=[-4,4],color=green,point_size=0.1,points_joined=true, points

9 - 44 (c) Gilberto Urroz / Luigi Marino - 2009

Page 45: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 8 / 24

(%i11) wxdraw2d(grid=true,yrange=[-3,3],color=green,point_size=0.1,points_joined=true, points

(%t11)

Example 6 - system of equations:

dy1/dt = y2, dy2/dt = y3, dy3/dt = y1

(%i12) kill(all);sol:rk([y2,y3,y1],[y1,y2,y3],[2,-1,-1],[t,0,8,0.1])$(%o0) done

(%i2) wxdraw2d(grid=true,yrange=[-1,2],color=green,point_size=0.1,points_joined=true, points(s

(%t2)

9 - 45 (c) Gilberto Urroz / Luigi Marino - 2009

Page 46: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 9 / 24

(%i3) wxplot2d([discrete,sol],[style,[points,1,2]],[gnuplot_preamble, "set grid;"]);

(%t3)

(%o3)

Example 7 - system of equations

dy1/dt = y2+y3-2*y1, dy2/dt = y1+y3-3*y2, dy3/dt = y1+y2-3*y3

(%i4) kill(all);(%o0) done

(%i1) sol:rk([y2+y3-3*y1,y1+y3-3*y2,y1+y2-3*y3],[y1,y2,y3],[1,2,-1],[t,0,8,0.1])$

(%i2) sol1:transpose(sol)$

9 - 46 (c) Gilberto Urroz / Luigi Marino - 2009

Page 47: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 10 / 24

(%i3) load(draw); wxdraw2d(grid=true,yrange=[-1,1],color=green,point_size=0.1,points_joined=true, points(s

(%o3) C:/PROGRA~2/MAXIMA~1.1/share/maxima/5.18.1/share/draw/draw.lisp

(%t4)

(%i5) sol2:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

(%i6) sol3:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

(%i7) sol4:makelist([first(sol[i]),fourth(sol[i])],i,1,length(sol))$

(%i8) wxdraw2d(grid=true,yrange=[-1,1],color=green,point_size=0.1,points_joined=true, points(s

(%t8)

9 - 47 (c) Gilberto Urroz / Luigi Marino - 2009

Page 48: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 11 / 24

(%i9) wxplot2d([[discrete,sol4],[discrete,sol3],[discrete,sol2]] ,[style,[points,1]],[y,-1,2],[gnuplot_preamble, "set grid;"]);

(%t9)

(%o9)

Example 8 - system of equations

dy1/dt = y1+y2+sin(x), dy2/dt = -y1+3*y2

(%i10) kill(all);(%o0) done

(%i1) sol:rk([y1+y2+sin(x),-y1+3*y2],[y1,y2],[-9/25,-4/25],[x,0,15,0.5])$

(%i2) sol1:transpose(sol)$

(%i3) solList1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$solList2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$solList3:makelist([second(sol[i]),third(sol[i])],i,1,length(sol))$

9 - 48 (c) Gilberto Urroz / Luigi Marino - 2009

Page 49: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 12 / 24

(%i6) wxdraw2d(grid=true,yrange=[-1,10],color=green,point_size=0.1,points_joined=true, points

(%t6)

(%i7) wxdraw2d(grid=true,yrange=[-1,10],color=green,point_size=0.1,points_joined=true, points

(%t7)

9 - 49 (c) Gilberto Urroz / Luigi Marino - 2009

Page 50: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 13 / 24

(%i8) wxdraw2d(grid=true,color=green,point_size=0.1,points_joined=true, points(solList3))$

(%t8)

Example 9 - system of equations

dy1/dt = y2, dy2/dt = -4*y1-3*y3, dy3/dt = y4, dy4/dt = -8*y1-2*y3

(%i9) kill(all);(%o0) done

(%i1) sol:rk([y2,-4*y1-3*y3,y4,-8*y1-2*y3],[y1,y2,y3,y4],[3,0,4,0],[x,0,4.442882938,0.1])$

(%i2) wxdraw2d(grid=true,yrange=[-5,5],color=green,point_size=0.1,points_joined=true, points(s

(%t2)

(%i3) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

9 - 50 (c) Gilberto Urroz / Luigi Marino - 2009

Page 51: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 14 / 24

(%i4) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

(%i5) wxdraw2d(grid=true,yrange=[-8,8],color=blue,point_size=0.1,points_joined=true, points(so

(%t5)

(%i6) sol3:makelist([first(sol[i]),fourth(sol[i])],i,1,length(sol))$

(%i7) wxdraw2d(grid=true,yrange=[-8,8],color=magenta,point_size=0.1,points_joined=true, points

(%t7)

9 - 51 (c) Gilberto Urroz / Luigi Marino - 2009

Page 52: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 15 / 24

(%i8) wxplot2d([[discrete,sol1],[discrete,sol3],[discrete,sol2]] ,[style,[points,1]],[y,-6,6],[gnuplot_preamble, "set grid;"]);

(%t8)

(%o8)

(%i9) wxplot2d([[discrete,sol1],[discrete,sol3],[discrete,sol2]] ,[style,lines],[y,-9,9],[gnuplot_preamble, "set grid;"]);

(%t9)

(%o9)

Example 10 - system of equations

dx/dt = y, dy/dt = -sin(x)

(%i10) kill(all);(%o0) done

9 - 52 (c) Gilberto Urroz / Luigi Marino - 2009

Page 53: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 16 / 24

(%i1) sol:rk([y,-sin(x)],[x,y],[0,1],[x,0,3.14159,0.1])$

(%i2) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

(%i3) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

(%i4) sol3:makelist([second(sol[i]),third(sol[i])],i,1,length(sol))$

(%i5) wxplot2d([discrete,sol1],[style,lines],[y,0,1.2],[gnuplot_preamble, "set grid;"]);

(%t5)

(%o5)

(%i6) wxplot2d([discrete,sol2],[style,lines],[y,0,1.2],[gnuplot_preamble, "set grid;"]);

(%t6)

(%o6)

9 - 53 (c) Gilberto Urroz / Luigi Marino - 2009

Page 54: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 17 / 24

(%i7) wxplot2d([discrete,sol3],[style,lines],[y,0,1.2],[gnuplot_preamble, "set grid;"]);

(%t7)

(%o7)

(%i8) kill(all);(%o0) done

Example 11 - The Van Der Pol Equation

dx/dt = y-x*(x^2-1), dy/dt = -x+cos(t)

(%i1) sol:rk([y-x*(x^2-1),-x+cos(t)],[x,y],[0,0],[t,0,10,0.1])$

(%i2) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

(%i3) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

(%i4) sol3:makelist([second(sol[i]),third(sol[i])],i,1,length(sol))$

9 - 54 (c) Gilberto Urroz / Luigi Marino - 2009

Page 55: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 18 / 24

(%i5) wxplot2d([[discrete,sol1],[discrete,sol2]],[style,lines],[y,-2,2],[gnuplot_preamble, "set grid;"]);

(%t5)

(%o5)

(%i6) wxplot2d([discrete,sol3],[style,lines],[y,-3,3],[gnuplot_preamble, "set grid;"]);

(%t6)

(%o6)

Example 12 - Single ODE

dx/dt = sin(t*x)+sin(t+x)

(%i7) kill(all);(%o0) done

9 - 55 (c) Gilberto Urroz / Luigi Marino - 2009

Page 56: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 19 / 24

(%i1) sol:rk([sin(t*x)+sin(t+x)],x,0.5,[t,-1,1,0.1])$

(%i2) wxplot2d([discrete,sol],[style,lines],[y,0,1],[gnuplot_preamble, "set grid;"]);

(%t2)

(%o2)

(%i3) kill(all);(%o0) done

(%i1) sol:rk([y,-5*y-6*x],[x,y],[1,0],[t,0,5,0.1])$

(%i2) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

(%i3) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

(%i4) sol3:makelist([second(sol[i]),third(sol[i])],i,1,length(sol))$

9 - 56 (c) Gilberto Urroz / Luigi Marino - 2009

Page 57: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 20 / 24

(%i5) wxplot2d([[discrete,sol1],[discrete,sol2],[discrete,sol3]],[style,[points,1]],[y,-1,1],[gnuplot_preamble, "set grid;"]);

(%t5)

(%o5)

Example 13 - The Lokta-Volterra equation

dx/dt = x*(1-y), dy/dt = -y*(1-x)

(%i6) kill(all);(%o0) done

(%i1) sol:rk([x*(1-y),-y*(1-x)],[x,y],[2,2],[t,0,10,0.01])$

(%i2) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

(%i3) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

9 - 57 (c) Gilberto Urroz / Luigi Marino - 2009

Page 58: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 21 / 24

(%i4) wxplot2d([[discrete,sol1],[discrete,sol2]],[style,[points,1]],[y,0,3],[gnuplot_preamble, "set grid;"]);

(%t4)

(%o4)

(%i5) sol3:makelist([second(sol[i]),third(sol[i])],i,1,length(sol))$

(%i6) wxplot2d([discrete,sol3],[style,[points,1]],[y,0,3],[gnuplot_preamble, "set grid;"]);

(%t6)

(%o6)

Example 14 - An LCR electric circuit

LCR circuit-equation L=0.1 Henry; C=10^(-3) Farad ; R=10 ohm ;v=5 voltdx/dt = y, dy/dt = -(L+R*C^2)/(L*C*R)*y - 2/(L*C)*x+v/(L*C)Here x = electric current, y = electric charge (y = dx/dt)

9 - 58 (c) Gilberto Urroz / Luigi Marino - 2009

Page 59: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 22 / 24

(%i7) kill(all);(%o0) done

(%i1) L:0.1;C:10^(-3);R:10;v:5;(%o1) 0.1

(%o2) 1

1000

(%o3) 10(%o4) 5

(%i5) sol:rk([y,-(L+R*C^2)/(L*C*R)*y - 2/(L*C)*x+v/(L*C)],[x,y],[0,0],[t,0,0.1,0.001])$

(%i6) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

(%i7) wxplot2d([discrete,sol1],[style,[points,1]],[y,0,3.4],[gnuplot_preamble, "set grid;"]);

(%t7)

(%o7)

(%i8) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

9 - 59 (c) Gilberto Urroz / Luigi Marino - 2009

Page 60: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 23 / 24

(%i9) wxplot2d([discrete,sol2],[style,[lines,1,6]],[y,-100,250],[gnuplot_preamble, "set grid;"]);

(%t9)

(%o9)

(%i10) wxdraw2d( color=magenta,point_size=0,points_joined=true, points(sol2))$

(%t10)

9 - 60 (c) Gilberto Urroz / Luigi Marino - 2009

Page 61: Maxima Book Chapter 9

05Modified_usage_rk_numeric_ode.wxm 24 / 24

(%i11) wxdraw2d( color=green,point_size=0,points_joined=true, points(sol1))$

(%t11)

>>

9 - 61 (c) Gilberto Urroz / Luigi Marino - 2009

Page 62: Maxima Book Chapter 9

04Focault_pendulumNUmerical.wxm 1 / 3

Focault pendulum - 2nd-order system

Solve the following system of two 2nd-order ODEs:

x''=-2*omega*sin(psi)*y'+k2*xy''=+2*omega*cos(psi)*x'+k2*y

by converting it to the 1st-order ODE system:

x'=vy'=zz'=2*omega*sin(psi)-k2*xv'=-2*omega*sin(psi)*v-k2*y

init:x(0)=1,y(0)=0,z(0)=0,v(0)=0k2=9.8/20psi=pi/4omega=0.0000729

(%i15) kill(all);(%o0) done

(%i1) eq1:[v,z,2*omega*sin(psi)-k2*x,-2*omega*sin(psi)*v-k2*y];

(%o1) [ v , z , 2 omega sin psi( )- k2 x , - k2 y - 2 omega sin psi( )v ]

(%i2) omega:0.0000729;

(%o2) 7.2899999999999997 10-5

(%i3) k2:9.8/20;(%o3) 0.49

(%i4) psi:float(%pi/4);(%o4) 0.78539816339745

(%i5) t_range:[t,0,100,0.03];(%o5) [ t , 0 , 100 , 0.03 ]

(%i6) init1:[1,0,0,0];(%o6) [ 1 , 0 , 0 , 0 ]

(%i7) eq2:[v,z,2*0.0000729*sin( 0.78539816339745 )-0.49*x, -2*0.0000729*sin( 0.78539816339745 )*v-0.49*y ];

(%o7) [ v , z , 1.0309616869699881 10-4 - 0.49 x , - 0.49 y - 1.0309616869699881 10-4 v ]

(%i8) sol: rk(eq2, [x,y,v,z],[1,0,0,0],[t,0,100,0.03])$

(%i9) sol1:makelist([first(sol[i]),second(sol[i])],i,1,length(sol))$

9 - 62 (c) Gilberto Urroz / Luigi Marino - 2009

Page 63: Maxima Book Chapter 9

04Focault_pendulumNUmerical.wxm 2 / 3

(%i10) wxdraw2d( color=green,title="x vs t", point_size=0,points_joined=true, points(sol1))$

(%t10)

(%i11) sol2:makelist([first(sol[i]),third(sol[i])],i,1,length(sol))$

(%i12) sol3: makelist( rest(sol[i]),i,1,length(sol))$

(%i13) wxdraw2d( color=blue,title="y vs t",point_size=0,points_joined=true, points(sol2))$

(%t13)

9 - 63 (c) Gilberto Urroz / Luigi Marino - 2009

Page 64: Maxima Book Chapter 9

04Focault_pendulumNUmerical.wxm 3 / 3

(%i14) wxdraw2d( color=magenta,title="Phase Plane", point_size=0,points_joined=true, points(so

(%t14)

9 - 64 (c) Gilberto Urroz / Luigi Marino - 2009