Solving Symbolic equations by solve command

Hi I am trying to solve following system of symbolic equations but I do not know why I am not getting any result.
syms I1 I2 I3 I4 V1 V2 S
C1=3e-9;
C2=2e-9;
C3=C2;
L1=1e-3;
L2=L1;
K=1;
M=sqrt(L1*L2);
eq1=3*I1+(1/(S*C1))*I1+(1/S*C2)*(I1-I2)-V1;
eq2=(1/S*C2)*(I2-I1)+S*L1*I2+S*M*I3;
eq3=S*L2*I3+S*M*I2+(1/S*C3)*(I3-I4);
eq4=3*I4+(1/S*C3)*(I4-I3)-V2;
solve(eq1==0,eq2==0,eq3==0,eq4==0,V1)
I would like to find V1/V2 meaning I like to find V2 based on V1 or vice versa. Can anyone tell me how to do that the final answer should not be dependent on I1, I2, I3 and I4 only to S.
Thanks.

Réponses (3)

Star Strider
Star Strider le 19 Juin 2015

2 votes

I’m not quite sure what network you’re analysing. One problem is that while your first equation is correct in terms of the capacitive reactances 1/(s*C), the others are incorrect. Also, I don’t see any equations relating ‘I1’ or ‘I2’ in terms of ‘I3’ or ‘I4’. The systems seem to be unconnected.
It seems you are using node-voltage analysis. I would solve each branch as a current as a function of the voltages through it (KVL), then develop separate equations for the currents in terms of KCL, just as you would if you were calculating them by hand. Set your equations up for your branch currents (not difficult for systems of small equations), then let MATLAB solve your system from them.

9 commentaires

chess
chess le 19 Juin 2015
I do not know what you mean by saying my other equations are not correct they are just mesh equations I have 4 equation and 4 unknown that Matlab should be able to solve it easily. Equation 1 is based on I1 and I2 and equation 2 is based on I1, I2 and I3 equation 3 is based on I2,I3 and I4 so they are related to each other.
Walter Roberson
Walter Roberson le 19 Juin 2015
You have 4 equations and 7 unknowns.
I would have to see your circuit to see if I can figure out what the problem is.
Even when I correct your code so that the capacitive reactances are correctly characterised:
eq1=3*I1+(1/(S*C1))*I1+(1/(S*C2))*(I1-I2)-V1;
eq2=(1/(S*C2))*(I2-I1)+S*L1*I2+S*M*I3;
eq3=S*L2*I3+S*M*I2+(1/(S*C3))*(I3-I4);
eq4=3*I4+(1/(S*C3))*(I4-I3)-V2;
V1 = solve(eq1==0,eq2==0,eq3==0,eq4==0,V1)
the ‘V1’ result is empty. If I change it to solve for ‘V2’, the result is the same.
Walter Roberson
Walter Roberson le 19 Juin 2015
You need to solve() for as many variables as you have equations, with the exception being that if the number of variables present in the equation as determined by symvar() matches the number of equations then you do not need to specify their names.
chess
chess le 20 Juin 2015
Dear Walter and Star I attach my circuit the left side is V1 and right side is V2. Starting from left loop I called current in first loop I1 then I2 and ...
chess
chess le 20 Juin 2015
I would like to know what would be the next set of equations?
Star Strider
Star Strider le 20 Juin 2015
Modifié(e) : Walter Roberson le 20 Juin 2015
The problems I had with my solution was that MATLAB didn't want to automatically substitute v1 (transformer primary voltage) in the equations for the currents in the transformer secondary circuit. I ended up having to do a specific subs call to do it.
In my code:
C1 = 6 pF
C2 = 6 nF
R1 = 3 Ohms
L1 = 1 mH
L2 = 1 mH
C2 = 6 nF
R2 = 3 Ohms
M = 1 mH (sqrt(L1*L2))
This is how I solved it (using the node-voltage approach). The transformer equation is the expression for v2, with i3 the transformer primary current, i4 the transformer secondary current, v1 the transformer primary voltage, and v2 the transformer secondary voltage. I won't diagram it, since the current definitions are likely obvious by the way they are defined:
syms C1 C2 C3 L1 L2 R1 R2 M i1 i2 i3 i4 i5 i6 Vin Vout v1 v2 s
i1 = (Vin - v1)/(R1 + 1/(s*C1)); % Input Side Branch Currents And Node Voltages
i2 = v1/(1/(s*C2));
i3 = v1/(s*L1);
Eq1 = i1 == i2 + i3; % Input Side KCL
v1 = solve(Eq1, v1); % Solve for v1
v2 = M*s*i3; % Output Side Branch Currents And Node Voltages
i4 = v2/(s*L2);
i5 = v2/(1/(s*C3));
i6 = (v2-Vout)/R2;
Eq2 = i6 == -(i4 + i5); % Output Side KCL
Vout = solve(Eq2, Vout); % Solve for Vout
Vout = subs(Vout, v1); % Substitute v1 For v1
TFs = simplify(collect(Vout/Vin, s)); % Symbolic Transfer Function
Tfn = vpa(subs(TFs, {C1, C2, C3, L1, L2, R1, R2, M}, {6E-12, 6E-9, 6E-9, 1E-3, 1E-3, 3, 3, 1E-3}), 5)
I will leave you to prettyprint TFs (the completely symbolic transfer function) if you like. The transfer function with the component values applied is:
Tfn =
(6.0e-12*s*(1.8e-11*s^2 + 0.001*s + 3.0))/(1.08e-22*s^3 + 6.006e-12*s^2 + 1.8e-11*s + 1.0)
This looks correct to me. I checked it several times and can't detect any errors (the reason for the delay in my Comment here). It was actually fun to do a circuit analysis problem again, especially with the transformer! (I had to go back to the books for the transformer model.)
If you need to invert this to get the time-domain response, and if you have R2015a, use the partfrac function.
chess
chess le 21 Juin 2015
Thanks Dear Stars but some of your equations are not correct since we have magnetic coupled coil therefore current in one coil affect current in the other therefore for inductor in left we have one term corresponding to L1 and one term to M meaning voltage across the inductor is (SL1I2+SMI3) where I3 is current passing through another inductor. I believe it is easier to write KVL equations
Star Strider
Star Strider le 21 Juin 2015
My analysis corresponds to the discussion on transformer modeling in the textbook I referred to, and my experience in circuit analysis and synthesis. The current through the primary, ‘i3’, produces the current through the secondary, ‘i4’. The primary and secondary are modeled as ‘L1’ and L2 in each circuit, and the induced current by ‘M’ in the expression for ‘v2’.
For what it’s worth, my analysis of your circuit actually works and provides a solution to the transfer function. In node-voltage analysis, KCL applies to the individual branches and to the net currents, and KVL to the nodes.
If your professor believes my analysis is incorrect, ask your professor to correct it, then post the correction here. I am always willing to learn if it turns out my analysis or code are in error.

