RC circuit

This commit is contained in:
Enrico Lumetti 2021-05-06 23:02:37 +02:00
commit b09ed303e7
3 changed files with 39 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
**/slprj/
*.slxc
*.asv

BIN
RC circuit/rc_circuit.slx Normal file

Binary file not shown.

36
RC circuit/run_circuit.m Normal file
View File

@ -0,0 +1,36 @@
clear;
model_name = "rc_circuit";
load_system(model_name);
stopTime = 5;
V_in = 10;
R = 1e3;
C = 1e-4;
freq = 1;
timestep = 0.01;
ts = (0:timestep:stopTime)';
vs = sin(2*pi*freq * ts);
sim_in = Simulink.SimulationInput(model_name);
sim_in = sim_in.setModelParameter("R", num2str(R));
sim_in = sim_in.setModelParameter("C", num2str(C));
sim_in = sim_in.setModelParameter("StopTime", num2str(stopTime));
% note: to be compatible with port size, ts must be a column vector
sim_in = sim_in.setExternalInput([ts, vs]);
% simulate
res = sim(sim_in);
figure;
subplot(2, 1, 1);
plot(ts, vs);
xlabel('Time (seconds)');
ylabel('V_{in} (Volt)');
subplot(2, 1, 2);
plot(res.yout{1}.Values);
close_system(model_name);