physical exponential decay and growth processes

8 visualizzazioni (ultimi 30 giorni)
Hi All,
I am trying to model the following exponential function for signal decay according to the equation N = N0*e^-1/tau where:
N = signal can vary from 0 to 1;
t = time from 0 to 10 (in seconds);
tau: the time required for N to decrease in size by a factor of 1/e when t = 1.
For my purpose, I hold N0 = 1 and T =1 since I am trying to model different curves at tau = 0.5, tau = 1, tau = 2, etc. to represent how the exponential decay changes as result of changes in tau.
I have tried the following code but I get an exp growth curve instead, which I don't understand why since the exp is negative. Of course, if I remove the negative sign, I get a decay curve, which is not the intended purpose of the formula:
N = linspace(0,1,11);
t = linspace(0,10,11);
tau = linspace(0.5,10,11);
N0= 1;
N = N0*exp(-1./tau);
plot(t,N,'-')
thanks for your help

Risposta accettata

Walter Roberson
Walter Roberson il 22 Nov 2021
You have two changing variables: t and tau. And you are calculating N using changes in tau, but plotting over changes in t.
If you want both t and tau to be changing, then your code needs to use a plot with two independent variables and one dependent variable, such as a surf() -- and your formula needs to include t, even if only implicitly. For example if you were to rewrite N0 to be something that depends on time:
num_t = 11;
num_tau = 12;
t = linspace(0, 10, num_t);
N0 = t ./ 10; %signal is straight line
tau = linspace(0.5, 10, num_tau);
N = N0 .* exp(-1./tau.'); %tau is vertical, time is horizontal
surf(t, tau, N, 'edgecolor', 'none');
xlabel('time'); ylabel('tau'); zlabel('N')

Più risposte (1)

Image Analyst
Image Analyst il 22 Nov 2021
You need to put t into the equation for N, and just plot one curve for each tau. You were varying N with tau and then plotting vs. t, which is wrong:
N = linspace(0,1,11);
t = linspace(0,10,11);
tau = linspace(0.5,10,11);
N0= 1;
for k = 1 : length(tau)
N = N0*exp(-t ./ tau(k));
plot(t,N,'-')
hold on;
end
grid on;
  2 Commenti
Felix
Felix il 22 Nov 2021
thanks, this is beautiful! it's the same curve I worked manually
Image Analyst
Image Analyst il 22 Nov 2021
You're welcome. If it works, then could you click the "Accept this answer" link? Thanks in advance.

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by