Solving linear systems in Matlab

1 回表示 (過去 30 日間)
L'O.G.
L'O.G. 2023 年 8 月 24 日
編集済み: Bruno Luong 2023 年 8 月 24 日
How do I solve for x in u = A(x+b)? A is a matrix, and the other terms are vectors. Isn't it something like x = A\u - b ? I'm not sure about subtracting the b term, however.
  1 件のコメント
Bruno Luong
Bruno Luong 2023 年 8 月 24 日
編集済み: Bruno Luong 2023 年 8 月 24 日
You need to be careful when the system is undedetermined (usually more unknown than equation)
In some sense x = A\u - b is the worse you can pick.

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

採用された回答

Torsten
Torsten 2023 年 8 月 24 日
編集済み: Torsten 2023 年 8 月 24 日
x = A\(u-A*b)
But it's the same as
x = A\u - b
  1 件のコメント
Bruno Luong
Bruno Luong 2023 年 8 月 24 日
編集済み: Bruno Luong 2023 年 8 月 24 日
Is it?
A=rand(3,4);
b=rand(4,1);
u=rand(3,1);
% 4 different solutions
x1=A\(u-A*b)
x1 = 4×1
-0.2210 0 -0.6049 -0.1026
x2=A\u-b
x2 = 4×1
-0.0231 -0.8875 -1.3122 1.0476
x3=lsqminnorm(A,u)-b
x3 = 4×1
-0.1409 -0.3592 -0.8912 0.3630
x4=lsqminnorm(A,u-A*b)
x4 = 4×1
-0.2409 0.0891 -0.5339 -0.2181
% All give the same "fitness"
A*x1-u
ans = 3×1
-0.9852 -1.3140 -1.3694
A*x2-u
ans = 3×1
-0.9852 -1.3140 -1.3694
A*x3-u
ans = 3×1
-0.9852 -1.3140 -1.3694
A*x4-u
ans = 3×1
-0.9852 -1.3140 -1.3694
norm(x1)
ans = 0.6522
norm(x2)
ans = 1.8993
norm(x3)
ans = 1.0368
norm(x4) % always the smallest
ans = 0.6314

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2023 年 8 月 24 日
Define a new variable y such that y = x+b.
Using this new variable simplifies your system to u = A*y.
Solve this simplified system for y using the backslash operator, y = A\u.
Substituing into that solution using the definition of y, we know x+b = A\u.
Subtract b from both sides to get x = (A\u)-b.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by