Вы находитесь на странице: 1из 6

1)

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

The given differential equation is:

dv
=v +RI ( t )
dt

I ( t )=I 0

Given that

0
and

and re ordering differential equation:

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

More prisizely we can approximate v(k) as follows:

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

Approximation does not matter if

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

Figure 2: Numeric solution for t= 100ms with threshold value of 1V

n_fire =
14
d)
If we put the calculation for the number of shoots in other loop and make

I0

variable, we can obtain the

effect of the current vs number of shoots.

n_cur= 9; % number of current value samples;


I_last=10e-3; %end value of the current
I_first= 2e-3; %start value of the current
I_0 = I_first:(I_last-I_first)/(n_cur-1):I_last; % Current array
n_fires=zeros(1,n_cur); %number of fires initialization for each current level
theta = 1; % threshold value
% we sweep the loop for each current value and extract the number of fires
% knowledge
for m=1:n_cur
Vp = zeros(1,n);
Vp(1)=0; % initial condition for voltage
% In order
for k=2:n
Vp(k)=(R*I_0(m)*dt+Tm*Vp(k-1))/(dt + Tm); % numeric calculation

if Vp(k) >= theta


Vp(k)=0;
n_fires(m)=n_fires(m)+1; % number of fires passing the threshold
end
end
end
figure
plot(I_0,n_fires)
title('Current vs Number of fires')
xlabel('Current I_0')
ylabel('Number of fires')
legend('Fires')
grid

Figure 3 Current Change vs. Number of Fire

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)

n_cur= 100; % number of current value samples;


I_mean=2e-3; %Mean value of the current
I_std= 4e-3; %Standard Deviation of the current
I_0 = I_mean + I_std.*randn(n_cur,1); % Current array
n_fires=zeros(1,n_cur); %number of fires initialization

for each current level

theta = 1; % threshold value


% we sweep the loop for each current value and extract the number of fires
% knowledge
for m=1:n_cur
Vp = zeros(1,n);
Vp(1)=0; % initial condition for voltage
% In order
for k=2:n
Vp(k)=(R*I_0(m)*dt+Tm*Vp(k-1))/(dt + Tm); % numeric calculation
if Vp(k) >= theta
Vp(k)=0;
n_fires(m)=n_fires(m)+1; % number of fires passing the threshold
end
end
end
hold on
scatter(I_0,n_fires, 'r') % scatter plot is more reasonable to show
title('Current vs Number of fires')
xlabel('Current I_0')
ylabel('Number of fires')
legend('Linear','Noise')
grid
hold off

Figure 4 Linear sweep of current vs. random picking of current value

Вам также может понравиться