-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDiffEqEulerMethodThread.cpp
64 lines (51 loc) · 1.25 KB
/
DiffEqEulerMethodThread.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
#include "DiffEqEulerMethodThread.h"
DiffEqEulerMethodThread::DiffEqEulerMethodThread(QString func, double xStart, double xEnd, double y0, double h, ModeDiff mode)
{
this->setObjectName("DiffEqEulerMethodThread");
this->func = func;
this->xStart = xStart;
this->xEnd = xEnd;
this->y0 = y0;
this->h = h;
this->mode = mode;
}
void DiffEqEulerMethodThread::run()
{
BaseCalcThread::run();
n = (int)ceil(fabs(xStart - xEnd) / h) + 1;
if(n > 10000 + 1)
{
sendError(ErrorTooLongN);
return;
}
if(xEnd < xStart)
h = -h;
PointFArray result = (PointFArray)malloc(sizeof(TPointF) * n);
switch(mode)
{
case ModeDiffEuler:
DifferentialEuler(QStrToCStr(func), xStart, y0, n, h, result);
break;
case ModeDiffRunge:
DifferentialRungeKutt(QStrToCStr(func), xStart, y0, n, h, result);
break;
default:
return;
}
if(IsErrorCalc())
{
free(result);
sendError(GetResultCode());
return;
}
if(IsCancel())
{
free(result);
return;
}
sendResult(result);
}
void DiffEqEulerMethodThread::sendResult(PointFArray value)
{
emit sendResultSignal(value, n);
}