Solving linear system - but using only parts of the Matrix

2 Ansichten (letzte 30 Tage)
Hi everyone,
I'm trying to solve a linear system of equations but want to use only selectet rows for that operation.
For example:
D=
0 0 0 0 0.345265357599750 0.457309520629080 0.548726230994530 0 0 0 0
0 0 0 0 0.200398189744228 0.345265357599750 0.457309520629080 0 0 0 0
0 0 0 0 -0.00530900651840216 0.200398189744228 0.345265357599750 0 0 0 0
0 0 0 0 -0.369187964058863 -0.00530900651840216 0.200398189744228 0 0 0 0
0 0 0 0 -1.19314718055995 -0.369187964058863 -0.00530900651840216 0 0 0 0
0 0 0 0 -0.369187964058863 -1.19314718055995 -0.369187964058863 0 0 0 0
0 0 0 0 -0.00530900651840216 -0.369187964058863 -1.19314718055995 0 0 0 0
0 0 0 0 0.200398189744228 -0.00530900651840216 -0.369187964058863 0 0 0 0
0 0 0 0 0.345265357599750 0.200398189744228 -0.00530900651840216 0 0 0 0
0 0 0 0 0.457309520629080 0.345265357599750 0.200398189744228 0 0 0 0
0 0 0 0 0.548726230994530 0.457309520629080 0.345265357599750 0 0 0 0
U=
0
0
0
0
1.14881496080949e-07
3.47991801628408e-07
1.14881496080949e-07
0
0
0
0
I want to perform the operation
P=D\U
But only with the 3 rows that contain a result in the variable U.
P should be
P=
0
0
0
0
-7.42753614188724e-09
-2.87062227792614e-07
-7.42753614188723e-09
0
0
0
0
Can somebody help me, how to program this?
Very best
Christian

Akzeptierte Antwort

Star Strider
Star Strider am 3 Mai 2021
The lsqr function is appropriate here —
D = [...
0 0 0 0 0.345265357599750 0.457309520629080 0.548726230994530 0 0 0 0
0 0 0 0 0.200398189744228 0.345265357599750 0.457309520629080 0 0 0 0
0 0 0 0 -0.00530900651840216 0.200398189744228 0.345265357599750 0 0 0 0
0 0 0 0 -0.369187964058863 -0.00530900651840216 0.200398189744228 0 0 0 0
0 0 0 0 -1.19314718055995 -0.369187964058863 -0.00530900651840216 0 0 0 0
0 0 0 0 -0.369187964058863 -1.19314718055995 -0.369187964058863 0 0 0 0
0 0 0 0 -0.00530900651840216 -0.369187964058863 -1.19314718055995 0 0 0 0
0 0 0 0 0.200398189744228 -0.00530900651840216 -0.369187964058863 0 0 0 0
0 0 0 0 0.345265357599750 0.200398189744228 -0.00530900651840216 0 0 0 0
0 0 0 0 0.457309520629080 0.345265357599750 0.200398189744228 0 0 0 0
0 0 0 0 0.548726230994530 0.457309520629080 0.345265357599750 0 0 0 0];
U = [...
0
0
0
0
1.14881496080949e-07
3.47991801628408e-07
1.14881496080949e-07
0
0
0
0];
ix = U~=0;
format long g
P = lsqr(D(ix,:),U(ix))
lsqr converged at iteration 2 to a solution with relative residual 1e-15.
P = 11×1
0 0 0 0 -7.42753614188729e-09 -2.87062227792613e-07 -7.42753614188729e-09 0 0 0
format short
.
  2 Kommentare
Christian S.
Christian S. am 4 Mai 2021
It works perfectly! Thank you very much Star Strider!
Very best
Christian
Star Strider
Star Strider am 4 Mai 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by