【MATLAB100个实用小技巧】——数值分析(85-100)

news2024/9/24 8:35:41

文章目录

  • 前言
  • 系列文章
  • 85.
  • 86. 三次样条插值法
  • 87. NEWTON 插值
  • 88. hermite 插值
  • 89. newton 形式的 hermite 插值
  • 90. 平方根法
  • 91. gauss 消去法
  • 92. 三角分解法
  • 93. jacobi 迭代法
  • 94. gauss 迭代法
  • 95. sor 迭代法
  • 96. 最速下降法
  • 97. 共额梯度法
  • 98. newton 迭代法
  • 99. broyden 迭代法
  • 100. 逆 broyden 迭代法

前言

🌏MATLAB是一个功能强大的软件,我们可以利用MATLAB进行绘图、算法验证、仿真实验等等。在学习MATLAB的过程中,繁多的命令与代码往往容易使我们脑容量过载😭😭😭请添加图片描述
🌏本系列将总结一些常见的MATLAB编程小技巧😽😽
🌏可能有些地方会有些错误或者是不太完善的,还请大家在评论区直接指出❤️❤️❤️

系列文章

【MATLAB100个实用小技巧】——图形应用(1-10)
【MATLAB100个实用小技巧】——图形应用(11-20)
【MATLAB100个实用小技巧】——图形应用(21-32)
【MATLAB100个实用小技巧】——界面设计(33-43)
【MATLAB100个实用小技巧】——界面设计(44-55)
【MATLAB100个实用小技巧】——界面设计(56-66)
【MATLAB100个实用小技巧】——图形处理(67-75)
【MATLAB100个实用小技巧】——图形处理(76-84)
【MATLAB100个实用小技巧】——数值分析(85-100)

85.

😉代码


X=input('请输入横坐标向量X:\nX=');  %输入的数据为一维数组,例如:[1,3,4,5](下同);
Y=input('请输入纵坐标向量Y:\nY=');
m = length(X);
L = ones(m,m);
for k = 1 : m
    V = 1;
    for i = 1 : m
        if k ~= i
            V = conv(V,poly(X(i))) / (X(k) - X(i));
        end
    end
    l(k, :) = poly2sym(V);
end

fprintf('基函数为:\n');
for k=1:m
    fprintf('q%d(x)=%s\n',k,l(k));
end
L = Y * l;
fprintf('拉格朗日多项式为:\nP(x)=%s\n',L);

😊效果
在这里插入图片描述

86. 三次样条插值法

😎重点 spline
😉代码

x = [0 1 2.5 3.6 5 7 8.1 10];
y = sin(x);
xx = 0:.25:10;
yy = spline(x,y,xx);
plot(x,y,'o',xx,yy)

😊效果

87. NEWTON 插值

参考博客
😉代码

function [A,y]= newtonzi(X,Y,x)
%   Newton插值函数
%   X为已知数据点的x坐标
%   Y为已知数据点的y坐标
%   x为插值点的x坐标
%   函数返回A差商表
%   y为各插值点函数值
n=length(X); m=length(x);
for t=1:m
    z=x(t); A=zeros(n,n);A(:,1)=Y';
    s=0.0; y=0.0; c1=1.0;
    for  j=2:n
       for i=j:n
           A(i,j)=(A(i,j-1)- A(i-1,j-1))/(X(i)-X(i-j+1));
       end
    end
    C=A(n,n);
    for k=1:n
        p=1.0;
        for j=1:k-1
            p=p*(z-X(j));
        end
        s=s+A(k,k)*p;        
    end
    ss(t)=s;
