C Programs
C Programs
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int i, n;
float p, q, delta_p = 0, delta_q = 0, deno, a[10], b[10], c[10];
flushall();
clrscr();
printf("Enter degree of polynomial: ");
scanf ("%d", &n);
printf("\nEnter coefficients of polynomial:\n");
for (i=0; i<=n; i++)
{
printf("a(%d)= ",i);
scanf ("%f", &a[i]);
}
printf("\nEnter initial guess for coefficient p: ");
scanf ("%f", &p);
printf("\nEnter initial guess for coefficient q: ");
scanf ("%f", &q);
do
{
b[0] = a[0]; c[0] = a[0];
b[1] = a[1] - p*b[0];
c[1] = b[1] - p*c[0];
for (i=2; i<=n; i++)
{
b[i] = a[i] - p*b[i-1] - q*b[i-2];
c[i] = b[i] - p*c[i-1] - q*c[i-2];
}
deno = c[n-2]*c[n-2] - c[n-3]*(c[n-1] - b[n-1]);
delta_p = (b[n-1]*c[n-2] - b[n]*c[n-3])/deno;
delta_q = (b[n]*c[n-2] - b[n-1]*(c[n-1] - b[n-1]))/deno;
p += delta_p; q += delta_q;
} while (delta_p > 0.01 || delta_q > 0.01);
printf("\n\nThe complex factor of the given polynomial is \n\n\n\t\tx^2 + (%f)x + (%f)",
p, q);
getch();
}
Output of program (Bairstow Method):
Enter degree of polynomial: 5
y = 58.251339e^(0.199373x)