필터 지우기
필터 지우기

Error message from integral calculation

조회 수: 5 (최근 30일)
Orongo
Orongo 2018년 4월 7일
댓글: Steven Lord 2018년 4월 9일
Hi, I'm calculating the survival function (lx) that is expressed with an integral such as
to calculate this I have created following program
% main.m
param_1938 = [2.06441912000572E-07/1000,0.197642212387667/100000,1.23947876070978/10];
mu_x=@(t) f_lx(param_1938);
l_x = exp(-integral(@(t) mu_x(t),0,106));
%f_lx.m
function res=f_lx(param)
x=(0:1:106)';
a=param(1);
b=param(2);
c=param(3);
res = zeros(size(x));
ind = x>100;
res(ind) = a+b*exp(c*100)+(x(ind)-100)*0.001;
res(~ind) =a+b*exp(c*x(~ind));
end
This result in the error message
Error using integralCalc/finalInputChecks (line 515)
Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to true.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
I'm not seeing where this goes wrong. Please can anyone shed some light on this??

답변 (1개)

Steven Lord
Steven Lord 2018년 4월 7일
You want to integrate with respect to x, not with respect to your parameters. See the "Parameterized Function" example on the documentation page for the integral function and the "Parameterizing Functions" page linked in the Topics section on that page to see how to integrate a parameterized function like yours.
  댓글 수: 2
Orongo
Orongo 2018년 4월 9일
Ok, I changed the code a bit but still getting same error though.
% main
param_1938 = [2.06441912000572E-07/1000,0.197642212387667/100000,1.23947876070978/10];
mu_x=@(t) f_lx(t,param_1938);
l_x = exp(-integral(mu_x,0,106));
Steven Lord
Steven Lord 2018년 4월 9일
And you changed f_lx to accept the first input argument as x and does not overwrite the array integral passed into your integrand function with a vector of a fixed length?

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

카테고리

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