Coding Circuits in Matlab
조회 수: 28 (최근 30일)
이전 댓글 표시
Hello everybody,
Im just getting started with Matlab. Can someone tell me how to write a code of a Resistor for example or a small electrical circuit consisting of two in series Resistors so the plot can be done in Simulink
thx in advance!
댓글 수: 0
답변 (2개)
Prasanna Konyala
2022년 3월 31일
Hi Ibrahim
From my understanding, you want to create a circuit with resistors in series.
To find the equivalent resistance you can use sum() (as the sum of resisters is the equivalent resistance in series connection).
If you want to design and implement and simulate the circuits, I suggest you try Simscape Electrical toolbox. It makes the process simpler than writing whole code in Matlab.
댓글 수: 0
pratiksha
2024년 9월 25일
% Define the symbolic variables
syms v1 v2 v3
% Given values
R1 = 1/3; % Resistance in Ohms
R2 = 1/2; % Resistance in Ohms
R3 = 1/6; % Resistance in Ohms
I1 = 4; % Current in Amps
I2 = 9; % Current in Amps
V_source = 5; % Voltage source value in Volts
% KCL equations using the supernode method
% Equation at node v1:
eq1 = (v1 - v2) / R1 == I1;
% Equation at node v3:
eq2 = (v3 - v2) / R3 == -I2;
% Supernode: Combine v2 and v3 with voltage source constraint
% Voltage constraint: v3 = v2 + V_source
eq3 = v3 == v2 + V_source;
% KCL at the supernode (combining v2 and v3):
% (v2 - v1) / R1 + v2 / R2 + (v2 - v3) / R3 = 0
eq4 = (v2 - v1) / R1 + v2 / R2 + (v2 - v3) / R3 == 0;
% Solve the equations
sol = solve([eq1, eq2, eq3, eq4], [v1, v2, v3]);
% Display the results
v1_sol = double(sol.v1);
v2_sol = double(sol.v2);
v3_sol = double(sol.v3);
fprintf('The solution for v1 is: %.2f V\n', v1_sol);
fprintf('The solution for v2 is: %.2f V\n', v2_sol);
fprintf('The solution for v3 is: %.2f V\n', v3_sol);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Simscape Electrical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!