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
{"ft_lang_label":"__label__en","ft_lang_prob":0.7428369,"math_prob":0.95780075,"size":1349,"snap":"2019-43-2019-47","text_gpt3_token_len":321,"char_repetition_ratio":0.133829,"word_repetition_ratio":0.0625,"special_character_ratio":0.23054114,"punctuation_ratio":0.12916666,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99790424,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-10-19T15:57:35Z\",\"WARC-Record-ID\":\"<urn:uuid:4ab5ccef-f9f7-40b2-b2c0-cd15426a164a>\",\"Content-Length\":\"110206\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3faac9c0-54ce-4e7c-b41a-077cc9196068>\",\"WARC-Concurrent-To\":\"<urn:uuid:f6efd700-1703-4978-8daf-329a6e4bae67>\",\"WARC-IP-Address\":\"23.50.112.17\",\"WARC-Target-URI\":\"https://www.mathworks.com/matlabcentral/answers/68788-integral-operator-in-a-for-loop\",\"WARC-Payload-Digest\":\"sha1:RE4I3XGW3UDOCSL2NRIPUQ7N2H75M5NR\",\"WARC-Block-Digest\":\"sha1:XN6VKV2FXBCV4ONARNHQK4DPXFB6L3JP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-43/CC-MAIN-2019-43_segments_1570986696339.42_warc_CC-MAIN-20191019141654-20191019165154-00370.warc.gz\"}"}