Integral with scalar input
조회 수: 6 (최근 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
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Computations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!