How to solve a system of equations for specific variables in terms of specific variables?

6 views (last 30 days)
let's say I have a system of n number of equations containing m number of variables, and I want to solve these equations for specific h number of variables in terms of specific u variables, given the fact that this operation is possible and we do not want to do it by hand, is it this possible?
for example I have 7 equations:
syms vi r1 is vc r2 ix vL v1 r2 r3 ir ii d1 d2
eq1 = -vi+3*is+vc+15*ix==0
eq2 = vL+4*v1-15*ix-vc==0
eq3 = -4*v1+6*ir==0
eq4 = is==ix+ii
eq5 = vi-v1==3*is
eq6 = ix==0.15*d1
eq7 = vL==0.375*d2
And I want to solve for 'd1' and 'd2' and 'ir' in terms of 'vc' and 'ii' and 'vi' GIVEN THE FACT THAT THIS OPERATION IS POSSIBLE, the output is:
d1 = (-0.37037)*vc + (-1.111111)*ii + (0.37037)*vc
d2 = (-1.33333)*vc + (20.000000)*ii + (-6.6666)*vc
ir = ( 0.11111)*vc + (-1.666666)*ii + (0.55555)*vc
Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 10 Aug 2021
syms vi r1 is vc r2 ix vL v1 r2 r3 ir ii d1 d2
eq1 = -vi+3*is+vc+15*ix==0
eq1 = 
eq2 = vL+4*v1-15*ix-vc==0
eq2 = 
eq3 = -4*v1+6*ir==0
eq3 = 
eq4 = is==ix+ii
eq4 = 
eq5 = vi-v1==3*is
eq5 = 
eq6 = ix==0.15*d1
eq6 = 
eq7 = vL==0.375*d2
eq7 = 
eqns = [eq1, eq2, eq3, eq4, eq5, eq6, eq7];
in_terms_of = [vc, vi, ii];
solve_for = setdiff(symvar(eqns), in_terms_of)
solve_for = 
sol = solve(eqns, solve_for)
sol = struct with fields:
d1: [1×1 sym] d2: [1×1 sym] ir: [1×1 sym] is: [1×1 sym] ix: [1×1 sym] v1: [1×1 sym] vL: [1×1 sym]
subs([solve_for].', sol)
ans = 
  4 Comments
Walter Roberson
Walter Roberson on 10 Aug 2021
Ndigit = 5;
syms vi r1 is vc r2 ix vL v1 r2 r3 ir ii d1 d2
eq1 = -vi+3*is+vc+15*ix==0
eq1 = 
eq2 = vL+4*v1-15*ix-vc==0
eq2 = 
eq3 = -4*v1+6*ir==0
eq3 = 
eq4 = is==ix+ii
eq4 = 
eq5 = vi-v1==3*is
eq5 = 
eq6 = ix==0.15*d1
eq6 = 
eq7 = vL==0.375*d2
eq7 = 
eqns = [eq1, eq2, eq3, eq4, eq5, eq6, eq7];
in_terms_of = [vc, vi, ii];
solve_for = setdiff(symvar(eqns), in_terms_of)
solve_for = 
sol = solve(eqns, solve_for)
sol = struct with fields:
d1: [1×1 sym] d2: [1×1 sym] ir: [1×1 sym] is: [1×1 sym] ix: [1×1 sym] v1: [1×1 sym] vL: [1×1 sym]
vpa(subs([solve_for].', sol), Ndigit)
ans = 

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!