Hier ein paar Kommentare:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double pn[1],pn_strich[1];
double *c,*d;// c Dynamische Speicherplatz für den ersten durchlauf des Hornerschemas usw
// d Dyn. Speicherplatz für die Ableitung und Abdivision des Ploynoms
void Horner_W2(double *c,double *pn,double *pn_strich,double *x,int n); //Aufgabenteil b)
void Horner_Abdiv(double *c,double *d,double xnst,int n); //Aufgabenteil c)
int Newton_Poly_Nst(double *c,int n,double *x,double eps_x,double eps_f,int ITMAX); //Aufgabenteil d)
int main (void) {
int n,i,j,N,rueck,ITMAX;
double eps_x,eps_f;
double xnst = 0;//Angenomme Nullstelle ...Startwert
n = 8;// Variable für den Grad des Polynoms nimmt pro Schleifendurchlauf ab
c = (double*) malloc (n*sizeof(double));
d = (double*) malloc ((n-1)*sizeof(double));
c[0]=1.;
c[1]=-28.;
c[2]=322.;
c[3]=-1960.;
c[4]=6769.;
c[5]=-13133.;
c[6]=13068.;
c[7]=-5040.;
eps_x=10E-14;//Genauigkeit der Nullstelle
eps_f=10E-14;//Genauigkeit der Funktion
ITMAX=50;// Maximale Iterationsschritte
N = 8;
for(j=1;j<N;j++){
rueck = Newton_Poly_Nst(c,n,&xnst,eps_x,eps_f,ITMAX);//Rückgabewert des Newtonsverfahrens
if(rueck==1) {
printf("\n Nullstelle konnte mit %d Iterationen nicht berechnet werden",ITMAX);
getchar ();
return 0;
}
printf ("\n test");
Horner_Abdiv(c,d,xnst,n);
n--;
printf("\n Nullstelle: %f\n\n",xnst);
printf("Weiter mit Return\n\n");
rewind(stdin);
getchar();
for (i=0;i<n;i++) {
c
=d[i];
}
}
return 0;
}
void Horner_W2(double *c,double *pn,double *pn_strich,double *x,int n) {
int i;
*pn = c[0];
*pn_strich = *pn;
for (i=1;i<(n-1);i++) {
*pn =*pn*(*x)+c[i];
*pn_strich = *pn_strich*(*x)+*pn;
}
*pn = *pn*(*x)+c[n-1];
}
void Horner_Abdiv(double *c,double *d,double xnst,int n){
int i;
*d= c[0];
for (i=1;i<(n-1);i++) {
d[i] = c[i-1]*xnst+c[i];
}
return;
}
int Newton_Poly_Nst(double *c,int n,double *x,double eps_x,double eps_f,int ITMAX) {
int i=0;
double x_neu;
for (;
{
Horner_W2(c,pn,pn_strich,x,n);
if ((fabs(*pn))<=eps_f) break;
x_neu = *x-((*pn)/(*pn_strich));
if ((fabs(x_neu-(*x)))<=(eps_x*fabs(x_neu))) break;
if (i>ITMAX) return 1;
i = i+1;
*x = x_neu;
}
*x = x_neu;
return 0;
}