Solving linear system - but using only parts of the Matrix

1 回表示 (過去 30 日間)
Christian S.
Christian S. 2021 年 5 月 3 日
コメント済み: Star Strider 2021 年 5 月 4 日
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

採用された回答

Star Strider
Star Strider 2021 年 5 月 3 日
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 件のコメント
Christian S.
Christian S. 2021 年 5 月 4 日
It works perfectly! Thank you very much Star Strider!
Very best
Christian
Star Strider
Star Strider 2021 年 5 月 4 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by