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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by