libnum:examples:gear
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| libnum:examples:gear [2026/03/04 14:07] – abc | libnum:examples:gear [2026/03/29 13:46] (current) – abc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Integration of Systems of Linear Differential Equations ====== | + | ====== Integration of Systems of Linear Differential Equations. Gear's method |
| - | Gear Method.\\ | + | |
| Let's examine the following //SLDE//: | Let's examine the following //SLDE//: | ||
| y₁′ = y₂ | y₁′ = y₂ | ||
| y₂′ = y₁ | y₂′ = y₁ | ||
| y₁(0)=0 | y₁(0)=0 | ||
| - | We expect sin(x)/ | + | NB: we expect |
| < | < | ||
| - | #include <stdio.h> | + | #include <iostream> |
| + | #include < | ||
| + | #include < | ||
| #include < | #include < | ||
| #include " | #include " | ||
| + | #include " | ||
| using namespace NumericMethods; | using namespace NumericMethods; | ||
| + | /* | ||
| + | y₁′ = y₂ | ||
| + | y₂′ = y₁ | ||
| + | y₁(0)=0 | ||
| + | // NB: we expect sin(x)/ | ||
| + | */ | ||
| + | |||
| + | static bool derfun(int n, double x, const double y[], double dy[]) | ||
| { | { | ||
| - | | + | dy[0] = y[1]; |
| - | | + | dy[1] = -y[0]; |
| + | return true; | ||
| + | } | ||
| + | |||
| + | static bool jacobian(int n, double x, const double y[], double j[]) | ||
| + | { | ||
| + | //for (int i = 0; i<n*n; ++i) j[i] = 0; | ||
| + | j[0] = 0; j[1] = 1; j[2] = -1; j[3] = 0; // sin/cos | ||
| + | return true; | ||
| + | } | ||
| + | |||
| + | |||
| + | int main() | ||
| + | { | ||
| + | |||
| + | double initValues[]={ 0,1,0,0}; | ||
| + | | ||
| Gear solver; | Gear solver; | ||
| - | | + | |
| | | ||
| - | | + | |
| - | | + | |
| - | GearEngineCallbackEmbed printHandler(my_print); | + | // Output variants |
| - | | + | /*1*/ GearPrintToStream print_1(std::cout, " |
| + | |||
| + | /*2*/ std:: | ||
| + | | ||
| + | |||
| + | /*3*/ std:: | ||
| + | | ||
| + | |||
| + | | ||
| + | print_4.setFormat(" | ||
| + | |||
| + | | ||
| try | try | ||
| { | { | ||
| - | Message rc=solver.solve(0, | + | Message rc=solver.solve(0, |
| } | } | ||
| - | | + | |
| + | { | ||
| + | | ||
| + | } | ||
| + | | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ---- | ||
| + | [ [[..: | ||
libnum/examples/gear.1772622427.txt.gz · Last modified: by abc
