conv not giving the expected results. Why?
Afficher commentaires plus anciens
My mathematical model consists of a convolution. I tried the the MATLAB "conv" function and it does not seem to return the expected results. I also tried to implement the convolution using "integral" (using formula below) and it works.
Please advise on how to make "conv" work because it is much faster and I need to calculate the convolution quite a lot.
t = 0:5/60:100/6;
% Method 1: conv
y1 = 0.3*conv(helper(t)/0.6,exp(-0.3*t));
%% Method 2: integral
fun = @(tt,Tau) helper(tt)/0.6.*exp(-0.3*(Tau-tt));
for i=1:length(t)
y2(i) = 0.3*integral(@(ttt)fun(ttt,t(i)),0,t(i),'RelTol', 1e-4, 'AbsTol', 1e-6);
end
%% Plotting results
figure; plot(t,y1(1:length(t)),t,y2);
%% Helper function
function y = helper(t)
syms x(t_fun)
x(t_fun) = 5.7326*exp(-(t_fun-0.17046)^2/0.0063) ...
+ 0.9974*exp(-(t_fun-0.365)^2/0.0348) ...
+ 1.050 *exp(-0.1685*t_fun)/(1+exp(-38.078*(t_fun-0.483)));
y = double(x(t));
end

2 commentaires
Walter Roberson
le 14 Fév 2019
experiment with fliplr() the second parameter to conv.
Tara
le 15 Fév 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!