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 Comments

Did my Answer to your previous Question Numerical Integration in Summation sign help in this regard?
I believe I demonstrated the necessary approach there.
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
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.
Have a look into "ArrayValued" option in integral.
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.

Sign in to comment.

 Accepted Answer

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

1 Comment

hello, I have another question. Are you god or something????
Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!