matlab中列主元三角分解法的函数,[数值算法]列主元三角分解法
[数值算法]列主元三角分解法
By EmilMatthew 05/9/13
列主元三角分角法是对直接三角分解法的一种改进,主要目的和列主元高斯消元法一样,就是避免小数作为分母项.
有一些麻烦是的是要对原矩阵的增广矩阵部分进行LU分解,而且每次要对当前未处不景行作求列主行的下标,然后做变换.
其它的注意点和LU分解法其本一致,而最后求出U矩阵后,可以直接用回代法求出解x,而不必先求y再用Ux=y来求解向量x了.
其实,这里根本没有必要用到数学上推导时用的L和U两个三角矩阵,只要用一个增广矩阵就可以解决战斗了,不过我实现时还是用了老方法,以后有待改进.
/*
LUColMainMethod, coded by EmilMathew 05/9/13, you can modify and use these code as you wish , but there is no guarantee that it can fit all you need.
*/
void LUColMainMethod(Type** matrixArr,Type* bList,Type* xAnsList,int len)
{
/*Core think of this algorithm:
matrix_L*yAnsList=bList;
matrix_U*xAnsList=yAnsList;
*/
Type** matrix_L,** matrix_U;/*The core two matrix object of the LU method.*/
Type* yAnsList;
int i,j,k;/*iterator num*/
int i2,j2;
Type sum;/*the temp tween data*/
/*LU
Col Main Spec Data*/
int maxRowIndex;
Type** matrixA_B;
/*input assertion*/
assertF(matrixArr!=NULL,"in LUPationMethod,matrixArr is NULL/n");
assertF(bList!=NULL,"in LUPationMethod,bList is NULL/n");
assertF(xAnsList!=NULL,"in LUPationMethod,xAnsList is NULL/n");
/*memory apply*/
matrix_L=(Type**)malloc(sizeof(Type*)*len);
twoDArrMemApply(&matrix_U,len,len+1);
for(i=0;i
{
matrix_L[i]=(Type*)malloc(sizeof(Type)*len);
//matrix_U[i]=(Type*)malloc(sizeof(Type)*len);
}
yAnsList=(Type*)malloc(sizeof(Type)*len);
/*==end of memory apply==*/
/*---assertion after apply the mem---*/
assertF(matrix_L!=NULL,"in LUPationMethod,matrix_L is NULL/n");
assertF(matrix_U!=NULL,"in LUPationMethod,matrix_U is NULL/n");
assertF(yAnsList!=NULL,"in LUPationMethod,yAnsList is NULL/n");
/*---end of assertion---*/
//printf("arr mem applyed/n");
/*----data initialization----*/
for(i=0;i
{
for(j=0;j
{
matrix_L[i][j]=0;
matrix_U[i][j]=0;
}
matrix_U[i][j]=0;
}
for(i=0;i
matrix_L[i][i]=1;
/*matrix A_B prepare*/
twoDArrMemApply(&matrixA_B,len,len+1);
matrixCopy(matrixArr,matrixA_B,len,len);
for(i=0;i
matrixA_B[i][len]=bList[i];
printf("show copied matrix:/n");
show2DArrFloat(matrixA_B,len,len+1);
for(i=0;i
{
maxRowIndex=getMaxRowIndexLU(matrixA_B,i,matrix_L,matrix_U,len);
if(i!=maxRowIndex)
{
swapTwoRow(matrixA_B,i,maxRowIndex,len+1);
swapTwoRow(matrix_L,i,maxRowIndex,len);
swapTwoRow(matrix_U,i,maxRowIndex,len);
}
/*matrixU make*/
for(j=i;j
{
sum=0;
for(k=0;k
sum+=matrix_L[i][k]*matrix_U[k][j];
matrix_U[i][j]=matrixA_B[i][j]-sum;
}
matrix_U[i][j]=matrixA_B[i][j]-sumArr1_IKByArr2_KJ(matrix_L,matrix_U,i,j,0,i-1);
matrixA_B[i][j]=matrix_U[i][j];
/*matrixL make*/
if(i
{
j2=i;
for(i2=j2+1;i2
{
sum=0;
for(k=0;k
sum+=matrix_L[i2][k]*matrix_U[k][j2];
matrix_L[i2][j2]=(matrixA_B[i2][j2]-sum)/matrix_U[j2][j2];
}
}
}
//copyBack
for(i=0;i
bList[i]=matrixA_B[i][len];
printf("show bList/n");
showArrListFloat(bList,0,len);
/*Adjusting of matrix_L*/
for(i=0;i
{
for(j=i;j
{
if(i==j)
matrix_L[i][i]=1;
else
matrix_L[i][j]=0;
}
}
printf("matrix L/n");
show2DArrFloat(matrix_L,len,len);
printf("matrix U/n");
show2DArrFloat(matrix_U,len,len);
for(i=len-1;i>=0;i--)
{
xAnsList[i]=(bList[i]-sumArr_JKByList_K(matrix_U,xAnsList,i,i+1,len-1))/matrix_U[i][i];
}
/*
downTriangleMethod(matrix_L,bList,yAnsList,len);
upTriangleMethod(matrix_U,yAnsList,xAnsList,len);
*/
/*memory free*/
for(i=0;i
{
free(matrix_L[i]);
free(matrix_U[i]);
}
free(matrix_L);
free(matrix_U);
free(yAnsList);
free(matrixA_B);
}
//辅助函数,求列主元的行位置.
int getMaxRowIndexLU(Type** inMatrixArr,int currentI,Type** matrix_L,Type** matrix_U,int size)
{
int i,maxRowIndex;
Type tmpSMax,tmpCompare;
assertF(inMatrixArr!=NULL,"in getMaxRowIndexLU,inMatrixArr is NULL/n");
assertF(matrix_L!=NULL,"in getMaxRowIndexLU,matrix_L is NULL/n");
assertF(matrix_U!=NULL,"in getMaxRowIndexLU,matrix_U is NULL/n");
tmpSMax=0;
//maxRowIndex=currentI;
for(i=currentI;i
{
tmpCompare=(float)fabs(inMatrixArr[i][currentI]-sumArr1_IKByArr2_KJ(matrix_L,matrix_U,i,currentI,0,currentI-1));
if(tmpCompare>tmpSMax)
{
tmpSMax=tmpCompare;
maxRowIndex=i;
}
}
return maxRowIndex;
}
我所写的程序的源码下载:
//如果上面这个链接无法响应下载(有可能是被网站给屏蔽掉了),则可使用下载工具(如迅雷等)下载
测试结果:
test1:
input:
3;
4,-2,-4,10;
-2,17,10,3;
-4,10,9,-7;
output:
after the LUPationMethod:the ans x rows is:(from x0 to xn-1)
2.000001.00000-1.00000
test2:
input:
3;
12,-3,3,15;
18,-3,1,15;
-1,2,1,6;
after the LUPationMethod:the ans x rows is:(from x0 to xn-1)
1.000002.000003.00000
matlab中列主元三角分解法的函数,[数值算法]列主元三角分解法相关推荐
- matlab中load seamout,matlab中的save与load函数
matlab中的save与load函数 用save函数,可以将工作空间的变量保存成txt文件或mat文件等. 比如: save peng.mat p j 就是将工作空间中的p和j变量保存在peng.m ...
- 邹检验 matlab,科学网—Matlab中一个很有用的函数:regionprops - 邹兴文的博文
Matlab中一个很有用的函数:regionprops 已有 6712 次阅读 2010-1-30 22:52 |个人分类:开发经验|系统分类:科研笔记| 有用的函数, regionprops Mat ...
- 函数调用matlab,Matlab中一个函数调用另外一个函数的操作方法
这篇文章为各位带来的内容是Matlab中一个函数调用另外一个函数相关的,对此感兴趣的用户可以去下文看看Matlab中一个函数调用另外一个函数的操作教程. Matlab中一个函数调用另外一个函数的操作方 ...
- matlab怎么调用主函数,Matlab中一个函数调用另外一个函数的操作步骤
原创Matlab中一个函数调用另外一个函数的操作步骤 编辑:小安 来源:PC下载网时间:2019-11-18 13:27:35 最近很多伙伴才刚刚安装入手Matlab这款软件,而本节就重点介绍了关于M ...
- Matlab中用于数据预测spline()函数的使用
Matlab中用于数据预测spline()函数的使用 再matlab中spline函数是利用三次方样条数据插值 语法 s = spline(x,y,xq) pp = spline(x,y) s = ...
- Matlab中产生正态分布随机数的函数normrnd-----用来产生高斯随机矩阵
Matlab中产生正态分布随机数的函数normrnd-----用来产生高斯随机矩阵 功能:生成服从正态分布的随机数 语法: R=normrnd(MU,SIGMA) R=normrnd(MU,SI ...
- Matlab中print, fprint, fscanf, disp函数的用法
最近一直在用python,导致学习的一些函数就有点混淆,趁着这会儿看代码,就再回顾下Matlab中print, fprint, fscanf, disp函数的用法 一.print() 函数可以把函数图 ...
- sin查找表 matlab,FPGA查找表法sin函数的实现
实验一Sin(x)函数的计算 一.实验要求 1.系统可以根据输入的角度(或弧度)x,显示相应的sin(x)数值,保证角度精度≤0.1度. 2.编辑测试激励文件,进行相关测试,注意测试的完备性. 3.根 ...
- MATLAB中的varargin,varargout在函数中运用
varargin,表示用在一个函数中,输入参数不确定的情况,这增强了程序的灵活性. 例如:function g=fun(f,varargin) ...
- matlab 中关于nargin 以及 varargin 函数的使用
最近自己在学matlab function过程当中对于 varargin函数的使用有了疑惑 于是结合自己所看的教学以及搜集到的资料对于这两个函数的理解 nargin: number of functi ...
最新文章
- 美亚排名超高的Docker入门书,不止简单易懂
- 清华大学研究称国内多城市饮用水含高浓度PFAS
- git 和 github 关系?
- wxWidgets:多文档界面实例
- 产品经理十八章:产品创新能力(二)
- xss漏洞的poc与exp
- 支持商用吗_可商用的插画素材 | 美翻了
- mysql导入dat文件_MySql导入和抽取大数量级文件数据
- 启动和停止mysql服务器_MySQL服务器的启动与关闭方法
- LeetCode之Z字形变换
- papers for mac 破解版永久激活方法
- 使用alter database create datafile恢复丢失数据文件
- 金融学习之四——插值法求远期国债收益率
- 前端程序员的焦虑感从何而来?web前端发展如何
- 设计模式七大原则之合成/聚合复用原则(CARP)
- 快手Android一面复盘
- 领导讲话稿小标题大全,笔杆子收藏备用
- MySQL 导入、备份
- 实施:GitHub + MarkDown 文档系统的工作环境部署及工作流程说明 | 技术传播
- android 开发过程中涉及到的清除缓存操作
热门文章
- w7忘记计算机密码,忘记电脑开机密码怎么办windows7_win7电脑忘记开机密码解决方法...
- 简单分析2022智能家居现状的优缺点
- 前端缓存方法实现—cookie/sessionStorage/localStorage
- word表格一行不对齐解决方法
- 无法打开包括文件:“afxcontrolbars.h”: 的解决方案
- 欧美顶尖大学是如何使用大数据的?
- 应付职称评定的论文-《七星彩神经网络预测系统》原型开发构想
- ADO访问Excel 2007
- PHPExcel浏览器输出Excel2007出错
- 0/1背包问题 - 如何理解 解空间