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 commentaires

Star Strider
Star Strider le 4 Fév 2019
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 le 4 Fév 2019
Modifié(e) : Esra Akdogan le 4 Fév 2019
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 le 4 Fév 2019
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 le 4 Fév 2019
Have a look into "ArrayValued" option in integral.
Esra Akdogan
Esra Akdogan le 4 Fév 2019
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.

Connectez-vous pour commenter.

 Réponse acceptée

Torsten
Torsten le 5 Fév 2019

1 vote

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

1 commentaire

Esra Akdogan
Esra Akdogan le 5 Fév 2019
hello, I have another question. Are you god or something????
Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by