how to plot multiple decaying exponentials in one plot.
3 ビュー (過去 30 日間)
古いコメントを表示
I would like to plot multiple decaying exponentials with different parameters (time, decay, peak). I was able to create this code to plot only one decaying exp. at t=20
clc,clear,close all
time = [20];
peak = [5];
decay = [2];
t = 1:100;
X = zeros(length(t),1);
for j = 1:length(t)
for i = 1:length(time)
if t(j) > time(i)
X(j) = peak(i)*exp(-(t(j)-time(i))/decay(i));
end
end
end
plot(t,X)
now say I have arrays of parameters like this
time = [20 50 80];
peak = [5 3 2];
decay = [2 4 6];
and I want to plot three consecutive decaying exponentials using each element of these parameters. Any thoughts on how to go about it?
Thanks,
0 件のコメント
回答 (1 件)
Alex Mcaulley
2019 年 5 月 20 日
Here two options:
time = [20 50 80];
peak = [5 3 2];
decay = [2 4 6];
% Symbolic toolbox needed
figure
syms t
X = peak.*exp(-(t-time)./decay);
fplot(X,[1,100])
%Anonymous functions
figure
t = 1:100;
X = @(t) peak.*exp(-(t-time)./decay);
plot(t,cell2mat(arrayfun(X,1:100,'UniformOutput',false)'))
2 件のコメント
Alex Mcaulley
2019 年 5 月 20 日
Why do you want to do it with loops? It is inefficient, but you can do it easily adding another loop (from 1 to size(time)).
By the way, following my previous code, to shift the exponentials to the desired position:
time = [20 50 80];
peak = [5 3 2];
decay = [2 4 6];
t = cell2mat(arrayfun(@linspace,time,100*ones(size(time)),'UniformOutput',false)');
X = @(t) peak.*exp(-(t)./decay);
plot(t',cell2mat(arrayfun(X,linspace(0,100),'UniformOutput',false)'))
参考
カテゴリ
Help Center および File Exchange で Octave についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!