# Integral operator in a for loop

82 views (last 30 days)
amin rasoulof on 27 Mar 2013
Commented: Walter Roberson on 15 Nov 2017
Hi folks! I am trying to calculate the integral of a function while it is in a loop,but MATLAB gives error. How can I change "v" each time? this is the code
f=@(y) sqrt(y)/(1+exp(y/v))
for v=-5:0.1:5
q(i)=integral(f,0,inf);
end

Shweta Rajoria on 15 Nov 2017
If we want to calculate double integral in a loop then what will be the modification in code below. If any body know the answer please help me. Any suggestions will be appreciated. Thanks in advance.
v= 1:1:5;
L= length(v)
for i=1:L
w=v(i)
fun= @(x,y) w.*x.*exp(-x.*y./w);
c(i)= @(y) integrate(@(x)fun(x,y), 0,Inf);
fun1= @(y) y+c(x)
c1(i)= integrate(fun1, 0,1)
end
diplay(c1())
Walter Roberson on 15 Nov 2017
Use integral instead of integrate -- just a small mistake in the name of the function.

Andrei Bobrov on 27 Mar 2013
Edited: Andrei Bobrov on 27 Mar 2013
v = -5:.1:5;
f = @(y)sqrt(y)./(1+exp(y./v));
q = integral(f,0,inf,'ArrayValued',true);

Matt J on 27 Mar 2013
vdata=-5:0.1:5;
n=length(vdata);
q=zeros(1,n);
for i=1:n
v=vdata(i);
f=@(y) sqrt(y)/(1+exp(y/v));
q(i)=integral(f,0,inf);
end