diff --git a/simulink/rc_circuit.slx b/simulink/rc_circuit.slx new file mode 100644 index 0000000..525e77d Binary files /dev/null and b/simulink/rc_circuit.slx differ diff --git a/simulink/rc_simulation_input.m b/simulink/rc_simulation_input.m new file mode 100644 index 0000000..bb790a7 --- /dev/null +++ b/simulink/rc_simulation_input.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