⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsolvernxn.m

📁 fastsolving linear equation
💻 M
字号:
%WARNING WORKSPACE WILL BE CLEARED!!!!
clc
clearvars
close all



m=3;%we want to solve mxm linear systems

nsyst=10;%number of systems


Amxn=rand(m,nsyst*m);%elements of nsyst mxm systems
b=rand(nsyst*m,1);%system vector

Amxn(:,end+1:end+m)=0;
b(end+1:end+m)=1;
nsyst=nsyst+1;

fprintf('Program started\n\n')

fprintf('We are going to solve %4.0f %4.0fx%1.0f systems\n',nsyst,m,m)



%Solve looping
x2=zeros(nsyst*m,1);
i1=1;
i2=m;
tic
for i=1:nsyst
    x2(i1:i2)=Amxn(:,i1:i2)\b(i1:i2);
    i1=i1+m;
    i2=i2+m;
end
fprintf('Looping took: %4.4f s\n',toc);


%Run solverNxN
tic
x=SolverNxN(Amxn,b);
fprintf('Solver NxN took: %4.4f s\n\n',toc)

%check the solution
Residue=norm(x-x2);
if Residue<1e-6*nsyst
    fprintf('Residue is %4.4f Solution is correct!\n',Residue);
else
    beep
    fprintf('Bug Found, Residue is %4.4f, please a report to the author\n',Residue);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -