资源简介
C语言实现L U分解 追赶法 平方根法对线性方程组的求解 计算方法中算法的实现
代码片段和文件信息
#include
#include
#include
#include
#define recept 100
double LU1(double **xdouble *y);
double catch1(double **xdouble *y);
double Cholesky(double **xdouble *y);
int n;
int main()
{
clock_t startend;
printf(“请输入方程组的阶数:“);
scanf(“%d“&n);
double **x;
x = (double**)malloc(sizeof(double*)*n);
int ij;
for(i = 0;i x[i] = (double*)malloc(sizeof(double)*n);
for(i = 0;i for(j = 0;j {
printf(“请输入X%d%d:“ij);
scanf(“%lf“&x[i][j]);
}
double *y;
y = (double*)malloc(sizeof(double)*n);
for(i = 0;i {
printf(“请输Y%d:“i);
scanf(“%lf“&y[i]);
}
printf(“\n“);
start=clock();
for(i = 0;i<100;i++)
{
LU1(xy);
//catch1(xy);
//Cholesky(xy);
}
end = clock();
printf(“程序用时为%lf\n“(double)(end -start) / CLOCKS_PER_SEC/recept );
return 0;
}
double LU1(double **xdouble *y)
{
double **l**u;
int ijk;
l = (double**)malloc(sizeof(double*)*n);
for(i = 0;i l[i] = (double*)malloc(sizeof(double)*n);
u = (double**)malloc(sizeof(double*)*n);
for(i = 0;i u[i] = (double*)malloc(sizeof(double)*n);
for(i = 0;i for(j = 0;j {
l[i][j] = 0;
u[i][j] = 0;
}
double sum = 0;
for(i = 0;i
{
//此循环求u每行l每列
for(j = i;j {
for(k = 0;k sum = sum+l[i][k]*u[k][j];
u[i][j] = x[i][j] - sum;
sum = 0;
for(k = 0;k sum = sum + l[j][k]*u[k][i];
l[j][i] = (x[j][i] - sum)/u[i][i];
sum = 0;
}
}
/* for(i = 0;i {
for(j = 0;j printf(“%lf “l[i][j]);
printf(“\n\n“);
}
for(i = 0;i {
for(j = 0;j printf(“%lf “u[i][j]);
printf(“\n\n“);
}*/
sum = 0;
double *b*solve;
b = (double*)malloc(sizeof(double)*n);
solve = (double*)malloc(sizeof(double)*n);
for(i = 0;i {
for(k=0;k sum = sum+l[i][k]*b[k];
b[i] = y[i] - sum;
sum = 0;
}
for(i = 0;i printf(“b===%lf y====%lf\n“b[i]y[i]);
for(i = n-1;i>=0;i--)
{
for(k = i+1;k sum = sum+u[i][k]*solve[k];
solve[i] = (b[i] - sum)/u[i][i];
sum = 0;
}
printf(“UL分解法:“);
for(i = 0;i printf(“x%d = %.12lf \n“i+1solve[i]);
return 0;
}
- 上一篇:摄像机标定TSAI两步法
- 下一篇:动态规划算法求解字符串比较问题c++源代码
相关资源
- 操作系统模拟Shell课程设计报告
- Open Gl 实现台灯
- Linux环境下C语言Socket编程——客户端
- 读入stl文件的一段C++代码
- c++primerplus最全课后习题答案
- ue4蓝图c++动态改变staticmeshactor材质动
- matlab2013a/b vs2013支持
- MATLAB数字图像处理:从仿真到C C++代码
- ELGamal简单实现
- LOOK电梯调度算法
- 卡尔曼滤波算法航迹预测.rar
- 利用MATLAB进行功率因数校正PFC仿真
- C++Builder6.0破解版安装包
- RTSP_Client.c
- Qt5 串口助手源代码
- 页面置换算法OPT、FIFO、LRU实现--C++版
- 基于Qt的信息管理系统设计.zip
- MyImg2Lcd4.0破解版
- SCAN扫描程序中jtwain.dll文件源码
- linux C与C++混合编程通用makefile
- matlab的smooth()函数c++实现
- C++入门经典(第9版) ([美]Walter Sa
- DLT645-97/07报文解释器VC源码
- 操作系统 C++ 页面置换算法含实验报告
- TelBook.cpp通讯录课程设计
- websocket_server_client
- C语言socket/smtp发送邮件,支持附件,
- KLT算法c++实现
- libstdc++-libc6.2-2.so.3.tar.gz
- Basler工业相机SDK sample
评论
共有 条评论