how to plot multiple decaying exponentials in one plot.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Alex Mcaulley
le 20 Mai 2019
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 commentaires
Alex Mcaulley
le 20 Mai 2019
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)'))
Voir également
Catégories
En savoir plus sur Octave dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!