Trying to do an integral
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hey guys, I'm having trouble computing this integral:
syms b h R x y
G=cos(x)^h;
int(G,x,-y,y)
where -y,y are integration constants.
Matlab spits back the integral. Does that mean it was unable to solve the integral?
It works in matlab if we define our boundaries to be specific values for example:
syms b h R x y
G=cos(x)^h;
int(G,x,-pi/2,pi/2)
we get answer like this:
>> untitled
ans =
beta(1/2, h/2 + 1/2)
So we can do it for specific bounadaries. Just not constants if that makes sense
0 Commenti
Risposte (2)
infinity
il 20 Giu 2019
Hello,
The problem is that if you use symbolic "y" and "h" in your way, it will not give you the result.
But if you put "h" equal to specific number and then you can find the integral of this function without boundaray "-y" and "y". Then, you can substitute value of "x = -y" and "x = y" into the obtained integral.
For example,
syms b x
h = 2;
G=cos(x)^h;
f = int(G,x)
It will give
f =
x/2 + sin(2*x)/4
Then, we can find the integral from -y to y by substitute them into the above function
fy = subs(f,y) - subs(f,-y)
and we obtain
fy =
y + sin(2*y)/2
By that way, you can change the value of "h = 3, 4, ....".
Best regards,
Trung
4 Commenti
infinity
il 21 Giu 2019
Hello Mohamed,
In your problem, it is seen to be impoossible for the symblic boundaries. However, I can suggest you one of my idea that you can get an approximate solution that depends on "h" and "y". My idea is
- You can change interval boundary with [-y y] to [-1 1], here you can refer in this link how to do this
When you have changed the function cos(x)^h will also depend on "y".
2. You can apply Gaussian quadrature for the integral in [-1 1]. In order to get the more accurate of the approximate solution, you shoul use large number of Gaussian point.
I hope this idea could give you a alternative way to pass your problem. In addition, you could try with "integral by part" like a comment before.
Best regards,
Trung
John D'Errico
il 21 Giu 2019
Since cos(x) is an even function, we can change the limits to [0,y] and just double the result. So we would have:
syms x h y
2*int(cos(x)^h,[0,y])
ans =
piecewise(y == pi/2, beta(1/2, h/2 + 1/2), y == pi/2 & h == 2, pi/2, y == pi/4 & h == -2, 2, y ~= pi/2 & (y ~= pi/4 | h ~= -2), 2*int(cos(x)^h, x, 0, y))
pretty(ans)
{ / 1 h 1 \ pi
{ beta| -, - + - | if y == --
{ \ 2 2 2 / 2
{
{ pi pi
{ -- if y == -- and h == 2
{ 2 2
{
{ pi
{ 2 if y == -- and h == -2
{ 4
{
{ y
{ /
{ | h pi / pi \
{ 2 | cos(x) dx if y ~= -- and | y ~= -- or h ~= -2 |
{ / 2 \ 4 /
{ 0
So MATLAB was a little more forthcoming here. We see a few specific cases where a solution is found. It gets hung up on the symbolic limits of integration, although for specific values of h (especially integer h), a solution will generally be found. For example:
2*int(cos(x)^2,[0,y])
ans =
y + sin(2*y)/2
2*int(cos(x)^3,[0,y])
ans =
2*sin(y) - (2*sin(y)^3)/3
2*int(cos(x)^0.5,[0,y])
ans =
4*ellipticE(y/2, 2)
John D'Errico
il 21 Giu 2019
Modificato: John D'Errico
il 21 Giu 2019
An alternative is to try a different solver. I seems Alpha finds a solution for the indefinite integral, so the definite integral, even with general bounds is now trivial.
Perhaps that is sufficient. Sorry the symbolic TB failed to find a solution.
0 Commenti
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!