function [L,U,pv,qv] = lugui(A,pivotstrat)
%LUGUI Gaussian elimination demonstration.
%
% LUGUI(A) shows the steps in LU decomposition by Gaussian elimination.
% At each step of the elimination, the pivot that would be chosen by
% MATLAB's partial pivoting algorithm is shown in magenta. You can use
% the mouse to pick any pivot. The pivot is shown in red, the emerging
% columns of L in green, and the emerging rows of U in blue.
%
% LUGUI with no arguments uses a random integer test matrix.
% Type 'help golub' for a description of the test matrices.
%
% A popup menu allows the pivot strategy to be changed dynamically.
% lugui(A,'pick'), choose pivots with the mouse.
% lugui(A,'diagonal'), use diagonal elements as pivots.
% lugui(A,'partial'), use the largest element in the current column.
% lugui(A,'complete'), use the largest element in the unreduced matrix.
%
% [L,U,p,q] = lugui(A,...) returns a lower triangular L, an upper
% triangular U and permutation vectors p and q so that L*U = A(p,q).
%
% See also PIVOTGOLF. % Initialize if nargin < 2
pivotstrat = 'pick';
end
if nargin < 1
n = 2 + ceil(6*rand);
A = golub(n);
end
Asave = A; [m,n] = size(A);
shg
clf
dx = 100;
dy = 30;
warns = warning('off','MATLAB:divideByZero');
set(gcf,'double','on','name','LU Gui', ...
'menu','none','numbertitle','off','color','white', ...
'pos',[480-(dx/2)*min(9,n) 320 (n+1)*dx (m+3)*dy], ...
'windowbuttonupfcn','set(gcf,''tag'',''pivot'')')
stop = uicontrol('style','toggle','string','X','fontweight','bold', ...
'back','w','pos',[(n+1)*dx-25 (m+3)*dy-25 25 25]);
axes('pos',[0 0 1 1])
axis off
Lcolor = [0 .65 0];
Ucolor = [0 0 .90];
Acolor = [0 0 0];
PartialPivotColor = [1 0 1];
PivotColor = [1 0 0];
TempColor = [1 1 1];
paws = 0.1; % Each element has its own handle for j = 1:n
for i = 1:m
t(i,j) = text('units','pixels','string',spf(A(i,j)), ...
'fontname','courier','fontweight','bold','fontsize',14, ...
'horiz','right','color',Acolor, ...
'pos',[20+j*dx 20+(m+2-i)*dy],'userdata',[i j], ...
'buttondownfcn','set(gcf,''userdata'',get(gco,''userdata''))');
end
end % Menus switch lower(pivotstrat)
case 'pick', val = 1;
case 'diagonal', val = 2;
case 'partial', val = 3;
case 'complete', val = 4;
otherwise, val = 1;
end
pivotstrat = uicontrol('pos',[60+(dx/2)*(n-2) 20 180 20],'style','pop', ...
'val',val,'fontsize',12,'back','white','string',{'Pick a pivot', ...
'Diagonal pivoting','Partial pivoting','Complete pivoting'}); % Elimination pv = 1:m;
qv = 1:n;
for k = 1:min(m,n) % If possible, quit early if all(all(A(k:m,k:n)==0)) | all(all(~isfinite(A(k:m,k:n))))
for l = k:min(m,n)
for i = l+1:m
set(t(i,l),'string',spf(A(i,l)),'color',Lcolor)
drawnow
end
for j = l:n
set(t(l,j),'string',spf(A(l,j)),'color',Ucolor)
drawnow
end
end
break
end if (m == n) & (k == n)
p = n;
q = n;
else
pp = min(find(abs(A(k:m,k)) == max(abs(A(k:m,k)))))+k-1;
set(t(pp,k),'color',PartialPivotColor)
p = 0;
q = 0;
while p < k | q < k | p > m | q > n
switch get(pivotstrat,'val') case 1 % Pick a pivot with mouse
pq = get(gcf,'userdata');
if isequal(get(gcf,'tag'),'pivot') & ~isempty(pq)
p = pq(1);
q = pq(2);
set(gcf,'tag','','userdata',[])
else
drawnow
end case 2 % Diagonal pivoting
p = k;
q = k; case 3 % Partial pivoting
p = pp;
q = k; case 4 % Complete pivoting
[p,q] = find(abs(A(k:m,k:n)) == max(max(abs(A(k:m,k:n)))));
p = p(1)+k-1;
q = q(1)+k-1;
end
if get(stop,'value') == 1, break, end
end
if get(stop,'value') == 1, break, end
set(t(pp,k),'color',Acolor)
set(t(p,q),'color',PivotColor)
end
if get(stop,'value') == 1, break, end
pause(10*paws) % Swap columns A(:,[q,k]) = A(:,[k,q]);
qv([q,k]) = qv([k,q]);
for s = .05:.05:1
for i = 1:m
set(t(i,k),'pos',[20+(k+s*(q-k))*dx 20+(m+2-i)*dy])
set(t(i,q),'pos',[20+(q+s*(k-q))*dx 20+(m+2-i)*dy])
end
drawnow
end
t(:,[q,k]) = t(:,[k,q]);
for i = 1:m
set(t(i,k),'string',spf(A(i,k)),'userdata',[i k])
set(t(i,q),'string',spf(A(i,q)),'userdata',[i q])
end
pause(10*paws) % Swap rows A([p,k],:) = A([k,p],:);
pv([p,k]) = pv([k,p]);
for s = .05:.05:1
for j = 1:n
set(t(k,j),'pos',[20+j*dx 20+(m+2-(k+s*(p-k)))*dy])
set(t(p,j),'pos',[20+j*dx 20+(m+2-(p+s*(k-p)))*dy])
end
drawnow
end
t([p,k],:) = t([k,p],:);
pause(10*paws) for j = k:n
set(t(k,j),'string',spf(A(k,j)),'userdata',[k j])
set(t(p,j),'string',spf(A(p,j)),'userdata',[p j])
end
pause(10*paws) % Skip step if column is all zero if all(A(k:m,k) == 0)
for i = k+1:m
set(t(i,k),'string',spf(A(i,k)),'color',Lcolor)
drawnow
end
for j = k:n
set(t(k,j),'string',spf(A(k,j)),'color',Ucolor)
drawnow
end
else % Compute multipliers in L for i = k+1:m
A(i,k) = A(i,k)/A(k,k);
set(t(i,k),'string',spf(A(i,k)),'color',Lcolor)
pause(paws)
drawnow
end % Elimination for j = k+1:n
for i = k+1:m
set(t(i,j),'color',TempColor)
drawnow
pause(paws)
A(i,j) = A(i,j) - A(i,k)*A(k,j);
set(t(i,j),'string',spf(A(i,j)),'color',Acolor)
drawnow
pause(paws)
end
end for j = k:n
set(t(k,j),'string',spf(A(k,j)),'color',Ucolor)
drawnow
end
pause(paws)
end
if k < min(m,n), pause(10*paws), end
end % Seperate L and U into two matrices delete(pivotstrat) for s = .1:.1:1.5
for j = 1:n
for i = 1:m
if i <= j
set(t(i,j),'pos',[20+(j+.10*s)*dx 20+(m+2-i)*dy])
else
set(t(i,j),'pos',[20+(j-.10*s)*dx 20+(m+2-s-i)*dy])
end
end
end
drawnow
end % Insert ones on diagonal of L r = min(m,n);
for j = 1:r
text('units','pixels','string',spf(1.0), ...
'fontname','courier','fontweight','bold','fontsize',14, ...
'horiz','right','color',Lcolor, ...
'pos',[20+(j-0.15)*dx 20+(m+.5-j)*dy]);
end
drawnow
warning(warns) if nargout > 0
L = tril(A(:,1:r),-1) + eye(m,r);
U = triu(A(1:r,:));
else
set(gcf,'userdata',Asave)
set(stop,'value',0,'callback','close(gcf)')
uicontrol('pos',[(n+1)*dx-70 10 60 20],'string','repeat', ...
'back','w','fontsize',12,'callback','lugui(get(gcf,''userdata''))')
end %------------------------------------------------------------ function s = spf(aij)
% Subfunction to format text strings
if aij == 0
f = '%10.0f';
elseif (abs(aij) < 1.e-4) | (abs(aij) >= 1.e4)
f = '%10.1e';
else
f = '%10.4f';
end
s = sprintf(f,aij);

