-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNWTP.c
More file actions
88 lines (64 loc) · 1.98 KB
/
NWTP.c
File metadata and controls
88 lines (64 loc) · 1.98 KB
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
//-----------------------------------------------------------------| NWTP Newton Polynom //
// | von Dietmar SCHRAUSSER 2011 //
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
void _profil();
void _head();
main(int argc, char *argv[])
{
FILE *in, *out;
int n_=0;
double x_, a_, b_, d_, p_=0, xn, xp;
char cx_[30];
if (argc != 4) { printf("\nArgument n .0\n"); _profil(); }
in = fopen( "nwti.txt", "r" ); if(in == 0) { printf("\nKoeffizientenvektor Datei (a) .0\n"); _profil(); }
fclose( in );
out = fopen( "nwtp.txt", "w"); // (F)=(x|p(x))
a_=atof(argv[1]);
b_=atof(argv[2]);
d_=atof(argv[3]);
_head();
for(x_=a_;x_<=b_;x_+=d_) //über (x) bei d
{
in = fopen( "nwti.txt", "r"); // (a)
p_=0;
fscanf(in,"%s\n",cx_); // a0
p_+=atof(cx_);
n_=1;
while (feof (in) == 0) // über n von (a)
{
xp=1;
for(xn=1;xn<=n_;xn++) xp*=(x_-xn); //(x-1)*...*(x-n)
fscanf(in,"%s\n",cx_); // ai
p_+=(atof(cx_)*xp);
n_++;
}
fclose( in );
printf("\np(x=%.3f)= %f",x_,p_); // bildschirmausgabe von p(x)
fprintf(out,"%f\t%f\n",x_,p_); // dateiausgabe von p(x)
}
fclose( out );
printf("\n"); // bildschirmausgabe von p(x)
return 0;
};
void _profil()
{
printf("------------------------------------------\n");
printf("Gebrauch: NWTP [a] [b] [d]\n");
printf("[a] ......... (x) Minimum\n");
printf("[b] ......... (x) Maximum\n");
printf("[d] ......... Intervall d\n");
printf("------------------------------------------\n");
printf("NWTP Newton Polynom von Dietmar Schrausser\n");
printf("compiliert: %s @ %s\n", __DATE__, __TIME__);
exit(0);
};
void _head()
{
printf("\nNWTP Newton Polynom von Dietmar Schrausser\n");
printf("compiliert: %s @ %s\n", __DATE__, __TIME__);
printf("berechne NWTP:\n");
};