You are on page 1of 5

MATHS ASSIGNMENT 2

KARISHMA BABBAR 2013136


#include<stdio.h>

#include<stdlib.h>

void main()

int n;

float x2=0, x3=0, x4=0, x5=0, x6=0;x7=0;

float x,y;

float f=0,g=0,h=0,k=0;

float a,b,c,d;

float det;

float P[4][4],P1[4][4];

int i,j;

printf("\nEnter the no. of values to be considered: ");

scanf("%d",&n);

for(i=0;i<n;i++)

printf("\nEnter value of x: ");

scanf("%f",&x);

printf("\nEnter value of y: ");

scanf("%f",&y);

x2=x2+x;

x3=x3+pow(x,2);

x4=x4+pow(x,3);

x5=x5+pow(x,4);

x6=x6+pow(x,5);

x7=x7+pow(x,6);
f=f+y;

g=g+y*pow(x,1);

h=h+y*pow(x,2);

k=k+y*pow(x,3);

P[0][0]=n;

P[0][1]=x2;

P[0][2]=x3;

P[0][3]=x4;

P[1][0]=x2;

P[1][1]=x3;

P[1][2]=x4;

P[1][3]=x5;

P[2][0]=x3;

P[2][1]=x4;

P[2][2]=x5;

P[2][3]=x6;

P[3][0]=x4;

P[3][1]=x5;

P[3][2]=x6;

P[3][3]=x7;

printf("The matrix is: \n")

for(i=0;i<4;i++)

for(j=0;j<4;j++)

printf("P[%d][%d]=%f\t",i,j);

break;

}
det = (- x7*x2*x2*x5 + x2*x2*x6*x6 + 2*x7*x2*x3*x4 - 2*x2*x3*x5*x6 - 2*x2*x4*x4*x6 +
2*x2*x4*x5*x5 - x7*x3*x3*x3 + 2*x3*x3*x4*x6 + x3*x3*x5*x5 - 3*x3*x4*x4*x5 + x1*x7*x3*x5 -
x1*x3*x6*x6 + x4*x4*x4*x4 - x1*x7*x4*x4 + 2*x1*x4*x5*x6 - x1*x5*x5*x5);

printf("\nThe determinant of the matrix is &f",det);

P1[0][0] = P[1][1]*P[2][2]*P[3][3] + P[1][2]*P[2][3]*P[3][1] + P[1][3]*P[2][1]*P[3][2] -


P[1][1]*P[2][3]*P[3][2] - P[1][2]*P[2][1]*P[3][3] - P[1][3]*P[2][2]*P[3][1];

P1[0][1] = P[0][1]*P[2][3]*P[3][2] + P[0][2]*P[2][1]*P[3][3] + P[0][3]*P[2][2]*P[3][1] -


P[0][1]*P[2][2]*P[3][3] - P[0][2]*P[2][3]*P[3][1] - P[0][3]*P[2][1]*P[3][2];

P1[0][2] = P[0][1]*P[1][2]*P[3][3] + P[0][2]*P[1][3]*P[3][1] + P[0][3]*P[1][1]*P[3][2] -


P[0][1]*P[1][3]*P[3][2] - P[0][2]*P[1][1]*P[3][3] - P[0][3]*P[1][2]*P[3][1];

P1[0][3] = P[0][1]*P[1][3]*P[2][2] + P[0][2]*P[1][1]*P[2][3] + P[0][3]*P[1][2]*P[2][1] -


P[0][1]*P[1][2]*P[2][3] - P[0][2]*P[1][3]*P[2][1] - P[0][3]*P[1][1]*P[2][2];

P1[1][0] = P[1][0]*P[2][3]*P[3][2] + P[1][2]*P[2][0]*P[3][3] + P[1][3]*P[2][2]*P[3][0] -


P[1][0]*P[2][2]*P[3][3] - P[1][2]*P[2][3]*P[3][0] - P[1][3]*P[2][0]*P[3][2];

P1[1][1] = P[0][0]*P[2][2]*P[3][3] + P[0][2]*P[2][3]*P[3][0] + P[0][3]*P[2][0]*P[3][2] -


P[0][0]*P[2][3]*P[3][2] - P[0][2]*P[2][0]*P[3][3] - P[0][3]*P[2][2]*P[3][0];

P1[1][2] = P[0][0]*P[1][3]*P[3][2] + P[0][2]*P[1][0]*P[3][3] + P[0][3]*P[1][2]*P[3][0] -


P[0][0]*P[1][2]*P[3][3] - P[0][2]*P[1][3]*P[3][0] - P[0][3]*P[1][0]*P[3][2];

P1[1][3] = P[0][0]*P[1][2]*P[2][3] + P[0][2]*P[1][3]*P[2][0] + P[0][3]*P[1][0]*P[2][2] -


P[0][0]*P[1][3]*P[2][2] - P[0][2]*P[1][0]*P[2][3] - P[0][3]*P[1][2]*P[2][0];

P1[2][0] = P[1][0]*P[2][1]*P[3][3] + P[1][1]*P[2][3]*P[3][0] + P[1][3]*P[2][0]*P[3][1] -


P[1][0]*P[2][3]*P[3][1] - P[1][1]*P[2][0]*P[3][3] - P[1][3]*P[2][1]*P[3][0];

