-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathnewt.c
45 lines (41 loc) · 871 Bytes
/
newt.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
#include <stdio.h>
#include "nrutil.h"
#define N2 1
int m, n;
float c2, dx, gmma;
int m, n;
float c2, dx, gmma;
int nvar;
float x1, x2;
int main(void) /*Program sphoot */
{
void newt(float x[], int n, int *check,
void(*vecfunc)(int, float[], float[]));
void shoot(int n, float v[], float f[]);
int check, i;
float q1, *v;
v = vector(1, N2);
dc = 1.0e-4;
nvar = 3;
for (;;){
printf("input m,n,c0squared\n");
if (scanf("%d %d %f", &m, &n, &c2) == EOF) break;
if (n < m || m < 0) continue;
gmma = 1.0;
q1 = n;
for (i = 1; i <= m; i++) gmma *= -0.5*(n + 1)*(q1-- / i);
v[1] = n*(n + 1) - m*(m + 1) + c2 / 2.0;
x1 = -1.0 + dx;
x2 = 0.0;
newt(v, N2, &check, shoot);
if (check) {
printf("shoot failed; bad initial guess \n");
}
else {
printf("\tmu(m,n)\n");
printf("%12.6f\n", v[1]) :
}
}
free_vector(v, 1, N2);
return 0;
}