difficulty solving simulataneous equations

조회 수: 2 (최근 30일)
Brian Tremaine
Brian Tremaine 2024년 1월 20일
댓글: Walter Roberson 2024년 1월 20일
I am new to symbolic editor and am having difficulty getting a non-empty solution. As a test I have a problem I can solve by hand yet can't get the editor to generate a non-empty answer,
By hand, my answer is iaD = (1/(La+Lb) ( Vb - Va + Rb*ib - Ra*ia ). I arrive at this answer by 'back substituing' the 2nd two eqations into the first equation. My real problem is a larger network but this problem displays my basic problem.
% rl2.m
% solve simple R, L equations in symbolic editor
% two phases in series
clear all
% variables
% Va, Vb, Ra, Rb, La and Lb are "fixed" inputs
% variable("unknowns") are ia, ib, iaD and ibD
clear syms Ra Rb La Lb Va Vb iaD ibD ia ib
syms Ra Rb La Lb Va Vb iaD ibD ia ib
% check
syms
% equations
clear eqns
eqns = [Lb*ibD - La*iaD + Rb*ib - Ra*ia + Vb == Va, ia == -ib,iaD == -ibD]
% solve
S = solve(eqns, ia, ib)

채택된 답변

John D'Errico
John D'Errico 2024년 1월 20일
You have 3 equations, and you calim to have 4 unknowns. However, you only tell solve that you want to solve for TWO unknowns, ia and ib.
syms Ra Rb La Lb Va Vb iaD ibD ia ib
% equations
eqns = [Lb*ibD - La*iaD + Rb*ib - Ra*ia + Vb == Va, ia == -ib,iaD == -ibD]
eqns = 
Solve will require it has the same number of unknowns as equations, and that the equations are independent. So you could do this:
solve(Lb*ibD - La*iaD + Rb*ib - Ra*ia + Vb == Va, ia == -ib,[ia,ib])
ans = struct with fields:
ia: -(Va - Vb + La*iaD - Lb*ibD)/(Ra + Rb) ib: (Va - Vb + La*iaD - Lb*ibD)/(Ra + Rb)
Again Count the equations. Count the unknowns. Are they the same? If not, then you have a problem.
  댓글 수: 2
Brian Tremaine
Brian Tremaine 2024년 1월 20일
Thank-you, this does what I want but not quite. I want to solve for iaD and ibD in terms of the independent variables ia and ib. The other symbols are all 'constants'.
In your answer for the solve command what does adding the brackets do to [ia, ib] ?
I modified my program per your input tried the followiing and got the expected answer ---- Thank-you
% rl2.m
% solve simple R, L equations in symbolic editor
% two phases in series
clear all
% variables
% Va, Vb, Ra, Rb, La and Lb are constants
% "unknowns" are iaD, ibD
% independent variables are ia and ib
clear syms Ra Rb La Lb Va Vb iaD ibD ia ib
syms Ra Rb La Lb Va Vb iaD ibD ia ib
% equations
clear eqns
eqns = [Lb*ibD - La*iaD + Rb*ib - Ra*ia + Vb == Va, iaD == -ibD]
eqns = 
% solve
S = solve(eqns, [iaD, ibD])
S = struct with fields:
iaD: -(Va - Vb + Ra*ia - Rb*ib)/(La + Lb) ibD: (Va - Vb + Ra*ia - Rb*ib)/(La + Lb)
Walter Roberson
Walter Roberson 2024년 1월 20일
clear syms Ra Rb La Lb Va Vb iaD ibD ia ib
Note that clears variables "syms" "Ra" "Rb" and so on -- the "syms" is treated as a variable name.
Note that clearing variables does not reset any symbolic assumptions on the variables.
syms Ra Rb La Lb Va Vb iaD ibD ia ib
That has the effect of effectively clearing any of those names (that already exist) and establishing new symbolic variables with the given names, and resetting any symbolic assumptions on those variables.
... effectively the "clear" statement is redundent (and misleading)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2024년 1월 20일
syms Ra Rb La Lb Va Vb iaD ibD ia ib
eqns = [Lb*ibD - La*iaD + Rb*ib - Ra*ia + Vb == Va, iaD == -ibD]
eqns = 
S = solve(eqns, [iaD,ibD])
S = struct with fields:
iaD: -(Va - Vb + Ra*ia - Rb*ib)/(La + Lb) ibD: (Va - Vb + Ra*ia - Rb*ib)/(La + Lb)

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by