P1[2][1] = P[0][0]*P[2][3]*P[3][1] + P[0][1]*P[2][0]*P[3][3] + P[0][3]*P[2][1]*P[3][0] -


P[0][0]*P[2][1]*P[3][3] - P[0][1]*P[2][3]*P[3][0] - P[0][3]*P[2][0]*P[3][1];
P1[2][2] = P[0][0]*P[1][1]*P[3][3] + P[0][1]*P[1][3]*P[3][0] + P[0][3]*P[1][0]*P[3][1] -
P[0][0]*P[1][3]*P[3][1] - P[0][1]*P[1][0]*P[3][3] - P[0][3]*P[1][1]*P[3][0];

P1[2][3] = P[0][0]*P[1][3]*P[2][1] + P[0][1]*P[1][0]*P[2][3] + P[0][3]*P[1][1]*P[2][0] -


P[0][0]*P[1][1]*P[2][3] - P[0][1]*P[1][3]*P[2][0] - P[0][3]*P[1][0]*P[2][1];

P1[3][0] = P[1][0]*P[2][2]*P[3][1] + P[1][1]*P[2][0]*P[3][2] + P[1][2]*P[2][1]*P[3][0] -


P[1][0]*P[2][1]*P[3][2] - P[1][1]*P[2][2]*P[3][0] - P[1][2]*P[2][0]*P[3][1];

P1[3][1] = P[0][0]*P[2][1]*P[3][2] + P[0][1]*P[2][2]*P[3][0] + P[0][2]*P[2][0]*P[3][1] -


P[0][0]*P[2][2]*P[3][1] - P[0][1]*P[2][0]*P[3][2] - P[0][2]*P[2][1]*P[3][0];

P1[3][2] = P[0][0]*P[1][2]*P[3][1] + P[0][1]*P[1][0]*P[3][2] + P[0][2]*P[1][1]*P[3][0] -


P[0][0]*P[1][1]*P[3][2] - P[0][1]*P[1][2]*P[3][0] - P[0][2]*P[1][0]*P[3][1];

P1[3][3] = P[0][0]*P[1][1]*P[2][2] + P[0][1]*P[1][2]*P[2][0] + P[0][2]*P[1][0]*P[2][1] -


P[0][0]*P[1][2]*P[2][1] - P[0][1]*P[1][0]*P[2][2] - P[0][2]*P[1][1]*P[2][0];

//P(t)Ax=P(t)Q

Q[0]=f;

Q[1]=g;

Q[2]=h;

Q[3]=k;

a = (k*(x6*x3*x3 - 2*x3*x4*x5 + x4*x4*x4 - x2*x6*x4 + x2*x5*x5))/(det) - (f*(x7*x4*x4 -


2*x4*x5*x6 + x5*x5*x5 - x3*x7*x5 + x3*x6*x6))/(det) + (h*(- x7*x3*x3 + x6*x3*x4 + x3*x5*x5 -
x4*x4*x5 + x2*x7*x4 - x2*x6*x5))/(det) + (g*(- x4*x4*x6 + x4*x5*x5 + x3*x7*x4 - x3*x5*x6 -
x2*x7*x5 + x2*x6*x6))/(det);

b = (f*(- x4*x4*x6 + x4*x5*x5 + x3*x7*x4 - x3*x5*x6 - x2*x7*x5 + x2*x6*x6))/(det)-(k*(-


x3*x3*x5 + x3*x4*x4 + x2*x6*x3 - x2*x4*x5 - x1*x6*x4 + x1*x5*x5))/(det)-(g*(x7*x3*x3 -
2*x3*x4*x6 + x5*x4*x4 + x1*x6*x6 - x1*x5*x7))/(det) +(h*(x4*x4*x4 - x1*x4*x7 + x1*x5*x6 +
x2*x3*x7 - x2*x4*x6 - x3*x4*x5))/(det);
c = ((f*(- x7*x3*x3 + x6*x3*x4 + x3*x5*x5 - x4*x4*x5 + x2*x7*x4 - x2*x6*x5))/(det))-((k*(-
x6*x2*x2 + x5*x2*x3 + x2*x4*x4 - x3*x3*x4 + x1*x6*x3 - x1*x5*x4))/(det ))-(h*(x7*x2*x2 -
2*x2*x4*x5 + x3*x4*x4 + x1*x5*x5 - x1*x3*x7))/(det)+(g*(x4*x4*x4 - x1*x4*x7 + x1*x5*x6 +
x2*x3*x7 - x2*x4*x6 - x3*x4*x5))/(det);

d = (f*(x6*x3*x3 - 2*x3*x4*x5 + x4*x4*x4 - x2*x6*x4 + x2*x5*x5))/(det) - (k*(x5*x2*x2 -


2*x2*x3*x4 + x3*x3*x3 - x1*x5*x3 + x1*x4*x4))/(det) - (h*(- x6*x2*x2 + x5*x2*x3 + x2*x4*x4 -
x3*x3*x4 + x1*x6*x3 - x1*x5*x4))/(det)-(g*(- x3*x3*x5 + x3*x4*x4 + x2*x6*x3 - x2*x4*x5 - x1*x6*x4
+ x1*x5*x5))/(det);

printf("a=%f\n",a);

printf("b=%f\n",b);

printf("c=%f\n",c);

printf("d=%f\n",d);

printf("polynomial is %f+%fx+%fx^2+%fx^3",a,b,c,d);

You might also like