solve A*X=B containing very large or small elements

hello
i have this linear system of equations A*X=B, which is apparently ill-conditioned with RCOND = 0. the elements in these matrices are either extremely large or small which have been derived using "besseli" and "besselk" functions.
A=
2.7673e+84 -2.7673e+84 -9.1252e-88 0 0 0 0 0 0 0
1.1039e+87 -2.2078e+90 7.2433e-82 0 0 0 0 0 0 0
0 7.7866e+105 2.5944e-109 -7.7866e+105 -2.5944e-109 0 0 0 0 0
0 6.2089e+111 -2.0604e-103 -6.2089e+111 2.0604e-103 0 0 0 0 0
0 0 0 1.5218e+110 1.2764e-113 -1.5218e+110 -1.2764e-113 0 0 0
0 0 0 1.2134e+116 -1.0138e-107 -1.2134e+116 1.0138e-107 0 0 0
0 0 0 0 0 2.2359e+127 7.5295e-131 -2.2359e+127 -7.5295e-131 0
0 0 0 0 0 1.7822e+133 -5.9817e-125 -8.9112e+129 2.9909e-128 0
0 0 0 0 0 0 0 1.9154e+170 6.5919e-174 -6.5919e-174
0 0 0 0 0 0 0 7.6309e+172 -2.6195e-171 5.239e-168
B=
-5.3706e+78
-4.2847e+84
1.5112e+100
1.205e+106
0
0
0
0
0
0
the solution is returend using X=A\B :
X=
0
1.9407e-06
4.6374e+150
8.1617e-89
4.6374e+150
1.5549e-107
4.6374e+150
-3.1817e-193
9.2546e+150
9.2616e+147
but it has realy large error:
A*X-B=
-8.2275e+63
0
-1.9427e+84
0
1.8889e+22
0
0
-1.0771e+10
-2.25e-39
0
also I am uncertained that in the future I might need to calculate other matrices which could probably contain even larger or smaller values that leads to "inf" or "0" elements.
I know that using "digits" and "vpa" functions in symbolic math toolbox it is really accurate but SPEED plays an important role in my code.
I have searched about "Fixed-point Designer Tollbox" but I did not find an example like mine.
what is the best workaround in this condition?

 Accepted Answer

Bruno Luong
Bruno Luong on 9 Aug 2020
Edited: Bruno Luong on 9 Aug 2020
Work with unitless system, scale your matrix, or use automatic scaling if you don't want to bother.

4 Comments

thank you for answering. but i am using matlab 2016a and it does not have equilibrate function.
scaling each simple equation means to scale the one row of coefficient matrix A, which in this problem it is ineffective; because in one row you can find two large coefficents and two small ones.
and I am already working in unitless system. for example one element is "besseli(1,n*p*x)" and "n" is harmonic number and "p" is pole-pairs number both are unitless and "x" is distance which is maximum 0.09 meter. if I make "x" per-unit then it would be even larger.
I have been looking for a way to solve this for about one month. I would be glad if any other way is proposed. thanks.
It looks like your matrix is large or small by columns, meaning you need to scale you unknown so that it about unit.
When you say the bessel has x in meter then it doesn't seem you work with unitless. It must work on unit of your "wavelength".
I don't know about your system, but looks badly scaled.
Exactly. I must scale the unknown vector "X" to "X=C.*X1" in which "C" is scaling coefficiets vector. and therefore the equation "A*X=B" must be transfomed into "A*(C.*X1)=B" or "A1*X1=B". in which "A1=A.*repmat(C.',[length(X) 1])". now that "A1" and "X1" are scaled and "A1" is well-conditioned; the solution is "X=C.*X1=C.*(A1\B)". am I rigth?
I think that's the spot.
many thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!