commit b09ed303e7219c20870644c843abafa7b2e49370 Author: Enrico Lumetti Date: Thu May 6 23:02:37 2021 +0200 RC circuit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c0dbdb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +**/slprj/ +*.slxc +*.asv diff --git a/RC circuit/rc_circuit.slx b/RC circuit/rc_circuit.slx new file mode 100644 index 0000000..525e77d Binary files /dev/null and b/RC circuit/rc_circuit.slx differ diff --git a/RC circuit/run_circuit.m b/RC circuit/run_circuit.m new file mode 100644 index 0000000..bb790a7 --- /dev/null +++ b/RC circuit/run_circuit.m @@ -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); \ No newline at end of file