Symbolic solution to a system of equations

1 vue (au cours des 30 derniers jours)
Aleem Andrew
Aleem Andrew le 1 Avr 2020
Commenté : Altug Bilge le 21 Nov 2020
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

Réponse acceptée

Ameer Hamza
Ameer Hamza le 1 Avr 2020
Modifié(e) : Ameer Hamza le 1 Avr 2020
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 commentaires
Ameer Hamza
Ameer Hamza le 11 Nov 2020
You can use subs() function
b_val = subs(sol.b, a, 5); % substitute a=5
Altug Bilge
Altug Bilge le 21 Nov 2020
Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by