Integral with scalar input
7 views (last 30 days)
Show older comments
Laureline Logiaco
on 29 May 2013
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
0 Comments
Accepted Answer
Teja Muppirala
on 29 May 2013
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Computations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!