Numerical integration twice wrt same variable

Hello people,
I have afunctionand it is calculated by only numerical methods. As an example let's say;
where
And I am asked to calculate; at some points of x, let's say at
I do not how to it. I need to calculate y, and use it as a function of x by numerical integration methods. I write my algortihm down below, and I get of course error. Can someone help me fix it?
Thanks in advanced.
clear
clc
r = 1:5; x = 1:5;
for k = 1:length(x)
y(k) = integral(@(r) ((r+1).^2+1)./r,1,x(k))
I(k) = integral(@(x) (1+y(k)),0,1)
end

5 件のコメント

Star Strider
Star Strider 2019 年 2 月 4 日
Did my Answer to your previous Question Numerical Integration in Summation sign help in this regard?
I believe I demonstrated the necessary approach there.
Esra Akdogan
Esra Akdogan 2019 年 2 月 4 日
編集済み: Esra Akdogan 2019 年 2 月 4 日
Hello, thanks for the answer first. Sure it makes me gain another points of view. But there you have created another situation. Here I have y only depends on x, and then I have to integrate it once again wrt x. There are no double independent variables. If I had double independent variables, I'd calculate a double integral and life'd be better. Here as you see, I have x in the boundary and I have to calculate y by numerical integration.
Your answer gives an idea to me, and I know that (thanks to you) I need something like this: (It does not matter if I'd use x again instead of r, since r is a dummy variable). When I run it, I get "not enough input argument" error.
for k = 1:length(x)
I(k) = integral(@(x) (1-(integral(@(r) ((r+1).^2+1)./r,1,x(k)))))
end
Esra Akdogan
Esra Akdogan 2019 年 2 月 4 日
I have x in the boundary of an integral that only can be calculated by numerical methods, and same x is the variable of follwing integral. It is like hell I think.
madhan ravi
madhan ravi 2019 年 2 月 4 日
Have a look into "ArrayValued" option in integral.
Esra Akdogan
Esra Akdogan 2019 年 2 月 4 日
Thanks for the answer guys. Actually I do not need the value of y(x). It is just an intermediate step in the way of reaching the main integral I. Maybe there is a way for this.

サインインしてコメントする。

 採用された回答

Torsten
Torsten 2019 年 2 月 5 日

1 投票

fun1 = @(x)integral(@(r)((r+1).^2+1)./r,1,x);
fun2 = integral(@(x)(1+fun1(x)),0,1,'ArrayValued',true)

1 件のコメント

Esra Akdogan
Esra Akdogan 2019 年 2 月 5 日
hello, I have another question. Are you god or something????
Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeParticle & Nuclear Physics についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by