end
    y=ss;
    A=[X',A];    
end

88. hermite 插值

参考博客
😉代码

%插值算法 (常用) 

%Hermite(埃尔米特)插值法

a=0;
a=input('请输入数据矩阵的行数:');

b=0;
b=input('请输入数据矩阵的列数:');

%初始化目标矩阵
c=zeros(a,b);
c=input('请依次输入数据矩阵:');
disp('数据矩阵:');
disp(c);

%确定插值区间
d=0;
d=input('请输入插值区间:');


%进行插值
e(1,:)=d;

[n,m]=size(c);

for i=2:n
    e(i,:)=pchip(c(1,:),c(i,:),d);
end

%目标矩阵
disp('Hermite插值后的矩阵:');
disp(e);

😊效果

89. newton 形式的 hermite 插值

参考博客

90. 平方根法

😉代码

h0=figure('toolbar','none',... 
    'position',[200 150 450 250]);
h1=axes('parent',h0,...
    'position',[0.05 0.15 0.65 0.6],...
'visible','off'); 
I=imread('abmatrix.bmp','bmp');
image(I)
axis off 
huidiao=[...
'a=[1 0 3 0;0 2 1 2;3 1 15 0;0 2 0 4;];,',...
'b=[1 6 5 8]'';,',...
'r=[a,b];,',...
'n=4;,',...
'tic,',... 
'x=ch(a,b,n);,',... 
'time1=toc;,',...
'T=num2str(time1);,',... 
'set(e1,''string'',[T,''秒'']);,',...
'msgbox([''X=['',num2str(x(1)),num2str(x(2)),num2str(x(3)),num2str(x(4)),'']''],''方程组的解'');'];
t1=uicontrol('parent',h0,...
    'units','points',...
'tag','t1',...
'style','text',...
'string','方程组如下:',...
'fontsize',15,... 
'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 100 20]);
e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',...
'horizontalalignment','right',...
'backgroundcolor',[1 1 1],...
'position',[290 100 30 20]);
t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',15,... 
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 125 80 20]);
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','平方根法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],...
'callback',huidiao);
b2=uicontrol('parent',h0,...
    'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

😊效果

91. gauss 消去法

😉代码

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 91');
h1=axes('parent',h0,...
    'position',[0.05 0.15 0.65 0.6],...
'visible','off'); 
I=imread('abmatrix.bmp','bmp'); 
image(I)
axis off 
huidiao=[...
'a=[1 2 4 1 7;2 3 0 1 8;4 1 7 6 1;1 1 0 2 1;1 3 0 1 1;];,',...
'b=[15 14 19 5 6]'';,',...
'r=[a,b];,',...
'n=5;,',...
'tic,',...
'x=gauss(r,n);,',...
'time1=toc;,',...
'T=num2str(time1);,',... 
'set(e1,''string'',[T,''秒'']);,',...
'msgbox([''X=['',num2str(x(1)),num2str(x(2)),num2str(x(3)),num2str(x(4)),num2str(x(5)),'']''],''方程组的解'');']; t1=uicontrol('parent',h0,...
'units','points',...
'tag','t1',...
'style','text',...
'string','方程组如下:',...
'fontsize',15,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 100 20]); 
e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',... 
'horizontalalignment','right',... 
'backgroundcolor',[1 1 1],...
'position',[290 100 30 20]);
t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',15,...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 125 80 20]);
b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','GS 消去法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],...
'callback',huidiao);
b2=uicontrol('parent',h0,...
    'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

😊效果

92. 三角分解法

😉代码

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 92');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('abmatrix.bmp','bmp'); image(I)
axis off huidiao=[...
'a=[1 2 4 1 7;2 3 0 1 8;4 1 7 6 1;1 1 0 2 1;1 3 0 1 1;];,',...
'b=[15 14 19 5 6]'';,',... 'n=5;,',...
'tic,',... 'x=dirang(a,b,n);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'msgbox([''X	=
['',num2str(x(1)),num2str(x(2)),num2str(x(3)),num2str(x(4)),num2str(x(5)),'']''],''方程组的解'');']; t1=uicontrol('parent',h0,...
'units','points',...
'tag','t1',...
'style','text',...
'string','方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 100 20]); e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...

'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[270 100 50 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 125 80 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','三角分解法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],... 'callback',huidiao);
b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

😊效果

93. jacobi 迭代法

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 93');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('abmatrix.bmp','bmp'); image(I)
axis off huidiao=[...
'a=[1 0 3 0;0 2 1 2;3 1 15 0;0 2 0 4;];,',...
'b=[1 6 5 8]'';,',... 'n=4;,',...
'u=zeros(n,1);,',...

'tic,',... '[x,k]=jac(a,b,n,u);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'set(e2,''string'',num2str(k));,',...
'msgbox([''X	=	['',num2str(x(1)),''	'',num2str(x(2)),''
'',num2str(x(3)),'','',num2str(x(4)),'']''],''方程组的解'');']; t1=uicontrol('parent',h0,...
'units','points',...
'tag','t1',...
'style','text',...
'string','方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 100 20]); e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 130 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 130 50 20]); e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 100 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','迭代步数:',...
'fontsize',10,...

