Integral with scalar input

7 次查看(过去 30 天)
Hi,
I am trying to integrate a function which I can't write easily for vector input, I only wrote it for scalar input.
I have been trying to use integral, either without options (the default should be, according to the documentation, 'ArrayValued', false), and by explicitly setting 'ArrayValued', false.
But the algorithm seems to always input vector to the function to be integrated. When it is debugged, I can indeed see that the size of the argument was (1,150):
prob_ISI1=@(One_del_sp_in_s)(comp_sngleS_given_SurvParts_meth1(One_del_sp_in_s,Exp_etaPr_tp,ints,delay_independent_jumps_inBins,dt,partial_cvnient_vect,tot_jump,frst_tot_jump_corr));
mat_value_totInt_ISIpdf(o,1)=integral(prob_ISI1,0,Inf,'RelTol',0,'AbsTol',1e-12,'ArrayValued',false);
Error using <
Matrix dimensions must agree.
Error in comp_sngleS_given_SurvParts_meth1 (line 13)
last_jmp=find(ints<(One_del_sp_in_s/dt),1,'last');
Error in
comp_num_Intgrl_ISIpdf_overalls_3meths>@(One_del_sp_in_s)(comp_sngleS_given_SurvParts_meth1(One_del_sp_in_s,Exp_etaPr_tp,ints,delay_independent_jumps_inBins,dt,partial_cvnient_vect,tot_jump,frst_tot_jump_corr))
(line 140)
prob_ISI1=@(One_del_sp_in_s)(comp_sngleS_given_SurvParts_meth1(One_del_sp_in_s,Exp_etaPr_tp,ints,delay_independent_jumps_inBins,dt,partial_cvnient_vect,tot_jump,frst_tot_jump_corr));
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 133)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 84)
[q,errbnd] = vadapt(@AToInfInvTransform,interval);
Error in integral (line 89)
Q = integralCalc(fun,a,b,opstruct);
Error in comp_num_Intgrl_ISIpdf_overalls_3meths (line 142)
mat_value_totInt_ISIpdf(o,1)=integral(prob_ISI1,0,Inf,'RelTol',0,'AbsTol',1e-12,'ArrayValued',false);
Error in main_BigFluct (line 59)
comp_num_Intgrl_ISIpdf_overalls_3meths(mn_step,std_step,dur_step,observed_ISIs,max_ISI,eta,dt,times_center_subjumps,rootsavedir,'')
size(One_del_sp_in_s)
ans =
1 150
Do you know how to fix this ? I am using Matlab R2013a
Laureline

采纳的回答

Teja Muppirala
Teja Muppirala 2013-5-29
For an integrand that can't accept vector inputs, but only take scalar values one by one, you actually need to set ArrayValued to TRUE.
Consider:
F = @(x) x^2
integral(F,0,1) % <-- Will give an error
integral(F,0,1,'ArrayValued',true) % <-- Gives 1/3 which is correct
However, if F was changed to
F = @(x) x.^2
Then it would work either way.
  2 个评论
Laureline Logiaco
Laureline Logiaco 2013-5-29
Thank you very much, my mistake indeed.
Leandro
Leandro 2019-10-16
编辑:Leandro 2019-10-16
What if the integral is double?
How to integrate, in Matlab, a function which is written only for scalar input?
The option ArrayValued is not available for integral2.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Computations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by