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:46] – 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₂ | ||
| Line 8: | Line 8: | ||
| < | < | ||
| - | #include <stdio.h> | + | #include <iostream> |
| + | #include < | ||
| + | #include < | ||
| #include < | #include < | ||
| #include " | #include " | ||
| + | #include " | ||
| using namespace NumericMethods; | using namespace NumericMethods; | ||
| - | bool derfun1(int n, double x, const double y[], double dy[]) | + | /* |
| + | y₁′ = y₂ | ||
| + | y₂′ = y₁ | ||
| + | y₁(0)=0 | ||
| + | // NB: we expect sin(x)/ | ||
| + | */ | ||
| + | |||
| + | static | ||
| { | { | ||
| dy[0] = y[1]; | dy[0] = y[1]; | ||
| Line 21: | Line 32: | ||
| } | } | ||
| - | bool jacobian1(int n, double x, const double y[], double j[]) | + | static |
| { | { | ||
| - | j[0] = 0; j[1] = 1; j[2] = -1; j[3] = 0; | + | |
| + | | ||
| return true; | return true; | ||
| } | } | ||
| - | bool my_print1(const GearEngineContext& | ||
| int main() | int main() | ||
| { | { | ||
| - | double initValues[] = { 0, 1, 0, 0}; | + | |
| - | | + | double initValues[]={ 0,1,0,0}; |
| + | | ||
| Gear solver; | Gear solver; | ||
| - | | + | |
| | | ||
| - | | + | |
| - | | + | |
| + | |||
| + | // | ||
| + | /*1*/ GearPrintToStream print_1(std:: | ||
| + | |||
| + | /*2*/ std:: | ||
| + | | ||
| + | |||
| + | /*3*/ std:: | ||
| + | | ||
| + | |||
| + | | ||
| + | print_4.setFormat(" | ||
| - | GearEngineCallbackEmbed printHandler(my_print); | + | |
| - | solver.setCallback(printHandler); | + | |
| try | try | ||
| { | { | ||
| - | Message rc=solver.solve(0, | + | Message rc=solver.solve(0, |
| - | printf(" | + | |
| - | assistant.statistics.steps, | + | |
| - | assistant.statistics.jacCalls); | + | |
| } | } | ||
| | | ||
| { | { | ||
| - | printf("\n\n%s",e.getMessageID().data()); | + | std::cout << |
| } | } | ||
| - | printf(" | + | std::cout << |
| } | } | ||
| + | </ | ||
| - | bool my_print1(const GearEngineContext& | + | ---- |
| - | { | + | [ [[..:classes: |
| - | | + | |
| - | // print y values and their derivatives | + | |
| - | int n = context.n; | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | </ | + | |
libnum/examples/gear.1772624763.txt.gz · Last modified: by abc
