Integral operator in a for loop

Asked by amin rasoulof

amin rasoulof (view profile)

on 27 Mar 2013
Latest activity Commented on by Walter Roberson

Walter Roberson (view profile)

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

Shweta Rajoria (view profile)

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

Walter Roberson (view profile)

on 15 Nov 2017
Use integral instead of integrate -- just a small mistake in the name of the function.

Products

Answer by Andrei Bobrov

Andrei Bobrov (view profile)

on 27 Mar 2013
Edited by Andrei Bobrov

Andrei Bobrov (view profile)

on 27 Mar 2013

v = -5:.1:5;
f = @(y)sqrt(y)./(1+exp(y./v));
q = integral(f,0,inf,'ArrayValued',true);

Answer by Matt J

Matt J (view profile)

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