Professional Documents
Culture Documents
I N
T U N OTE
K
E S . I N
NOT
}
KTU
for(j=1; j<=n; j++) /* loop for the generation of upper triangular matrix*/
{
for(i=1; i<=n; i++)
{
if(i>j)
{
c=A[i][j]/A[j][j];
for(k=1; k<=n+1; k++)
{
A[i][k]=A[i][k]-c*A[j][k];
}
}
}
}
x[n]=A[n][n+1]/A[n][n];
E S . I N
NOT
}
KTU
OUTPUT
Enter the order of matrix: 4
A[1][1] : 1
A[1][2] : 2
A[1][3] : 3
A[1][4] : 4
A[1][5] : 10
A[2][1] : 7
A[2][2] : 10
A[2][3] : 5
A[2][4] : 2
A[2][5] : 40
A[3][1] : 13
A[3][2] : 6
x1= 1
x2= 2
x3= 3
x4= -1
E S . I N
#include<iostream>
KTU
using namespace std;
NOT
int main()
{
int i,j,k,n;
float A[20][20],c,x[10];
cout<<"\nEnter the size of matrix: ";
cin>>n;
cout<<"\nEnter the elements of augmented matrix row-wise:\n";
for(i=1; i<=n; i++)
{
for(j=1; j<=(n+1); j++)
{
cout<<"A["<<i<<"]["<<j<<"] : ";
cin>>A[i][j];
}
}
E S . I N
NOT
for(i=1; i<=n; i++)
KTU
{
x[i]=A[i][n+1]/A[i][i];
}
return(0);
}
OUTPUT
Enter the size of matrix: 4
E S . I N
x1= 1
x2= 0
KTU NOT
x3= -1
x4= 2
#include<iostream>
using namespace std;
int main()
{
float x[100],y[100],a,s,t,sum=0;
int i,j,n;
cout<<"enter the number of terms available: ";
cin>>n;
cout<<"enter the values of x and corresponding y ";
for(i=0;i<n;i++)
}
cout<<"enter the value of x whose y value is to be computed: ";
cin>>a;
for(i=0;i<n;i++)
{
s=1;
t=1;
for(j=0;j<n;j++)
{
if(i!=j)
{
E S . I N
NOT
s=s*(a-x[j]);
KTU
t=t*(x[i]-x[j]);
}
sum=sum+((s/t)*y[i]);
}
cout<<"value of y is"<<sum;
return 0;
}
Output
enter the number of terms available: 5
enter the values of x and corresponding y
x0:1
y0: 1
x1:2
x2:3
y2: 1.7321
x3:4
y3: 2
x4:5
y4: 2.2361
enter the value of x whose y value is to be computed: 2.5
value of y is1.58164
E S . I N
KTU NOT