RC circuit
This commit is contained in:
commit
b09ed303e7
|
|
@ -0,0 +1,3 @@
|
||||||
|
**/slprj/
|
||||||
|
*.slxc
|
||||||
|
*.asv
|
||||||
Binary file not shown.
|
|
@ -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);
|
||||||
Loading…
Reference in New Issue