2021年6月3日 星期四

電路分析

 電路分析

源自於https://bime-matlab.blogspot.com/2006/11/102-3.html

範例二:有一電路如下圖,試寫一MATLAB程式,求解各電阻器上之電流。


就克希荷夫(Kirchhoff)定律,可以在電路上任選定三個迴圈建立電阻與電壓降三項聯立方程式,及電流經A、B兩點分流時建立之二項聯立方程式,其結果如下:



整理此組聯立方程式,其變數I有五項,其方程式有五組,故應可得解。茲以矩陣[R][I]=[V]表示,利用左除法即為[I]=[R]\[V]。其各變數矩陣分別為:



     

程式內容:

function Current=findC(v1,v2,r)
% Prog using Kirchhoff's law to find the currents in a circuit.
% Inputs:
% v1, v2: Voltage of generators. volts
% r: the elements of resistances in Kohms. r=[r1 r2 r3 r4 r5]
% Outputs:
% current: currents through resistors [c1 c2 c3 c4 c5], in ma.
% Example: current=findC(100,50,[5 100 200 150 250])
V=[v1 0 v2 0 0]';
R=[r(1) 0 0 r(4) 0;0 r(2) 0 -r(4) r(5);0 0 -r(3) 0 r(5);...
   1 -1 0 -1 0;0 1 -1 0 -1];
Current=R\V;

%filename: findC.m
function Current=findC(v1,v2,r)
% Prog using Kirchhoff's law to find the currents in a circuit.
% Inputs:
%   v1, v2: Voltage of generators. volts
%   r: the elements of resistances in Kohms. r=[r1 r2 r3 r4 r5]
% Outputs:
%   current: currents through resistors [c1 c2 c3 c4 c5], in ma.
% Example: current=findC(100,50,[5 100 200 150 250])
V=[v1 0 v2 0 0]';
R=[r(1)  0      0     r(4)      0;
       0    r(2)   0    -r(4)   r(5);
       0     0    -r(3)  0      r(5);
       1    -1     0     -1          0;
       0     1    -1     0           -1];

Current=R\V;


>> findC(100,75,[80 120 250 150 200] )

ans =

    0.5082
    0.1126
   -0.1166
    0.3956
    0.2292

function Current1=findC(v1,v2,r)
% Prog using Kirchhoff's law to find the currents in a circuit.
% Inputs:
%   v1, v2: Voltage of generators. volts
%   r: the elements of resistances in Kohms. r=[r1 r2 r3 r4 r5]
% Outputs:
%   current: currents through resistors [c1 c2 c3 c4 c5], in ma.
% Example: current=findC(100,50,[5 100 200 150 250])
V=[v1 0 v2 0 0]';
R=[r(1) 0 0 r(4) 0;
    0 r(2) 0 -r(4) r(5);
    0 0 -r(3) 0 r(5);
    1 -1 0 -1 0;
    0 1 -1 0 -1];

%Current1=R\V;
Current1=inv(R)*V;

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...