Symbolic solution to a system of equations

2 次查看(过去 30 天)
Can Matlab solve a system of equations like a+b=c, b=2c symbolically for b and c? The output should be c=-a, b=-2a

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-1
编辑:Ameer Hamza 2020-4-1
In MATLAB you solve it like this using symbolic variables and solve function()
syms a b c
eq1 = a+b==c;
eq2 = b==2*c;
sol = solve([eq1 eq2])
Result:
>> sol.b
ans =
-2*a
>> sol.c
ans =
-a
  5 个评论
Ameer Hamza
Ameer Hamza 2020-11-11
You can use subs() function
b_val = subs(sol.b, a, 5); % substitute a=5

请先登录,再进行评论。

更多回答(1 个)

David Hill
David Hill 2020-4-1
syms a;
[1,-1;2,-1]\[a;0];

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by