Write a C program to find the roots for the following polynomial using bisection
ID: 3779587 • Letter: W
Question
Write a C program to find the roots for the following polynomial using bisection method.
F(x) = Ax^3 + Bx^2 + Cx + D
Where A, B, C and D are coefficients/constant of the polynomial. The program should ask the user to enter the values for each and also the initial low and high values of estimated root value.
Use 10 decimal places for precision.
Expected exact input and output:
Finding-root for three degree polynomial Ax"3 + Bx"2 + CX + D using Bisection method Enter value for the following coefficients B:3 C :-1 D:-4 Initial brackets for root Low value :1 High value:2 1:New interval: [ 1.0000000000 1.5000000000 ] 2:New interval: [ 1.0000000000 1.2500000000 ] 3:New interval: [ 1.0000000000 1.1250000000 ] :New interval: [ 1.0625000000 1.1250000000 5:New interval: [ 1.0 937500000 1.1250000000 ] 6 :New interval: [ 1.1093750000 1.1250000000 ] 7:New interval: [ 1.1093750000 1.1171875000 ] 8:New interval: [ 1.1132812500 1.1171875000 ] 92New interval: [ 1.1132812500 1.1152343750 ] 10:New interval: [ 1.1142578125 1.1152343750 ] 11:New interval: [ 1.1147460938 1.1152343750 12:New interval: [ 1.1147460938 1.1149902344 ] 13:New interval: [ 1.1148 681641 1.1149902344 ] 14:New interval: [ 1.1148 68 16 41 1.1149291992 ] 15:New interval: [ 1.1148986816 1.1149291992 ] 16 :New interval: [ 1.1148 986816 1.1149139404 ] 17:New interval: [ 1.1149 063110 1.1149139404 ] 18:New interval: [ 1.1149063110 1.1149101257 ] 19:New interval: [ 1.1149 06 31 10 1.1149082184 ] 20:New interval: [ 1.1149 072647 1.1149082184 ] 21:New interval: [ 1.1149 072647 1.1149077415 ] 22:New interval: [ 1.1149075031 1.1149077415 ] 23:New interval: [ 1.1149075031 1.1149076223 ] 24:New interval: [ 1.1149075031 1.1149075627 ] 25:New interval: [ 1.1149075329 1.1149075627 ] 26:New interval: [ 1.1149 075329 1.1149075478 ] 27:New interval: [ 1.1149 075404 1.1149075478 ] 28:New interval: [ 1.1149 075404 1.1149075441 ] 29:New interval: [ 1.1149 075404 1.1149075422 ] 30:New interval: [ 1.1149 075413 1.1149075422 ] 31:New interval: [ 1.1149075413 1.1149075418 ] 32:New interval: [ 1.1149 075413 1.1149075415 ] 33:New interval: [ 1.1149 075414 1.1149075415 ] 34:New interval: [ 1.1149 075414 1.1149075415 Approximate solution 1.1149075415 0000000000044224474455377881228555 0000000055544990058811222774221111 0000000077733994421144266444444444 0000007744400993308877777777777777 3 3 9 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0000001122299999999999999999999999 ao 0 5 5 5 5 7 7 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 0522221111111111111111111111111111 5211111111111111111111111111111111 4 4 3 3 3 4 4 00000000023344111114433322000111 3 3 4 4 4 4 4 4 0000000228001166333225555555555555 0 0000055117668888666777777777777777 9 0005733222778888999999999999999999 1 00U 2 3 9 9 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 0006900111111111111111111111111111 0000011111111111111111111111111111 1 1111111111111111111111111111111111 t wwwww wwwww 14.1 V iwg -234567890-234567890-234567890-234 p 1111111111222222222233333 pExplanation / Answer
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,x1,x2,x3,disc;
int i;
float expr;
clrscr();
printf("ax^3 + bx^2 + cx + d = 0 Enter a,b,c,d : ");
scanf("%f,%f,%f,%f",&a,&b,&c,&d);
i = 0;
while(i<abs(d))
{
expr = a*pow(i,3)+b*pow(i,2)+c*i+d;
if(expr==0)
{
x1=i;
break;
}
expr = a*pow(-i,3)+b*pow(-i,2)+c*(-i)+d;
if(expr==0)
{
x1=-i;
break;
}
i++;
}
printf("Root 1 = %f",x1);
b = b + (a*(x1));
c = c + (b*(x1));
disc = (b*b)-(4*a*c);
if(disc>=0)
{
x2 = (-b+sqrt(disc))/(2*a);
x3 = (-b-sqrt(disc))/(2*a);
printf(" Root 2 = %f Root 3 = %f",x2,x3);
}
else
{
disc = ((4*a*c)-pow(b,2))/(2*a);
printf(" Root 2 : %f+%fi",((-b)/(2*a)),disc);
printf(" Root 3 : %f-%fi",((-b)/(2*a)),disc);
}
}
after exicution press alt+f5 for the show the output
thanks.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.