-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmonomial_value_prb.c
143 lines (111 loc) · 2.53 KB
/
monomial_value_prb.c
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# include <stdlib.h>
# include <stdio.h>
# include <math.h>
# include <string.h>
# include <time.h>
# include "monomial_value.h"
int main ( );
void test01 ( );
/******************************************************************************/
int main ( )
/******************************************************************************/
/*
Purpose:
MAIN is the main program for MONOMIAL_VALUE_PRB.
Discussion:
MONOMIAL_VALUE_PRB tests the MONOMIAL_VALUE library.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
17 August 2014
Author:
John Burkardt
*/
{
timestamp ( );
printf ( "\n" );
printf ( "MONOMIAL_VALUE_PRB\n" );
printf ( " C version\n" );
printf ( " Test the MONOMIAL_VALUE library.\n" );
test01 ( );
/*
Terminate.
*/
printf ( "\n" );
printf ( "MONOMIAL_VALUE_PRB\n" );
printf ( " Normal end of execution.\n" );
printf ( "\n" );
timestamp ( );
return 0;
}
/******************************************************************************/
void test01 ( )
/******************************************************************************/
/*
Purpose:
TEST01 tests MONOMIAL_VALUE on sets of data in various dimensions.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
17 August 2014
Author:
John Burkardt
*/
{
int *e;
int e_max;
int e_min;
int i;
int j;
int m;
int n;
int seed;
double *v;
double *x;
double x_max;
double x_min;
printf ( "\n" );
printf ( "TEST01\n" );
printf ( " Usine monomial_value to evaluate monomials in\n" );
printf ( " dimensions 1 through 3.\n" );
e_min = -3;
e_max = 6;
n = 5;
seed = 123456789;
x_min = -2.0;
x_max = +10.0;
for ( m = 1; m <= 3; m++ )
{
printf ( "\n" );
printf ( " Spatial dimension M = %d\n", m );
e = i4vec_uniform_ab_new ( m, e_min, e_max, &seed );
i4vec_transpose_print ( m, e, " Exponents:" );
x = r8mat_uniform_ab_new ( m, n, x_min, x_max, &seed );
/*
To make checking easier, make the X values integers.
*/
r8mat_nint ( m, n, x );
v = monomial_value ( m, n, e, x );
printf ( "\n" );
printf ( " V(X) " );
for ( i = 0; i < m; i++ )
{
printf ( " X(%d)", i );
}
printf ( "\n" );
printf ( "\n" );
for ( j = 0; j < n; j++ )
{
printf ( "%14.6g ", v[j] );
for ( i = 0; i < m; i++ )
{
printf ( "%10.4f", x[i+j*m] );
}
printf ( "\n" );
}
free ( e );
free ( x );
free ( v );
}
return;
}