-
Notifications
You must be signed in to change notification settings - Fork 0
/
r6op.cpp
121 lines (116 loc) · 3.63 KB
/
r6op.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
111
112
113
114
115
116
117
118
119
120
/*============================================================================
* Daniel J. Greenhoe
* operations on R^6 sequences
*============================================================================*/
/*=====================================
* headers
*=====================================*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<main.h>
#include<r1.h>
#include<r6.h>
#include<r6op.h>
/*=====================================
* operations
*=====================================*/
/*-------------------------------------------------------------------------
* compute the magnitude of sequence <x> over R^2
* yielding the sequence <y> over R^1
*-------------------------------------------------------------------------*/
void mag(seqR6 *x, seqR1 *y){
const long Nx=x->getN();
const long Ny=y->getN();
long n;
vectR6 xn; //nth element of sequence <*x>
double xnm; //magnitude of xn
y->clear();//not necessary but may help robustness and/or for debugging
if(Nx!=Ny){
fprintf(stderr,"ERROR using mag(seqR6 *x,seqR1 *y): lengths of *x (%ld) and *y (%ld) differ.\n",Nx,Ny);
exit(EXIT_FAILURE);
}
for(n=0;n<Nx;n++){
xn = x->get(n);
xnm = xn.mag();
y->put(n,xnm);
}
}
/*-------------------------------------------------------------------------
* z = x * y where * represents convolution
* Let <*x> be a length Nx sequence over R^6
* and <*y> be a length Ny sequence over R^1.
* Then <*z> is a length Nz=Nx+Ny-1 sequence over R^6
* m=n
* z[n] = x[n] * y[n] = SUM x[m]*y[n-m]
* m=0
*-------------------------------------------------------------------------*/
void convolve(seqR6 *x, seqR1 *y, seqR6 *z, int showcount){
const long Nx=x->getN();
const long Ny=y->getN();
const long Nz=z->getN();
long n,m,nm;
vectR6 u,sum;
double v;
if(Nz!=Nx+Ny-1){//check length of *z
fprintf(stderr,"\nERROR using using convolve(seqR6 *x, seqR1 *y, seqR6 *z): %ld = Nz != Nx+Ny-1 = %ld+%ld-1 = %ld\n",Nz,Nx,Ny,Nx+Ny-1);
exit(EXIT_FAILURE);
}
if(showcount)fprintf(stderr,"%10ld ",0);
for(n=0;n<Nz;n++){
if(showcount)fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b\b\b%10ld ",n);
sum=0;
for(m=0;m<=n;m++){
nm=n-m;
if(m>=Nx) u=0;
else u=x->get(m);
if(nm<0 || nm>=Ny)v=0;
else v=y->get(nm);
sum += u*v;
//printf("n=%3ld m=%3ld n-m=%3ld u=%7.3lf v=%7.3lf sum=%7.3lf\n",n,m,nm,u,v,sum);
}
z->put(n,sum);
}
}
/*-------------------------------------------------------------------------
* compute min of R^6 sequence
*-------------------------------------------------------------------------*/
int min(seqR6 *xR6, seqR1 *ymin){
long Nx=xR6->getN();
long Ny=ymin->getN();
long N=(Nx<Ny)?Nx:Ny;
long n;
int retval=0;
vectR6 u;
ymin->clear();
if(Nx!=Ny){
fprintf(stderr,"ERROR using y=min(xR6): lengths of xR6 (%ld) and ymax (%ld) differ.\n",Nx,Ny);
exit(EXIT_FAILURE);
}
for(n=0;n<N;n++){
u=xR6->get(n);
ymin->put(n,u.min());
}
return retval;
}
/*-------------------------------------------------------------------------
* compute min of R^6 sequence
*-------------------------------------------------------------------------*/
int max(seqR6 *xR6, seqR1 *ymax){
long Nx=xR6->getN();
long Ny=ymax->getN();
long N=(Nx<Ny)?Nx:Ny;
long n;
int retval=0;
vectR6 u;
ymax->clear();
if(Nx!=Ny){
fprintf(stderr,"ERROR using y=max(xR6): lengths of xR6 (%ld) and ymax (%ld) differ.\n",Nx,Ny);
exit(EXIT_FAILURE);
}
for(n=0;n<N;n++){
u=xR6->get(n);
ymax->put(n,u.max());
}
return retval;
}