physical exponential decay and growth processes

조회 수: 7 (최근 30일)
Felix
Felix 2021년 11월 22일
댓글: Image Analyst 2021년 11월 22일
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

채택된 답변

Walter Roberson
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')

추가 답변 (1개)

Image Analyst
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
Felix
Felix 2021년 11월 22일
thanks, this is beautiful! it's the same curve I worked manually
Image Analyst
Image Analyst 2021년 11월 22일
You're welcome. If it works, then could you click the "Accept this answer" link? Thanks in advance.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by