Asked by abdul mohamed
on 20 Jun 2019

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

Answer by infinity
on 20 Jun 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

John D'Errico
on 20 Jun 2019

For specific bounds like [-pi, pi], things apparently get far more easy. To be honest, I'm surprised that a solution exists for the case of a general exponent even there. But based on the solution that it returns, I have a funny feeling a nice substitution exists that cleans it all up, but only for a specific set of bounds.

So as a wild guess, suppose you consider an application of integration by parts. Then think about the beta function, and if a transformation of variables will get you to the solution. Finally, think about what happens if the limits are not [-pi,pi]. That might also suggest why a solution was not found for general limits on the integral.

Not all problems that you will pose have an analytical solution. In fact, the opposite is more often true - that most problems lack such a solution.

infinity
on 21 Jun 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
on 21 Jun 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)

Sign in to comment.

Answer by John D'Errico
on 21 Jun 2019

Edited by John D'Errico
on 21 Jun 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.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.