simulator.m (467B)
1 #!/usr/bin/env octave 2 3 R=200; 4 C=1e-6; 5 dt=1e-5; 6 vh=3.3; 7 vl=0; 8 vhh=2.8; 9 vhl=1.8; 10 11 te=0.1; 12 13 sincoeff=pi/te; 14 15 Rf=@(t) 10e3 - sin(sincoeff*t)*(10e3-1e3); 16 17 tv=0:dt:te; 18 u=zeros(length(tv),1); 19 uiv=zeros(length(tv),1); 20 rv=ones(length(tv),1)*Rf(0); 21 ui=vh; 22 con=dt/(R*C); 23 for i=1:length(tv)-1 24 if u(i) > vhh 25 ui=vl; 26 end 27 if u(i) < vhl 28 ui=vh; 29 end 30 uiv(i)=ui; 31 R=Rf(tv(i)); 32 rv(i)=R; 33 u(i+1) = dt/(R*C)*(ui-u(i))+u(i); 34 end 35 36 dlmwrite("simulation.csv", [tv', u, uiv, rv], "\t")