Академический Документы
Профессиональный Документы
Культура Документы
a)
For a linear equation as follows:
dy
=f ( x , y )
dx
dy
+ p ( x ) y=q ( x )
dx
General solution for the differential equation is as follows:
y=
u ( x ) q ( x ) dx+C
u(x)
Where
u ( x ) =e
p( x)dx
dv
=v +RI ( t )
dt
I ( t )=I 0
Given that
0
and
dv v R I 0
+ =
dt m m
Therefore;
q ( x )=
RI0
m
p ( x )=
1
m
y=v
We replace the variables to general solution
1 dx
u ( x ) =e
=e
x
m
e
v=
x
m
RI0
dx+C
m
e
x
m
x
m
R I 0 e +C
e
x
m
=R I 0 +C e
x
m
0
With given initial condition
0=R I 0 +C e
0
m
C=R I 0
As a result:
v (t )=R I 0 +C e
t
m
b)
We can represent differential equation as follows:
v
=v+R I 0
t
v ( k ) =R I 0 m
v ( k )v ( k 1 )
t
Or;
v ( k 1 )=R I 0 m
v ( k )v ( k1 )
t
t is small enough.
% initializations
R =1e3; % resistor 1k
I=2e-3; % I_0 current
Tm = 10e-3; % time constant
t_last= 100e-3; % 100ms simulation time
n=1001; % number of points to simulate larger it is less difference between analytic
and numeric solutions
t= 0:t_last/(n-1):t_last; % time vector
V
= R.*I-R.*I.*exp(-t./Tm);
Vp = zeros(1,n);
Vp(1)=0; % initial condition for voltage
dt =t_last/(n-1);
for k=2:n
Vp(k)=(R*I*dt+Tm*Vp(k-1))/(dt + Tm);% numeric representation of the differential
equation
%Vp(k)=t_last/(n-1)/Tm * (R*I-Vp(k-1))+Vp(k-1);
end
% plot the results
plot(t,V,t,Vp)
title('Numeric vs. Analytic Solutions')
xlabel('time')
ylabel('v')
legend('Analytic','Numeric')
grid
Figure 1: Analytic vs. Numeric Solution for the given differential equation
c)
Now we put a threshold to reset the voltage. We are able to see the spikes.
n_fire=0; % variable to store number of fires
theta = 1; % threshold value
for k=2:n
Vp(k)=(R*I*dt+Tm*Vp(k-1))/(dt + Tm); % numeric calculation
if Vp(k) >= theta
Vp(k)=0;
n_fire=n_fire+1; % number of fires passing the threshold
end
end
n_fire % number of fires
figure
plot(t,Vp)
title('Numeric Solution with threshold')
xlabel('time')
ylabel('v')
legend('Numeric')
grid
n_fire =
14
d)
If we put the calculation for the number of shoots in other loop and make
I0
e)
The only difference between part d is current sweep method. Instead of linearly sweeping, we randomly
picked the current values for a given mean and standard value. The result should be completely correlated.
In Figure 4 you can clearly see the result. While Gaussian distribution may select negative values, it is
possible to see that there is no firing below some current value.
% We take the results of the part d to show the correlation between random
% sweep and linear sweep
figure
plot(I_0,n_fires)