physical exponential decay and growth processes
10 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2021-11-22
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')
0 个评论
更多回答(1 个)
Image Analyst
2021-11-22
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 个评论
Image Analyst
2021-11-22
You're welcome. If it works, then could you click the "Accept this answer" link? Thanks in advance.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!