Inaccuracy in solving simultaneous equations using matrix

So i was solving a system of n linear equations. My coefficient matrix is a tridiagonal one.
However as i was decreasing the values inside matrix or increasing n the error was increasing rapidly.
clear
n=1000;
B=(1:n);
B=B';
A=full(gallery('tridiag',n,0.341,0.232,0.741));
x=A\B;
c=A*x-B;
error=0;
for i=1:n
error=error+abs(c(i,1));
end
error
%error = 2.174626266011847e+155
Here the system is in the form Ax=B
ideally c should contain only zero.
Can anyone a suggest a method so that i can decrease the net error.
NOTE: I also tried the Thomas Algorithm even that gave an error of similar order .

3 件のコメント

Walter Roberson
Walter Roberson 2020 年 6 月 3 日
>> rcond(A)
ans =
5.96371748872238e-170
Much too small for reliable numeric solution. rank(A) says 999 rather than 1000.
Switching to symbolic toolbox is able to get full rank and exact solution.
Susmit Kumar Mishra
Susmit Kumar Mishra 2020 年 6 月 3 日
How can one solve system of equations involving variable names in an array using symbolic toolbox.
Can you just give an example by solving above set of equations in symbolic toolbox and display the corresponding error.
Walter Roberson
Walter Roberson 2020 年 6 月 3 日
編集済み: Walter Roberson 2020 年 6 月 3 日
n = 1000;
B = (1:n).';
A = sym( full(gallery('tridiag',n,0.341,0.232,0.741)) ); %11 seconds
x = A\B; %not fast!! 43 seconds
c = A*x-B;
error = sum(abs(c));
disp(error)

サインインしてコメントする。

 採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 6 月 3 日

1 投票

If you run this code-snippet:
N = round(logspace(1,3,7));
for i1 = 1:numel(N),
n = N(i1);
B=(1:n)';
A=full(gallery('tridiag',n,0.341,0.232,0.741));
[U,S,V] = svd(A);
ph(i1) = plot(diag(S),'.-','linewidth',2,'markersize',15,'color',rand(1,3));
title(n)
drawnow
end
% Pause
set(gca,'xscale','log')
% Pause
set(gca,'yscale','log')
You will see that the smallest eigenvalue is way smaller than the next smallest. Such matrices A are illconditioned and are a bit more problematic to solve. For more information and better tools to handle such problems have a look at regtools.
HTH

その他の回答 (0 件)

カテゴリ

製品

リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by