Subversion Repositories programming

Rev

Rev 145 | Rev 147 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 145 Rev 146
Line 16... Line 16...
16
 
16
 
17
float x5_const[7] = { 2.723987182E+01, 2.433564214E+01, 2.157974547,
17
float x5_const[7] = { 2.723987182E+01, 2.433564214E+01, 2.157974547,
18
                      4.580044419E-03, 1.047977675E-6 , 4.078415017E-10,
18
                      4.580044419E-03, 1.047977675E-6 , 4.078415017E-10,
19
                      5.024239358E-11 };
19
                      5.024239358E-11 };
20
 
20
 
21
/* Copied from the Project #2 Handout.
-
 
22
 *
-
 
23
 * FOR TESTING ONLY
-
 
24
 */
-
 
25
float Bessel_Recursive_BU (int n, float x, float base0, float base1)
-
 
26
{
-
 
27
    if (n == 0)
-
 
28
        return base0;
-
 
29
    else if (n == 1)
-
 
30
        return base1;
-
 
31
 
-
 
32
    return Bessel_Recursive_BU (n-2, x, base0, base1)
-
 
33
           + 2.0F * (float)(n-1) * Bessel_Recursive_BU (n-1, x, base0, base1) / x;
-
 
34
}
-
 
35
 
-
 
36
float Bessel_Recursive_TD (int n, float x, float base19, float base20)
-
 
37
{
-
 
38
    if (n == 19)
-
 
39
        return base19;
-
 
40
    else if (n == 20)
-
 
41
        return base20;
-
 
42
 
-
 
43
    return (2.0F * (float)(n+1) / x) * Bessel_Recursive_TD (n+1, x, base19, base20)
-
 
44
           + Bessel_Recursive_TD (n+2, x, base19, base20);
-
 
45
}
-
 
46
 
-
 
47
 
-
 
48
/* Find the Bessel Function.
21
/* Find the Bessel Function.
49
 * Algorithm: I[n+1](x) = I[n-1](x) - (2*n/x) * I[n](x)
22
 * Algorithm: I[n+1](x) = I[n-1](x) - (2*n/x) * I[n](x)
50
 * Which is equvalent to: I[n](x) = I[n-2](x) - (2 * (n-1)/x) * I[n-1](x)
23
 * Which is equvalent to: I[n](x) = I[n-2](x) - (2 * (n-1)/x) * I[n-1](x)
51
 * by simple substitution.
24
 * by simple substitution.
52
 *
25
 *
Line 161... Line 134...
161
             << setw(20) << calc_val
134
             << setw(20) << calc_val
162
             << setw(20) << abs_err
135
             << setw(20) << abs_err
163
             << setw(20) << rel_err
136
             << setw(20) << rel_err
164
             << endl;
137
             << endl;
165
    }
138
    }
-
 
139
 
-
 
140
    cout << endl;
166
}
141
}
167
 
142
 
168
int main (void)
143
int main (void)
169
{
144
{
170
    print_table (1.0, &Bessel_BottomUp);
145
    print_table (1.0, &Bessel_BottomUp);
171
    cout << endl;
-
 
172
    print_table (2.0, &Bessel_BottomUp);
146
    print_table (2.0, &Bessel_BottomUp);
173
    cout << endl;
-
 
174
    print_table (5.0, &Bessel_BottomUp);
147
    print_table (5.0, &Bessel_BottomUp);
175
    cout << endl;
148
    cout << endl << endl;
176
 
-
 
-
 
149
    print_table (1.0, &Bessel_TopDown);
-
 
150
    print_table (2.0, &Bessel_TopDown);
-
 
151
    print_table (5.0, &Bessel_TopDown);
177
 
152
 
178
    return 0;
153
    return 0;
179
}
154
}
180
 
155