Coding Circuits in Matlab
23 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
1 Kommentar
Antworten (2)
Prasanna Konyala
am 31 Mär. 2022
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 Kommentare
pratiksha
am 25 Sep. 2024
% 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 Kommentare
Siehe auch
Kategorien
Mehr zu Simscape Electrical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!