User Tools

Site Tools


libnum:examples:gear

This is an old revision of the document!


Integration of Systems of Linear Differential Equations

Gear Method.
Let's examine the following SLDE:

y₁′ = y₂
y₂′ = y₁
y₁(0)=0  and  y₂(0)=1
# we expect sin(x)/cos(x) as the result
#include <stdio.h>
#include <math.h>
#include "libnum/gear.h"

using namespace NumericMethods;

{
 double initValues[] = { 0, 1, 0, 0};
 GearUserProc uf1(diffun1), uf2(j1);

 Gear solver;
 solver.set(2, &uf1, &uf2); // task dimention is 2
 GearAssistant& assistant = solver.assistant;
 assistant.params.setParameter("HINI", 0.0001);  // starting step of integration 
 assistant.params.setParameter("EPS", 0.001);    // step error constant 

 GearEngineCallbackEmbed printHandler(my_print);
 solver.setCallback(printHandler);

 try
 {
  Message rc=solver.solve(0, 5, initValues);     // integrate for t from 0 to 5
 }
 catch(Message e) {}
}
libnum/examples/gear.1772622402.txt.gz · Last modified: by abc