eigenmath/dsolve.cpp

118 lines
1.2 KiB
C++
Raw Permalink Normal View History

2004-03-03 21:24:06 +01:00
#include "stdafx.h"
#include "defs.h"
2006-01-06 21:26:36 +01:00
// q(x)y' + p(x)*y = g(x)
2004-03-03 21:24:06 +01:00
//
// u(x) = exp(integral(p))
//
// y = (integral(u*g) + c) / u(x)
#define f p1
#define y p2
#define x p3
#define p p4
#define g p5
2006-01-06 21:26:36 +01:00
#define q p6
2004-03-03 21:24:06 +01:00
2006-01-06 21:26:36 +01:00
#define mu p7
2004-03-03 21:24:06 +01:00
void
dsolve(void)
{
int n;
save();
x = pop();
y = pop();
f = pop();
push(f);
push(y);
push(x);
n = distilly();
if (n != 3)
stop("error in dsolve");
2006-01-06 21:26:36 +01:00
q=pop();
2004-03-03 21:24:06 +01:00
p = pop();
negate();
g = pop();
2006-01-06 21:26:36 +01:00
/* print(g);
2004-06-09 04:45:50 +02:00
print(p);
2006-01-06 21:26:36 +01:00
print(p);
*/
2004-03-03 21:24:06 +01:00
push(p);
2006-01-06 21:26:36 +01:00
push(q);
divide();
2004-03-03 21:24:06 +01:00
push(x);
integral();
exponential();
mu = pop();
push(mu);
push(g);
2006-01-06 21:26:36 +01:00
push(q);
divide();
2004-03-03 21:24:06 +01:00
multiply();
push(x);
integral();
scan("C");
add();
push(mu);
divide();
restore();
}
// n p1 p2 p3 p4 p5 stack
// 1 4y'+3xy+2x+1 y x 1 2x+1 2x+1
// 2 4y'+3xy y' x y 3xy 3x
// 3 4y' y'' x y' 4y' 4
int distilly()
{
int n = 0;
save();
2004-06-25 22:45:15 +02:00
p4 = one;
2004-03-03 21:24:06 +01:00
p3 = pop();
p2 = pop();
p1 = pop();
while (1) {
n++;
push(p1);
push(p2);
2004-06-25 22:45:15 +02:00
push(zero);
2004-03-03 21:24:06 +01:00
subst();
eval();
p5 = pop();
push(p5);
push(p4);
divide();
push(p1);
push(p5);
subtract();
p1 = pop();
2004-06-25 22:45:15 +02:00
if (equal(p1, zero))
2004-03-03 21:24:06 +01:00
break;
p4 = p2;
push(p2);
push(p3);
derivative();
p2 = pop();
}
restore();
return n;
}