campo-sirio/gfm/demo15.c

40 lines
881 B
C
Raw Normal View History

#include <stdio.h>
#include "gm.h"
void main(void);
void main()
{
DEC *xarr[100], *yarr[100], *p;
DECP lina, linb, corr, gx, gy, px, py;
int n, i;
printf("Number of elements: ");
scanf("%d", &n);
AllocateDecimalArray(xarr, n);
AllocateDecimalArray(yarr, n);
for (i=0; i<n; i++) {
printf("X Element #%d: ",i);
dscanf("%t", xarr[i]);
printf("Y Element #%d: ",i);
dscanf("%t", yarr[i]);
}
p = LinearEstimate(corr, lina, linb, xarr, yarr, n);
if (p) {
dprintf("\nY = %t + %t * X\n", lina, linb);
dprintf("Correleation coefficient: %t\n", corr);
}
else
dprintf("\nLinearEstimate failed\n");
printf("\nGiven X value: ");
dscanf("%t", gx);
if (PredictY(py, gx))
dprintf("X = %t corresponds to Y = %t\n", gx, py);
printf("\nGiven Y value: ");
dscanf("%t", gy);
if (PredictX(px, gy))
dprintf("Y = %t corresponds to X = %t\n", gy, px);
}