Solving linear system - but using only parts of the Matrix

3 次查看(过去 30 天)
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
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Least Squares 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by