Program to find nth power of a matrix
#include < stdio.h>
#include < conio.h>
void mul();
int a[10][10],c[10][10],r;
main()
{
int i,j,n;
clrscr();
printf("Enter the order of the matrix:");
scanf("%d",&r);
printf("Enter the Matrix\n");
for(i=0;i < r;i++)
{
for(j=0;j < r;j++)
{
scanf("%d",&a[i][j]);
if(i==j)
c[i][j]=1;
else
c[i][j]=0;
}
}
printf("Enter the power : ");
scanf("%d",&n);
for(i=0;i < n;i++)
mul();
printf("\n\nAnswer\n");
for(i=0;i < r;i++)
{
for(j=0;j < r;j++)
printf(" %d",c[i][j]);
printf("\n");
}
getch();
}
void mul()
{
int b[10][10],i,j,k;
for(i=0;i < r;i++)
{
for(j=0;j < r;j++)
{
b[i][j]=0;
for(k=0;k < r;k++)
b[i][j]=b[i][j]+a[i][k]*c[k][j];
}}
for(i=0;i < r;i++)
{
for(j=0;j < r;j++)
c[i][j]=b[i][j];
}
}
4 comments:
thank you so much about the article..
.
it will for my project.
.
and I hope we can to be a friend, so that I can ask more to you about C++.
.
=D
can you implement it using matrix chain multiplication to reduce the no of operations?
and if possible with diagonalisation matrix by finding eigen values and eigen vectors.
Post a Comment