Effacer les filtres
Effacer les filtres

Solving linear systems with a function

8 vues (au cours des 30 derniers jours)
Luke Radcliff
Luke Radcliff le 10 Juil 2016
Commenté : Akash Chauhan le 18 Jan 2021
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?

Réponse acceptée

Star Strider
Star Strider le 10 Juil 2016
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 commentaires
Hayriye Esin Basaran
Hayriye Esin Basaran le 16 Déc 2020
Modifié(e) : Hayriye Esin Basaran le 16 Déc 2020
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 le 16 Déc 2020
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);

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 10 Juil 2016
Modifié(e) : Andrei Bobrov le 11 Juil 2016
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 commentaire
Akash Chauhan
Akash Chauhan le 18 Jan 2021
can u please explain this to me ?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by