Azzera filtri
Azzera filtri

Symbolic solution to a system of equations

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Ameer Hamza
Ameer Hamza il 1 Apr 2020
Modificato: Ameer Hamza il 1 Apr 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 Commenti
Ameer Hamza
Ameer Hamza il 11 Nov 2020
You can use subs() function
b_val = subs(sol.b, a, 5); % substitute a=5

Accedi per commentare.

Più risposte (1)

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

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by