'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 100 50 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','Jacobi 迭代法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],... 'callback',huidiao);
b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

94. gauss 迭代法

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 94');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('abmatrix.bmp','bmp'); image(I)
axis off huidiao=[...
'a=[1 0 3 0;0 2 1 2;3 1 15 0;0 2 0 4;];,',...
'b=[1 6 5 8]'';,',... 'n=4;,',...
'u=zeros(n,1);,',... 'tic,',... '[x,k]=gs(a,b,n,u);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'set(e2,''string'',num2str(k));,',...
'msgbox([''X	=	['',num2str(x(1)),''	'',num2str(x(2)),''
'',num2str(x(3)),'','',num2str(x(4)),'']''],''方程组的解'');']; t1=uicontrol('parent',h0,...
'units','points',...

'tag','t1',...
'style','text',...
'string','方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 100 20]); e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 130 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 130 50 20]); e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 100 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','迭代步数:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 100 50 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','GS 迭代法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],... 'callback',huidiao);

b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

95. sor 迭代法

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 95');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('abmatrix.bmp','bmp'); image(I)
axis off huidiao=[...
'a=[1 0 3 0;0 2 1 2;3 1 15 0;0 2 0 4;];,',...
'b=[1 6 5 8]'';,',... 'n=4;,',...
'u=zeros(n,1);,',... 'tic,',... '[x,k]=sor(a,b,n,u);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'set(e2,''string'',num2str(k));,',...
'msgbox([''X	=	['',num2str(x(1)),''	'',num2str(x(2)),''
'',num2str(x(3)),'','',num2str(x(4)),'']''],''方程组的解'');']; t1=uicontrol('parent',h0,...
'units','points',...
'tag','t1',...
'style','text',...
'string','方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 100 20]); e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',...

'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 130 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 130 50 20]); e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 100 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','迭代步数:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 100 50 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','SOR 迭代法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],... 'callback',huidiao);
b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

96. 最速下降法

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 96');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('abmatrix.bmp','bmp'); image(I)
axis off huidiao=[...
'a=[1 0 3 0;0 2 1 2;3 1 15 0;0 2 0 4;];,',...
'b=[1 6 5 8]'';,',... 'n=4;,',...
'u=zeros(n,1);,',... 'tic,',... '[x,k]=cg(a,b,n,u);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'set(e2,''string'',num2str(k));,',...
'msgbox([''X	=	['',num2str(x(1)),''	'',num2str(x(2)),''	'',num2str(x(3)),'','', num2str(x(4)),'']''],''方程组的解'');'];
t1=uicontrol('parent',h0,... 'units','points',...
'tag','t1',...
'style','text',...
'string','方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 100 20]); e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 130 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...

'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 130 50 20]); e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 100 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','迭代步数:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 100 50 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','最速下降法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],... 'callback',huidiao);
b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

97. 共额梯度法

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 97');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('abmatrix.bmp','bmp'); image(I)

axis off huidiao=[...
'a=[1 0 3 0;0 2 1 2;3 1 15 0;0 2 0 4;];,',...
'b=[1 6 5 8]'';,',... 'n=4;,',...
'u=zeros(n,1);,',... 'tic,',... '[x,k]=getd(a,b,n,u);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'set(e2,''string'',num2str(k));,',...
'msgbox([''X	=	['',num2str(x(1)),''	'',num2str(x(2)),''
'',num2str(x(3)),'','',num2str(x(4)),'']''],''方程组的解'');']; t1=uicontrol('parent',h0,...
'units','points',...
'tag','t1',...
'style','text',...
'string','方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 100 20]); e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 130 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 130 50 20]); e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 100 35 20]);

