Error solving three equations in three unknowns

syms Tan Man Lan eqns vars L av bv cv
Tan =- b - 2 == 0;
Man = c + 1 == 0;
Lan = a + b - 3*c - 1 == 0;
eqns = [Tan Man Lan];
vars = [a b c];
L = solve(eqns,vars,'ReturnConditions',true)
av=L.a
bv=L.b
cv=L.c
Error is Empty sym: 0-by-1

5 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 10 月 25 日
Which release are you using. I get following result
syms Tan Man Lan eqns vars L av bv cv b c a
Tan =- b - 2 == 0;
Man = c + 1 == 0;
Lan = a + b - 3*c - 1 == 0;
eqns = [Tan Man Lan];
vars = [a b c];
L = solve(eqns,vars,'ReturnConditions',true)
Result
>>
av=L.a
bv=L.b
cv=L.c
av =
0
bv =
-2
cv =
-1
Mohamed Mahmoud
Mohamed Mahmoud 2020 年 10 月 25 日
The online version at https://matlab.mathworks.com/
Ameer Hamza
Ameer Hamza 2020 年 10 月 25 日
Even in MATLAB online, I am getting the correct result. Can you copy and paste the code in my answer and run it?
Mohamed Mahmoud
Mohamed Mahmoud 2020 年 10 月 25 日
The only diff I used
Tan=simplify((solve(S==(T^f),f)))==0
Man=simplify((solve(S1==(M^f),f)))==0
Lan=simplify((solve(S2==(L^f),f)))==0
eqns = [Tan Man Lan];
vars = [a b c];
L = solve(eqns,vars,'ReturnConditions',true);
Instead of writing the equations
The answer =
a: [0×1 sym]
b: [0×1 sym]
c: [0×1 sym]
parameters: [1×0 sym]
conditions: [0×1 sym]
John D'Errico
John D'Errico 2020 年 10 月 25 日
First, I would point out you seem to think you need to define all of your variables.
syms Tan Man Lan eqns vars L av bv cv
Yet ALL of those variables were defined later.
In fact, the only variables in your code that you never defined as symbolic, were the ones you really need to define! That is, a,b,c all need to be created as symbolic variables, you you never did that.

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

回答 (1 件)

John D'Errico
John D'Errico 2020 年 10 月 25 日

0 投票

syms a b c
Tan = -b - 2 == 0;
Man = c + 1 == 0;
Lan = a + b - 3*c - 1 == 0;
[av,bv,cv] = solve(Tan,Man,Lan,a,b,c)
av = 
0
bv = 
2
cv = 
1
This is a linear system, so there is no need even to specify the returnconditions.
As you can see, the only thing I needed to define as symbolic were the variables a,b,c. Everything else is then derived from them.

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

質問済み:

2020 年 10 月 25 日

回答済み:

2020 年 10 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by