Question

I would like to solve numerically an integral than depends on its previous path. Integral 7.14 from here http://www.mathworks.com/matlabcentral/answers/uploaded_files/8998/1.pdf.

With the code below I am getting an error. What is wrong? Am I solving this integral with this code?

"Error using integralCalc/finalInputChecks (line 516) 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."

Thank you.

z = 0:1/1000:10^-2
dz = z(2)-z(1); %integration step
sigma = 1;
q=0; %Integral value at z=0
for rr = 1:length(z)
fun = @(z) sigma*((10^4-exp(q))/((10^4+exp(q))));
q = integral(fun,0,z(rr))*dz;
end
q
Was it helpful?

Solution

Replace the line :

q = integral(fun,0,z(rr))*dz;

With:

q = integral(fun,0,z(rr),'ArrayValued',true)*dz;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top