t2=uicontrol('parent',h0,... 'units','points',...
'tag','t2',...
'style','text',...
'string','迭代步数:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 100 50 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','共轭梯度法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],... 'callback',huidiao);
b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

98. newton 迭代法

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 98');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('fabmatrix.bmp','bmp'); image(I)
axis off huidiao=[...
'n=3;,',...
'u=zeros(n,1);,',... 'tic,',... '[x,k]=nnewton(u,n);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'set(e2,''string'',num2str(k));,',...


'');'];

'msgbox([''X=['',num2str(x(1)),'' '',num2str(x(2)),'' '',num2str(x(3)),'']''],'' 方程组的解

t1=uicontrol('parent',h0,... 'units','points',...
'tag','t1',...
'style','text',...
'string','非线性方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 150 20]); e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 130 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 130 50 20]); e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 100 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','迭代步数:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 100 50 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...

'string','Newton 迭代法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],... 'callback',huidiao);
b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

99. broyden 迭代法

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 99');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('fabmatrix.bmp','bmp'); image(I)
axis off huidiao=[...
'n=3;,',...
'u=zeros(n,1);,',... 'tic,',... '[x,k]=broyden(u,n);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'set(e2,''string'',num2str(k));,',...
'msgbox([''X=['',num2str(x(1)),'' '',num2str(x(2)),'' '',num2str(x(3)),'']''],'' 方程组的解
'');'];
t1=uicontrol('parent',h0,... 'units','points',...
'tag','t1',...
'style','text',...
'string','非线性方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 150 20]); e1=uicontrol('parent',h0,...
'units','points',...

'tag','e1',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 130 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 130 50 20]); e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 100 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','迭代步数:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 100 50 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','Broyden 迭代法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 60 20],... 'callback',huidiao);
b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 60 20],...
'callback','close');

100. 逆 broyden 迭代法

h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例 100');
h1=axes('parent',h0,... 'position',[0.05 0.15 0.65 0.6],...
'visible','off'); I=imread('fabmatrix.bmp','bmp'); image(I)
axis off huidiao=[...
'n=3;,',...
'u=zeros(n,1);,',... 'tic,',... '[x,k]=fbroyden(u,n);,',... 'time1=toc;,',...
'T=num2str(time1);,',... 'set(e1,''string'',[T,''秒'']);,',...
'set(e2,''string'',num2str(k));,',...
'msgbox([''X=['',num2str(x(1)),'' '',num2str(x(2)),'' '',num2str(x(3)),'']''],'' 方程组的解
'');'];
t1=uicontrol('parent',h0,... 'units','points',...
'tag','t1',...
'style','text',...
'string','非线性方程组如下:',...
'fontsize',15,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[20 150 150 20]); e1=uicontrol('parent',h0,...
'units','points',...
'tag','e1',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 130 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','计算时间:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...

'position',[240 130 50 20]); e2=uicontrol('parent',h0,...
'units','points',...
'tag','e2',...
'style','edit',... 'horizontalalignment','right',... 'backgroundcolor',[1 1 1],...
'position',[295 100 35 20]); t2=uicontrol('parent',h0,...
'units','points',...
'tag','t2',...
'style','text',...
'string','迭代步数:',...
'fontsize',10,... 'backgroundcolor',[0.75 0.75 0.75],...
'position',[240 100 50 20]); b1=uicontrol('parent',h0,...
'units','points',...
'tag','b1',...
'style','pushbutton',...
'string','逆 Broyden 迭代法',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 60 70 20],... 'callback',huidiao);
b2=uicontrol('parent',h0,... 'units','points',...
'tag','b2',...
'string','关闭',...
'style','pushbutton',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[250 30 70 20],...
'callback','close');
XOR

function [x,st]=sor(a,b,n,x1) D=zeros(n,n);
L=zeros(n,n);
U=zeros(n,n); for i=1:n
for j=1:n
if j==i
D(i,j)=a(i,j);
end if j<i









end







end


end if j>i

end

L(i,j)=-a(i,j);



U(i,j)=-a(i,j);

opt=oumiga(a);
Bsor=inv(D-opt*L)*[(1-opt)*D+opt*U]; fsor=opt*inv(D-opt*L)*b;
k=1;
x2=Bsor*x1+fsor; e=x2-x1;
while norm(e,2)>1e-6 k=k+1;
x1=x2; x2=Bsor*x1+fsor; e=x2-x1;
end x=x2; st=k;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/98246.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

前端媒体查询@media示例详解和calc()函数的使用

