To do a Cholesky decomposition the given Matrix Should Be a Symmetric Positive-definite Matrix.
Here we have the origianl marix and its cholesky Matrix
A=LLT
LT= Transpose of L Matrix
***************************************************************************
#include<stdio.h>
#include<iostream>
#include<conio.h>
#include<malloc.h>
#include<math.h>
using namespace std;
void main()
{
double a[3][3]={{2,-1,0},{-1,2,-1},{0,-1,2}};
double L[3][3]={0};
double LT[3][3]={0};
int i=0,j=0,k=0;
double temp=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
temp=0;
if(i==j)
{
for(k=0;k<j;k++)
{
temp+=((L[j][k])*(L[j][k]));
}
L[i][j]=sqrt((double)(a[i][j]-temp));
}
if(i>j)
{
for(k=1;k<j;k++)
{
temp+=((L[i][k]*L[j][k]));
}
L[i][j]=(1/(L[j][j]))*((a[i][j])-temp);
}
if(i<j)
{
L[i][j]=0;
}
}
}
printf("Given Matrixis\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
//printf("%2d\t",a[i][j]);
cout<<a[i][j]<<"\t\t\t";
}
printf("\n");
}
// Cheloskey Transform
printf("\nGiven Matrix cheloskey Transform is\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<L[i][j]<<"\t\t\t";
//printf("%f\t",L[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
LT[i][j]=L[j][i];
}
}
printf("\n");
printf("Transpose of L MAtrix is");
printf("\n");
printf("\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<LT[i][j]<<"\t";
//printf("%2d\t",LT[i][j]);
}
printf("\n");
}
_getch();
}
original Matrix |
L Matix |
Here we have the origianl marix and its cholesky Matrix
A=LLT
LT= Transpose of L Matrix
***************************************************************************
#include<stdio.h>
#include<iostream>
#include<conio.h>
#include<malloc.h>
#include<math.h>
using namespace std;
void main()
{
double a[3][3]={{2,-1,0},{-1,2,-1},{0,-1,2}};
double L[3][3]={0};
double LT[3][3]={0};
int i=0,j=0,k=0;
double temp=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
temp=0;
if(i==j)
{
for(k=0;k<j;k++)
{
temp+=((L[j][k])*(L[j][k]));
}
L[i][j]=sqrt((double)(a[i][j]-temp));
}
if(i>j)
{
for(k=1;k<j;k++)
{
temp+=((L[i][k]*L[j][k]));
}
L[i][j]=(1/(L[j][j]))*((a[i][j])-temp);
}
if(i<j)
{
L[i][j]=0;
}
}
}
printf("Given Matrixis\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
//printf("%2d\t",a[i][j]);
cout<<a[i][j]<<"\t\t\t";
}
printf("\n");
}
// Cheloskey Transform
printf("\nGiven Matrix cheloskey Transform is\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<L[i][j]<<"\t\t\t";
//printf("%f\t",L[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
LT[i][j]=L[j][i];
}
}
printf("\n");
printf("Transpose of L MAtrix is");
printf("\n");
printf("\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<LT[i][j]<<"\t";
//printf("%2d\t",LT[i][j]);
}
printf("\n");
}
_getch();
}
****************************************************************
The Output will be
The Input Matrix Was
The Cheloskey Transform Upper Triangular Matrix is
Its Lower trainguler Matrix is
No comments:
Post a Comment