How to do type II double integration on matlab
6 views (last 30 days)
Show older comments
I have no problem using type I (dydx) and when I use it i get the correct answer but if i try replicating the same method using type 2(dxdy) i get a diffrent answer which is wrong can someone explain what i am getting wrong.
Type 1
ymax = @(x) cos(x);
xmax = pi/2;
% ymax = upperboud of y I had to make a function for it since we can't put
% y below in integral2
rrr = integral2(fun,0,xmax,0,ymax);
%%% the volume is 0.4674 using type I which is correct
Type 2
% finding the volume using type 2
fun = @(x,y) (x.^2);
xmax = @(y) acos(y);
% xmax = upperbound of x, we had to make a function for it since we can't put
% x below in integral 2
rr = integral2(fun,0,xmax,0,1)
i got a wrong answer.
I would be very grateful if someone can help me thanks.
0 Comments
Accepted Answer
David Hill
on 28 Oct 2022
Use symbolic integration
syms x y
f=x^2;
int(int(f,x,0,acos(y)),y,0,1)
double(ans)
More Answers (1)
John D'Errico
on 28 Oct 2022
Edited: John D'Errico
on 28 Oct 2022
First, type I and II are not any common names for integrals that I know of. It might be what your teacher calls them. Maybe the new math, something that constantly seems to change. Regardless, it appears the difference lies merely in which order you perform the integration. So first, what volume are you computing an integral for?
The integration kernel is x^2, so you want to compute an integral of x^2 over a region in the (x,y) plane.
x varies from 0 to pi/2, y varies from 0 to cos(x).
First, what should we get analytically?
syms x y
symbintegral = int(int(x.^2,y,[0,cos(x)]),x,[0,pi/2])
vpa(symbintegral)
So you are correct there. What is the domain of integration? DRAW A PICTURE IF NECESSARY! I should have done that first. My bad.
X = linspace(0,pi/2);
Ymax = cos(X);
domainpoly = polyshape([X,pi/2,0],[Ymax,0,0])
plot(domainpoly)
So a quasi-pseudo-vaguely-triangular area, where one side of the triangle (the hypotenuse) is a cosine function. First, we can integrate with respect to x on the inner integral, then on y.
fun1 = @(x,y) x.^2;
xmax = pi/2;
ymax = @(x) cos(x);
integral2(fun1,0,xmax,0,ymax)
That works perfectly. Now, you want to swap the order of integration. REMEMBER that integral2 does the inner integral on the FIRST parameter of the function you give it! So you need a different function, with the arguments swapped!
fun2 = @(y,x) x.^2;
ymax = 1;
xmax = @(y) acos(y);
integral2(fun2,0,ymax,0,xmax)
Easy peasy.
See Also
Categories
Find more on Calculus 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!