www.bilisim-egitim.tr.gg |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Polinom kökü hesaplayan fonksiyon
#include <stdio.h> /* printf,scanf */
#include <stdlib.h> /* EXIT_SUCCESS,malloc,free */
#include <math.h> /* fabs */
#define TRUE 1
float newton_raphson(float x, const float a[], int n);
int main(void)
{
float *a;
int n, i;
float xi, xj, error;
printf("Polinomun derecesi: "); scanf("%d", &n);
a = (float *) malloc((n+1) * sizeof(float));
for (i = n; i >= 0; i--)
{
printf("a%d: ", i); scanf("%f", &a[i]);
}
printf("Hata: "); scanf("%f", &error);
printf("x0: "); scanf("%f", &xi);
while (TRUE)
{
xj = newton_raphson(xi, a, n);
if (fabs(xj - xi) < error)
break;
xi = xj;
}
printf("Kök: %fn", xj);
free(a);
return EXIT_SUCCESS;
}
float newton_raphson(float x, const float a[], int n)
{
float *b, *c;
float xn;
int i;
b = (float *) malloc((n+1) * sizeof(float));
c = (float *) malloc((n+1) * sizeof(float));
b[n] = a[n];
c[n] = b[n];
for (i = n - 1; i > 0; i--)
{
b[i] = b[i+1] * x + a[i];
c[i] = c[i+1] * x + b[i];
}
b[0] = b[1] * x + a[0];
xn = x - b[0] / c[1];
free(b);
free(c);
return 0;
/*www.bilisim-egitim.tr.gg*/
}
|
|
|
|
|
|
|
Bugün 173 ziyaretçi (262 klik)
www.bilisim-egitim.tr.gg
|
|
|
|
|
|
|
|