Prev: How to store variables?
Next: Baffling colon behaviour
From: Courtney Williams on 29 Mar 2010 19:50 Hi, I have created a function file and a script file that charges an RC Circuit and now I have to modify the program to show the RC circuit charging and discharging by making for the pulse is long enough to reach vfinal = 5.0 mV and possibly changing the stimulation time but I am having trouble doing this. My code for charging an RC circuit is below: Script file function b = b(t,vout) Cm = 1.0e-6; Rm = 1.5e6; Iin = 3.33e-6; b = ((Rm*Iin) - vout)/(Rm*Cm); end Function file % tau = 1.5 ms % time step (change in time) = 1.5 ms/5 = 0.3 ms % I chose this value beacuse it takes 5 times before the time constant % reaches steady state. % tmax = 10RC = 10(1.5 ms) = 15 ms % Iin = Vfin/Rm = 3.33e-6 mA Cm = 1.0e-6; Rm = 1.5e6; Iin = 3.33e-6; dur = 7.5; tmax = 15; dt = 0.3; t = 0:dt:tmax; vout(1) = 0; for i=1:length(t)-1 if 0 <= t(i) <= dur stimulus = Iin; else stimulus = 0; end vout (i+1) = vout(i)+ dt*b(t(i),vout(i)); end plot(t,vout)
|
Pages: 1 Prev: How to store variables? Next: Baffling colon behaviour |