媒体查询media media 可以针对不同的屏幕尺寸设置不同的样式&#xff0c;特别是如果需要设置设计响应式的页面&#xff0c;media 是非常有用的。当重置浏览器大小的过程中&#xff0c;页面也会根据浏览器的宽度和高度重新渲染页面。 eg&#xff1a;如果文档宽度小于 500 像素…

pytorch 自编码器实现图像的降噪

自编码器 自动编码器是一种无监督的深度学习算法&#xff0c;它学习输入数据的编码表示&#xff0c;然后重新构造与输出相同的输入。它由编码器和解码器两个网络组成。编码器将高维输入压缩成低维潜在(也称为潜在代码或编码空间) &#xff0c;以从中提取最相关的信息&#xff…

SpringCloud之Hystrix

复杂分布式体系结构中的应用程序有数十个依赖关系&#xff0c;每个依赖关系在某些时候将不可避免失败&#xff01; 服务雪崩 多个微服务之间调用的时候&#xff0c;假设微服务A调用微服务B和微服务C&#xff0c;微服务B和微服务C又调用其他的微服务&#xff0c;这就是所谓的“…

HttpRunner3.x 安装与使用

HttpRunner3.x 安装与使用HttpRunner3.x 安装与使用安装使用运行脚手架项目方式一&#xff1a;录制生成用例步骤1&#xff1a;导出har文件步骤2&#xff1a;转化成测试用例文件har2casehmake步骤3&#xff1a;执行测试用例方式二&#xff1a;手工编写测试用例HttpRunner3.x 安装…

Jenkins自动部署springboot的Docker镜像,解决Status [1]问题

Jenkins凡是要指定路径的命令&#xff0c;一定要写绝对路径&#xff0c;不能写相对路径&#xff01;不要以为配置了Remote directory&#xff0c;那么命令就会在Remote directory下执行&#xff01;这种想法是错误的&#xff01;&#xff01;&#xff01; 《jenkins自动化发布到…

机器学习实战教程(五):朴素贝叶斯实战篇

一、前言 上篇文章机器学习实战教程&#xff08;四&#xff09;&#xff1a;朴素贝叶斯基础篇_M_Q_T的博客-CSDN博客讲解了朴素贝叶斯的基础知识。本篇文章将在此基础上进行扩展&#xff0c;你将看到以下内容&#xff1a; 拉普拉斯平滑垃圾邮件过滤(Python3)新浪新闻分类(skle…

毕业设计 - 基于Java的敬老院管理系统设计与实现【源码+论文】

文章目录前言一、项目设计1. 模块设计系统的主要功能性需求2. 实现效果二、部分源码项目源码前言 今天学长向大家分享一个 java web项目: 基于Java的敬老院管理系统设计与实现 一、项目设计 1. 模块设计 站在护工角度来看&#xff0c;他们迫切希望&#xff0c;在运用该系统…

【Flink】Flink Starting Offset 启动消费位置 指定时间消费

文章目录 1.概述2.测试3.源码1.概述 首先参考文章:【Flink】Flink 1.14.0 全新的 Kafka Connector Kafka Source 能够通过指定 OffsetsInitializer来消费从不同偏移量开始的消息。内置的初始值设定项包括: KafkaSource.builder()// Start from committed offset of the co…

【YOLOv7-环境搭建③】PyCharm安装和环境、解释器配置

下载链接&#xff1a; 来源&#xff1a;&#xff08;博主&#xff09;唐三. 链接:https://pan.baidu.com/s/1y6s_EScOqvraFcx7iPSy1g 提取码:m1oa 安装&#xff1a; 以管理员身份打开安装完成后&#xff0c;打开软件到达以下界面&#xff0c;框框全选到达以下界面&#xf…

【指纹识别】指纹识别匹配门禁系统【含GUI Matlab源码 587期】

⛄一、指纹识别简介 1 指纹识别的引入和原理 1.1 指纹的基本知识 指纹&#xff0c;由于其具有终身不变性、唯一性和方便性&#xff0c;已几乎成为生物特征识别的代名词。指纹是指人的手指末端正面皮肤上凸凹不平产生的纹线。纹线有规律的排列形成不同的纹型。纹线的起点、终点…

kotlin基础学习笔记第九章——泛型

