📄 3107002005_2nd_a_ldl.cpp
字号:
// 3107002005_second_A.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <fstream.h>
#include <math.h>
double a[20][20];
double r[20];
int LDL(int n=20)
{
int z;
double v;
for(int k=0;k<n;k++)
{
double u=0;
for(int p=0;p<=k-1;p++)
{
r[p]=a[p][p]*a[k][p];
u=u+a[k][p]*r[p];
}
a[k][k]=a[k][k]-u;
if (a[k][k]==0)
{
cout<<"Sth is wrong here!!!";
return 1111;
}
for(int q=k+1;q<n;q++)
{
v=0;
for(z=0;z<=k-1;z++)
{
v=v+a[q][z]*r[z];
}
a[q][k]=(a[q][k]-v)/a[k][k];
}
}
return 0;
}
int main()
{
for(int i=0;i<20;i++)
{
for(int j=0;j<20;j++)
{
a[i][j]=i+1;
if(j<i)
a[i][j]=j+1;
}
}
LDL(20);
cout<<"LDL分解结果中对焦矩阵D为diag{";
for(i=0;i<20;i++)
{
cout<<a[i][i]<<' ';
}
cout<<"}"<<endl;
cout<<endl<<"L为";
for(i=0;i<20;i++)
{
cout<<endl;
for(int j=0;j<20;j++)
{
if(j<=i)
cout<<a[i][j]<<' ';
else
cout<<"0"<<' ';
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -