-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoly.cpp
executable file
·50 lines (43 loc) · 973 Bytes
/
Poly.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
/////////////////////////////////////////////////////////////////////////
// Program : poly.cpp
// Coded by : Prof. Gang-Gyoo Jin, Korea Maritime University
// Coded on : 10/01/2004
#include "cmatrix.h"
// finds the polynomial from REAL roots
RVECTOR Poly(RVECTOR &p)
{
int i, j, n= p.num, np1= n+1;
RVECTOR a(np1);
CVECTOR c(np1), d(np1);
for(i=0; i<np1; i++)
c(i)= (i==0) ? 1:0;
for(j=0; j<n; j++)
{
for(i=1; i<=j+1; i++)
d(i)= c(i)-p(j)*c(i-1);
for(i=1; i<=j+1; i++)
c(i)= d(i);
}
for(i=0; i<np1; i++)
a(i)= c(i).Re;
return a;
}
// finds the polynomial from COMPLEX roots
RVECTOR Poly(CVECTOR &p)
{
int i, j, n= p.num, np1= n+1;
RVECTOR a(np1);
CVECTOR c(np1), d(np1);
for(i=0; i<np1; i++)
c(i)= (i==0) ? 1:0;
for(j=0; j<n; j++)
{
for(i=1; i<=j+1; i++)
d(i)= c(i)-p(j)*c(i-1);
for(i=1; i<=j+1; i++)
c(i)= d(i);
}
for(i=0; i<np1; i++)
a(i)= c(i).Re;
return a;
}