Matlab lugui的更多相关文章

  1. Matlab 绘制三维立体图(以地质异常体为例)

    前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...

  2. Matlab slice方法和包络法绘制三维立体图

    前言:在地球物理勘探,流体空间分布等多种场景中,定位空间点P(x,y,x)的物理属性值Q,并绘制三维空间分布图,对我们洞察空间场景有十分重要的意义. 1. 三维立体图的基本要件: 全空间网格化 网格节 ...

  3. Matlab 高斯_拉普拉斯滤波器处理医学图像

    前言:本程序是我去年实现论文算法时所做.主要功能为标记切割肝脏区域.时间有点久,很多细节已经模糊加上代码做了很多注释,因此在博客中不再详述. NOTE: 程序分几大段功能模块,仔细阅读,对解决医学图像 ...

  4. MATLAB中绘制质点轨迹动图并保存成GIF

    工作需要在MATLAB中绘制质点轨迹并保存成GIF以便展示. 绘制质点轨迹动图可用comet和comet3命令,使用例子如下: t = 0:.01:2*pi;x = cos(2*t).*(cos(t) ...

  5. linux下配置matlab运行环境(MCR)

    在安装好的matlab下有MCR(MatlabCompilerRuntime)在matlab2011/toolbox/compiler/deploy/glnxa64下找到MCRInstaller.zi ...

  6. EMD分析 Matlab 精华总结 附开源工具箱(全)

    前言: 本贴写于2016年12与15日,UK.最近在学习EMD(Empirical Mode Decomposition)和HHT(Hilbert-Huang Transform)多分辨信号处理,FQ ...

  7. Atitit MATLAB 图像处理 经典书籍attilax总结

    Atitit MATLAB 图像处理 经典书籍attilax总结 1.1. MATLAB数字图像处理1 1.2. <MATLAB实用教程(第二版)>((美)穆尔 著)[简介_书评_在线阅读 ...

  8. Atitit MATLAB 图像处理attilax总结

    Atitit MATLAB 图像处理attilax总结 1.1. 下载 Matlab7.0官方下载_Matlab2012 v7.0 官方简体中文版-办公软件-系统大全.html1 1.2. Matla ...

  9. Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结

    Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...

随机推荐

  1. go 学习笔记 - sublime text 环境配置

    园里已经有了一篇相当不错的配置说明文章,只是现在gosublime不再支持2.x.文章里的操作在sublimetext3 里一样可以使用 文章地址 : http://www.cnblogs.com/s ...

  2. ActionForward

    一.只有登录才能显示的页面 这是一个很平常的问题,在访问某些网页的时候,只有登录才可以访问,以此保证安全. 实现原理也很简单,就是将一个属性设置在session中.在访问的时候进行判断即可. 例:re ...

  3. JS~JS里的数据类型

    JS里的数据类型,它虽然是个弱类型的语言,但它也有自己的规定的,它不会向其它语言那么,使用int来声明一个整形变量,而是使用 var,如果你是一个C#的开发者,你就会知道,原来C#现在也在和JS学,开 ...

  4. iOS/iPhone 程序文件目录结构以及启动流程

    要想清晰的理解IOS应用程序的启动过程,毫无疑问需要深入了解一下ios应用程序的文件系统.一个ios应用程序都有一个属于自己沙盒(sandbox),应用沙盒就是文件系统目录,并且与文件系统的其他部分隔 ...

  5. onvif规范的实现:成功实现ONVIF协议RTSP-Video-Stream与OnvifDeviceManager的视频对接

    有了前几篇的基础,现在可以正式开始onvif的实现工作,其中一项非常重要的部分就是视频流的对接,即能够在符合onvif标准的监控客户端软件里接收到设备端NVT发来的RTSP视频流.这里,我所用的客户端 ...

  6. 用MVC4+EF改写XXX系统的计划--前言

    感觉自己工作了三年,重来没有自己一个人写一个项目,从开始的策划,功能需求,业务逻辑,扩展,性能优化等等方面去做,从今天起准备发比半年时间重写XXX项目,每天中午和晚上分别花半个小时和一个小时开发,周末 ...

  7. background小结

    CSS背景属性Background详解 本文详解了CSS的背景属性Background,包括CSS3中新增的背景属性.如果你是个CSS初学者,还可以查看之前介绍的CSS浮动属性和CSS透明属性详解. ...

  8. Spring Ioc知识整理

    Ioc知识整理(一): IoC (Inversion of Control) 控制反转. 1.bean的别名 我们每个bean元素都有一个id属性,用于唯一标识实例化的一个类,其实name属性也可用来 ...

  9. wpf中,一个简单的自定义treeview

    首先创建一个自定义控件,在里面定义好treeview的样式,将本来的三角形的图标变为加号的图标,并且添加节点之间的连线. <UserControl x:Class="TreeViewE ...

  10. Makefiles 介绍

    http://www-personal.umich.edu/~ppannuto/writings/makefiles.html Makefiles Makefiles (or, the GNU aut ...