arrayfun applied to integral

조회 수: 7 (최근 30일)
Olivier
Olivier 2022년 12월 23일
댓글: Olivier 2023년 1월 13일
Hello!
I would like to vectorialize a subroutine calculating an integral.
The main entry is an array that includes, in row, parameters of the function to integrate and the boundaries for the integration.
It works fine when called into a for loop, but I failed to vectorize it using arrayfun. Below is the code.
Any help to speed up this code would be most the welcome!!!
Many thanks
Olivier
function hV=change_potential_by_history_NoDOV3(t,t0,tpeak,w,past,slops,extrems)
%Matlab2022
parfor i=1:length(t)
int(i)=integrate_PSP(t(i),t0(i),tpeak(i),w(i),past(i));
end
%I WANT SOMETHING LIKE
%int=arrayfun(@integrate_PSP, t,t0,tpeak,w,past)
%
hV=sum
end
function int=integrate_PSP(t,t0,tpeak,w,past)
if t>t0
tr=t-t0;
if tr-past>0
int=integral(@(tr) w.*tr.*exp(-tr./tpeak),tr-past,tr)/past;
else
int=integral(@(tr) w.*tr.*exp(-tr./tpeak),0,tr)/tr;
end
else
int=0;
end
end
  댓글 수: 2
Torsten
Torsten 2022년 12월 24일
Hint:
syms x a b
f = a*x*exp(-x/b)
f = 
F = int(f)
F = 
Olivier
Olivier 2023년 1월 13일
Thank!

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by