Solve a system of linear equations in matrix form

조회 수: 1 (최근 30일)
Saeed Ahmadzadeh Mahboobi
Saeed Ahmadzadeh Mahboobi 2019년 12월 9일
편집: Saeed Ahmadzadeh Mahboobi 2019년 12월 9일
I want to solve the following system of linear equations.
u1 - u2 = 11.1680
u1 - u4 = 22.8197
u3 - u5 = 8.7093
u5 - u1 = 0.3391
u5 - u2 = 11.4875
So I want to create 2 matrices and set them equal to each other and simply solve them in matrix form.
So here's what I've done:
u=sym('u%d',[5,1]); % u=[u1 ; u2 ; u3 ; u4 ; u5]
Left = [u1-u2 ; u1-u4 ; u3-u5 ; u5-u1 ; u5-u2]; % Left side of the above equation system
Right = [11.1680 ; 22.8197 ; 8.7093 ; 0.3391 ; 11.4875]; % Right side of the above equation system
solve(Left==Right)
but what MATLAB returns is this:
ans =
struct with fields:
u1: [0×1 sym]
u2: [0×1 sym]
u3: [0×1 sym]
u4: [0×1 sym]
u5: [0×1 sym]
What is the problem?
Has anyone any idea how I can solve these equations in matrix form?

채택된 답변

Star Strider
Star Strider 2019년 12월 9일
The problem is that the system is sparse, so you need to use sparse functions with it.
Try this:
Left = [1 -1 0 0 0; 1 0 0 -1 0; 0 0 1 0 -1; -1 0 0 0 1; 0 -1 0 0 1];
u = lsqr(Left,Right)
producing:
u =
-0.0644
-0.3004
1.9476
-2.1104
0.5276

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by