## Double Integral unkown limits

Asked by erhan aksu

### erhan aksu (view profile)

on 10 Feb 2019
Latest activity Commented on by John D'Errico

### John D'Errico (view profile)

on 11 Feb 2019
Accepted Answer by John D'Errico

### John D'Errico (view profile)

Hi
In this problem a=0.5 b=0.1 funa*x.^2 + b*y.^2 0<x<5 0<y<2xk and q=125. I try fo find that What is the value of the k? now I don't know a value but I know q. How can I estimate a value and use random command for a value.
a =0.5;
b = 0.1;
fun = @(x,y) a*x.^2 + b*y.^2;
%0<x<5 0<y<2xk
ymax=2*x*k
q = integral2(fun,0,5,0,ymax)==125 % real value 125
What is the value of the k???

Show 1 older comment
Star Strider

### Star Strider (view profile)

on 10 Feb 2019
The problem is that by definition the double integration completely evaluates ‘x’ in the first integration, so it cannot be considered in the second integration, since ‘x’ is integrated between 0 and 5, not between 0 and a function of ‘y’. The only possible solution for your problem that I see is to reverse the order of integration, evaluating ‘y’ first, then ’x’, or re-defining your problem. However, that may not be appropriate.
Walter Roberson

### Walter Roberson (view profile)

on 10 Feb 2019
Instead of passing ymax to integral2, pass @(x) ymax(x,k)
Meanwhile, the @(x,y,k)fun(x,y) should just be fun as no third parameter is going to be passed by integral2 and fun does not need k.
erhan aksu

### erhan aksu (view profile)

on 11 Feb 2019
Thanks Star Strider and Walter Roberson for advices.

### Tags

Answer by John D'Errico

### John D'Errico (view profile)

on 10 Feb 2019
Edited by John D'Errico

### John D'Errico (view profile)

on 10 Feb 2019

Basic calc? I hope this is not homework. But at least you made some effort.
You have formulated the problem as
q = int( int( a*x^2 + b*y^2,0,2*x*k), 0,5)
Where a, b, q are all known. The problem is, you want to solve for k, where k is part of that upper limit on y. We can do this on paper, at last most of it, but easy enough to do entirely in MATLAB too.
syms x y k
q = 125;
a = 0.5;
b = 0.1;
The symbolic toolbox is smart enough to recognize the decimal values 0.5 and 0.1 as their true fractional equivalents.
We can do the inner integral on y easily enough.
int(a*x^2 + b*y^2,y,0,2*x*k)
ans =
(k*x^3*(4*k^2 + 15))/15
So we should see the double integral is simple too.
dubint = int(int(a*x^2 + b*y^2,y,0,2*x*k),x,0,5)
dubint =
(125*k*(4*k^2 + 15))/12
What we see is a cubic polynomial in k.
solve(dubint == 125,'maxdegree',3)
ans =
(269^(1/2)/8 + 3/2)^(1/3) - 5/(4*(269^(1/2)/8 + 3/2)^(1/3))
5/(8*(269^(1/2)/8 + 3/2)^(1/3)) - (3^(1/2)*(5/(4*(269^(1/2)/8 + 3/2)^(1/3)) + (269^(1/2)/8 + 3/2)^(1/3))*1i)/2 - (269^(1/2)/8 + 3/2)^(1/3)/2
(3^(1/2)*(5/(4*(269^(1/2)/8 + 3/2)^(1/3)) + (269^(1/2)/8 + 3/2)^(1/3))*1i)/2 + 5/(8*(269^(1/2)/8 + 3/2)^(1/3)) - (269^(1/2)/8 + 3/2)^(1/3)/2
Kind of a symbolic mess. But vpa can reduce it simply.
vpa(ans)
ans =
0.70611518025253139152901981827648
- 0.35305759012626569576450990913824 - 2.0307508428749447828026672218255i
- 0.35305759012626569576450990913824 + 2.0307508428749447828026672218255i
Now, could I have done that on paper? Yes, except for the last part, where I'd probably have thrown the cubic polynomial into roots to solve.
expand(dubint)
ans =
(125*k^3)/3 + (625*k)/4
>> roots([125/3 0 625/4 -125])
ans =
-0.353057590126266 + 2.03075084287495i
-0.353057590126266 - 2.03075084287495i
0.706115180252531 + 0i
Could you have done it without using the symbolic toolbox? Yes. It is a bit easier to do the integration symbolically, and I am a bit lazy. I'd certainly have done the integrations on paper as calc 101.
Verification step:
k = 0.706115180252531;
ulimy = @(x) 2*x*k;
integral2(@(x,y) a*x.^2 + b*y.^2,0,5,0,ulimy)
ans =
125.000000000043
Ok. Could I have solved it using fzero and integral2? Do I really need to? Sigh.
k = fzero(@(k) integral2(@(x,y) a*x.^2 + b*y.^2,0,5,0,@(x) 2*x*k) - 125,[0.1,5])
k =
0.706115180252333
It seems to have worked this way too. I suppose if the integrand were more complicated, you would have had no choice in the matter.

Show 1 older comment
John D'Errico

### John D'Errico (view profile)

on 11 Feb 2019
Lets see. You asked how to solve a problem. I showed you not one way to solve that exact problem, but several ways. You are unhappy with the solution, because it does not teach you how to solve the problem you have not told us about?
In fact, the last way I showed you how to solve the problem (with fzero and integral2) was a completely general one. It did not rely on anything special about the function which you have carefully kept secret from us.
I'll try to dig out my old MATLAB Tarot card set. Maybe it will help. If not that, then the MATLAB crystal ball may help. Now, just close your eyes, and focus on your problem...........
erhan aksu

### erhan aksu (view profile)

on 11 Feb 2019
Sorry I could’t see last solution. I am looking for that. Thanks for everything. Best regards.
John D'Errico

### John D'Errico (view profile)

on 11 Feb 2019
Ah. Ok. I just got too busy with the other solutions, that the last one got lost. I do that sometimes.