实化类型参数允许你在运行时的内联函数中引用作为类型实参的具体类型&#xff08;对普通的类和函数来说&#xff0c;这样行不通&#xff0c;因为类型实参在运行时会被擦除&#xff09;。 声明点变型可以说明一个带类型参数的泛型类型&#xff0c;是否是另一个泛型类型的子类型或…

什么是MySQL插入意向锁?

Insert Intention Lock&#xff0c;中文我们也称之为插入意向锁。 这个可以算是对我们之前所讲的 Gap Lock 的一个补充&#xff0c;关于 Gap Lock&#xff0c;如果还有小伙伴不懂&#xff0c;可以参考&#xff1a;记录锁、间隙锁与 Next-Key Locks。 1. 为什么需要插入意向锁…

吃透Chisel语言.40.Chisel实战之单周期RISC-V处理器实现(下)——具体实现和最终测试

Chisel实战之单周期RISC-V处理器实现&#xff08;下&#xff09;——具体实现和最终测试 上一篇文章中我们对本项目的需求进行了分析&#xff0c;并得到了初步的设计&#xff0c;这一篇文章我们就可以基于该设计来实现我们的单周期RISC-V处理器了。实现之后也必须用实际代码来…

[ 数据结构 -- 手撕排序算法第三篇 ] 希尔排序

文章目录前言一、常见的排序算法二、希尔排序2.1 希尔排序(缩小增量排序)2.1.1 预排序阶段2.1.2 插入排序阶段2.2 单趟希尔排序2.2.1 思路分析三、希尔排序实现代码四、希尔排序的时间复杂度五、希尔排序和直接插入排序效率测试5.1 测试5.2 结论5.2.1 随机数比较5.2.2 有序数组…

【二维码识别】灰度+二值化+校正二维码生成与识别【含GUI Matlab源码 635期】

⛄一、二维码生成与识别简介 如今,移动互联网技术日新月异,随着5G时代的来临,广泛应用于数据处理过程中的二维码信息安全日益成为人们越来越关注的问题。以QR码为代表的二维码,以其在信息存储、传输和识别技术领域优异的表现,成为信息共享、移动支付等领域的宠儿。不可避免地,…

利用深度学习生成数据的时间序列预测(Matlab代码实现)

目录 &#x1f4a5;1 概述 &#x1f4da;2 运行结果 &#x1f389;3 参考文献 &#x1f468;‍&#x1f4bb;4 Matlab代码 &#x1f4a5;1 概述 数据分析研究目前仍是行业热点,相关学者从数据分析关键技术中的异常检测、入侵检测、时间序列预测等角度展开研究。然而,现有研…

Go环境搭建与IDE开发工具配置

安装Go语言编译器 Go语言编译器》编译器将源代码编译为可执行程序》源代码程序员使用高级语言所书写的代码文件》高级语言c/c/go…》机器语言0和1构成&#xff0c;机器能直接识别》汇编语言比机器语言稍微可读一点点的指令集 编译器下载地址 根据系统下载对应的go编译器版本…

微信小程序保存相册授权全过程:第一次授权、已授权、拒绝后再授权

微信小程序部分功能需要使用授权&#xff08;也就是需要用户显式同意&#xff0c;系统会阻止开发者任何静默获取授权行为&#xff09;&#xff0c;以存储相册为例&#xff0c;用户需要获得"scope.writePhotosAlbum"权限 微信系统接口wx.getSetting可以获取已经获得的…

MySQL连接数据库

①MySQLpymysql ②django开发操作数据库&#xff0c;orm框架 安装第三方模块&#xff1a;orm pip install mysqlclient ORM Django链接数据库 在settings.py中修改 查看创建的数据库的端口号和用户名&#xff1a; Django操作表&#xff1a; 创建表 models.py from django…

[附源码]Python计算机毕业设计Django新冠疫苗接种预约系统

项目运行 环境配置&#xff1a; Pychram社区版 python3.7.7 Mysql5.7 HBuilderXlist pipNavicat11Djangonodejs。 项目技术&#xff1a; django python Vue 等等组成&#xff0c;B/S模式 pychram管理等等。 环境需要 1.运行环境&#xff1a;最好是python3.7.7&#xff0c;…