Solving linear systems with a function

have a circuit that has 5 resistors and 1 applied voltage. Kirchoff's voltage law was applied to 3 loops that gave me 3 linear equations.
v - R2*i2 - R4*i4 = 0
-R2*i2 + R1*i1 + R3*i3 = 0
-R4*i4 - R3*i3 + R5*i5 = 0
from that law Is known:
6 = i1 + i2
4 = i2 + i3
1 = i3 + i5
6 = i4 + i5
using this I made a function that just finds the current in i4 with a given set of values.
values to use: R1 = 1, R2 = 4, R3 = 5, R4 = 1, R5 = 5, v = 100, measured in ohms and volts
function I made to solve this.
function [i4] = I(R1, R2, R3, R4, R5, v)
format shortg;
A = [0 -R2 0 -R4 0 0
R1 -R2 R3 0 0 0
0 0 -R3 -R4 R5 0];
b = [-v; 0; 0;];
x = A\b;
i2 = x(2,:);
i3 = x(3,:);
i4 = i2 + i3;
return
This system is overdetermined, using gauss-jordan in matlab I got x, which give all 6 currents values. With this function i4 = 45, the answer is i4 = 27.638. What do I have wrong in my function or need to add?

 採用された回答

Star Strider
Star Strider 2016 年 7 月 10 日

1 投票

I get the same result you do, coding your matrices myself. I would have to see your circuit. (I usually use the node voltage approach, since it’s easier for me.)

14 件のコメント

Luke Radcliff
Luke Radcliff 2016 年 7 月 10 日
I attached the circuit for you
Luke Radcliff
Luke Radcliff 2016 年 7 月 10 日
Thanks for trying, I have solved it.
Star Strider
Star Strider 2016 年 7 月 10 日
I apologise for the delay. It was too late last night for me to work on this, and I got a late start today.
My nodal analysis labeled the node defined by the connection of ‘R2’, ‘R3’, and ‘R4’ as ‘VA’, and the node defined by the connection of ‘R1’, ‘R3’, and ‘R5’ as ‘VB’ (the apex of the triangle). I defined ‘IT’ as the total current supplied by the source. I did all the calculations with the Symbolic Math Toolbox, largely because I’m lazy today. The currents correspond to those in the circuit schematic diagram you supplied. The nodes were not labeled, so I created my own labels.
The Nodal Equations:
syms R1 R2 R3 R4 R5 V VA VB IT
R1 = 1; R2 = 4; R3 = 5; R4 = 1; R5 = 5; V = 100;
I1 = (V-VB)/R1;
I2 = (V-VA)/R2;
I3 = (VB-VA)/R3;
I4 = VA/R4;
I5 = VB/R5;
Eq1 = I1+I2 == IT;
Eq2 = -I1+(I5+I3) == 0;
Eq3 = I2+I3-I4 == 0;
S = solve(Eq1, Eq2, Eq3);
V_A = vpa(S.VA, 7)
V_B = vpa(S.VB, 7)
I_T = vpa(S.IT, 7)
The Voltages and Total Current:
V_A =
27.63819
V_B =
75.37688
I_T =
42.71357
That calculates to a total network resistance of 2.3412 Ohms (seems reasonable), in the event you want to do a Norton or Thévenin equivalent circuit of it. With the solved voltages, the currents are straightforward calculations.
I haven’t done circuit analysis in at least a few months (since I don’t usually need to), so thanks for the opportunity to come back up to speed on it! It was fun!
Marc
Marc 2016 年 7 月 11 日
Looks good to me... I wish I could give Star Strider some gold for the effort after Luke got a bit frisky.... Much better man than I would have been.
Star Strider
Star Strider 2016 年 7 月 11 日
@Marc —
Thank you!
Luke Radcliff
Luke Radcliff 2016 年 7 月 13 日
編集済み: Luke Radcliff 2016 年 7 月 13 日
A bit frisky.... wait what? haha looks good star thanks for your help.
Star Strider
Star Strider 2016 年 7 月 13 日
My pleasure!
Hayriye Esin Basaran
Hayriye Esin Basaran 2020 年 12 月 11 日
編集済み: Hayriye Esin Basaran 2020 年 12 月 11 日
how can i do this using first method. i want to calculate currents
Star Strider
Star Strider 2020 年 12 月 11 日
Hayriye Esin Basaran —
Solve for the voltages, then plug those back into the current equations to solve for the currents. That’s how I always do it.
Hayriye Esin Basaran
Hayriye Esin Basaran 2020 年 12 月 15 日
function [i,i1,i2,i3,i4,i5,i6]=kirchoff(R1,R2,R3,R4,R5,V)
A=[0 -R2 0 -R4 0 0; R1 -R2 R3 0 0 0; 0 0 -R3 -R4 R5 0];
B=[-V;0;0];
i=pinv(A)*B;
i1 = i(3,1)+i(5,1);
i2 = i(4,1)-i(3,1);
i3 = i(1,1)-i(5,1);
i4 = i(2,1)+i(3,1);
i5 = i(1,1)-i(3,1);
i6 = i(4,1)+i(5,1);
Hayriye Esin Basaran
Hayriye Esin Basaran 2020 年 12 月 15 日
i do like that but i dont understand what is the wrong. i calculate the currents but after i1,i2... the result is not same. i am confused.
Star Strider
Star Strider 2020 年 12 月 15 日
Hayriye Esin Basaran — I cannot follow what you are doing.
Hayriye Esin Basaran
Hayriye Esin Basaran 2020 年 12 月 16 日
編集済み: Hayriye Esin Basaran 2020 年 12 月 16 日
nction [i,i1,i2,i3,i4,i5,i6]=kirchoff(R1,R2,R3,R4,R5,V)
A=[0 -R2 0 -R4 0 0; R1 -R2 R3 0 0 0; 0 0 -R3 -R4 R5 0];
B=[-V;0;0];
i=pinv(A)*B;
i1 = i(3,1)+i(5,1);
i2 = i(4,1)-i(3,1);
i3 = i(1,1)-i(5,1);
i4 = i(2,1)+i(3,1);
i5 = i(1,1)-i(3,1);
i6 = i(4,1)+i(5,1);
Command Window:
>> [i,i1,i2,i3,i4,i5,i6]=kirchoff(1,5,2,10,5,100)
Hayriye Esin Basaran
Hayriye Esin Basaran 2020 年 12 月 16 日
I want to get the same result with the current results I found by typing i = pinv (A) * B and the new current equations I added below.
i1 = i(3,1)+i(5,1);
i2 = i(4,1)-i(3,1);
i3 = i(1,1)-i(5,1);
i4 = i(2,1)+i(3,1);
i5 = i(1,1)-i(3,1);
i6 = i(4,1)+i(5,1);

サインインしてコメントする。

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2016 年 7 月 10 日
編集済み: Andrei Bobrov 2016 年 7 月 11 日

0 投票

R1 = 1, R2 = 4, R3 = 5, R4 = 1, R5 = 5, v = 100
R = [R1;R2;R3;R4;R5;0];
E = [zeros(5,1);v];
J = zeros(6,1);
D = [[1 -1 1 0 0 0];[0 0 -1 -1 1 0];[0 1 0 1 0 1]];
RR = D*diag(R)*D';
EE = D*(E - J.*R);
Ik = RR\EE;
I = D'*Ik + J;

1 件のコメント

Akash Chauhan
Akash Chauhan 2021 年 1 月 18 日
can u please explain this to me ?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by