Connectez-vous pour commenter.

Walter Roberson
Walter Roberson le 19 Juin 2015
Modifié(e) : Walter Roberson le 19 Juin 2015

0 votes

You have 4 equations in 7 unknowns. You can eliminate I1, I2, I3, I4 by solving for those, but the result is going to be in V1, V2 and S. That does not give you enough information to relate V1 to V2 in terms of S. In order to do that you need two more equations: if you solve 6 equations in 7 unknowns then the results will be in terms of the 7th variable.
Note: when you have a set of equations, you need to solve them for as many variables as there are equations. You might not care what the values are of the other variables but you must supply their names to solve() so it knows what to isolate.

3 commentaires

chess
chess le 19 Juin 2015
Thanks. But that's all can be written by mesh equations. Lets say I know V1 but V2 is my output there is no way I know what V2 is. Do you have any suggestion to find the transfer function by Matlab?
If I use the revised equations that Star Strider provided, you can get down to
V1/V2 = V1 * (9 * S^3 + 1750000000 * S^2 + 2250000000000 * S + 250000000000000000000) / (27 * I4 * S^3 + (7500000000 * I4 + 750000000 * V1) * S^2 + 250006750000000000 * I4 * S + 750000000000000000000*I4)
therefore you need at least one more equation, preferably involving I4, in order to fully resolve the system.
Walter Roberson
Walter Roberson le 19 Juin 2015
Solve eq1 for I1. Substitute that value of I1 into the rest of the equations. Solve the first of the substituted equations for I2. Substitute that value of I2 into the rest of the substituted equations. Solve the third (now twice substituted) equations for I3. Substitute that into the last. Now solve the last for V2. You still have not resolved I4 so it will appear. You now have V1 (a given) and V2 in terms of V1 and I4 and S, so you can take V1/V2 to get an expression in V1, I4, and S. But to get it down to being in V1 and S you need one more equation.

Connectez-vous pour commenter.

% Variables KVL1 KVL2 eqn1 eqn2 e0
% for symbolic declaration R1 R2 C1 C2 e0 e1(t) e2(t) De1(t) De2(t)
format compact
De1 = diff(e1)
De2 = diff(e2)
% Write the KCL equation for node voltage, e1.
% Use Ohm's law and the current through a capacitor to rewrite the KCL equation for node voltage, e1, in terms of e0, e1, e2, R1, R2, and C1.
KVL1 =
% Write the KCL equation for the node voltage, e2.
% Use Ohm's law and the current through a capacitor to rewrite the KCL equation for node voltage, e2, in terms of e1, e2, R2, and C2.
KVL2 =
% Solve equation for e0.
eqn1 =
% Solve equation for e1.
eqn2 =
% Use algebra to substitute one equation into the other and solve for the dynamic equation.
eqn1 = subs(eqn1,lhs(eqn2),rhs(eqn2))
e0 = rhs(eqn1)
% Simplify equation to solve for the dynamic equation.
e0 =
% Show your equation e0 as human readable text

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by