-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaplace.cpp
110 lines (88 loc) · 1.27 KB
/
laplace.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Laplace transform
#include "stdafx.h"
#include "defs.h"
void
eval_laplace(void)
{
push(cadr(p1));
eval();
push(symbol(SYMBOL_T));
laplace();
}
#define F p3
#define T p4
#define A p5
void
laplace(void)
{
int h;
save();
T = pop();
F = pop();
// L[f + g] = L[f] + L[g]
if (car(F) == symbol(ADD)) {
p1 = cdr(F);
h = tos;
while (iscons(p1)) {
push(car(p1));
push(T);
laplace();
p1 = cdr(p1);
}
add_all(tos - h);
restore();
return;
}
// L[Af] = A L[f]
if (car(F) == symbol(MULTIPLY)) {
push(F);
push(T);
partition();
F = pop();
A = pop();
laplace_main();
push(A);
multiply();
} else
laplace_main();
restore();
}
void
laplace_main(void)
{
int n;
// L[t] = 1 / s^2
if (F == symbol(SYMBOL_T)) {
push_symbol(SYMBOL_S);
push_integer(-2);
power();
return;
}
// L[t^n] = n! / s^(n+1)
if (car(F) == symbol(POWER) && cadr(F) == T) {
push(caddr(F));
n = pop_integer();
if (n > 0) {
push_integer(n);
factorial();
push_symbol(SYMBOL_S);
push_integer(n + 1);
power();
divide();
return;
}
}
stop("laplace: cannot solve");
}
#if SELFTEST
static const char *s[] = {
// float ok?
"laplace(3t^2.0)",
"6/(s^3)",
};
void
test_laplace(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}
#endif