Why is my integration output the mathematical expression and not the solution?

I am trying to solve the following question:
and I have utlised the following script to achieve so:
syms x
func = ((x^3*cos(x/2)+1/2)*(sqrt(4-x^2)));
int(func,x,-2,2)
But MATLAB keeps returning the explicit form of the function back instead of computing it, as shown below:
ans =
int((4 - x^2)^(1/2)*(x^3*cos(x/2) + 1/2), x, -2, 2)
What am I doing wrong that is making it not compute but merely display the function?
The answer should be or π.

4 Comments

I apologise to anyone that is confused by the awkward formating of the math functions/charcters, I used LaTex for it and I don't know why it does that.
Odd. If you break it into two pieces then it can handle the 1/2*sqrt(4-x^2) by itself (giving π for that part), but it cannot seem to handle the x^3*cos(x/2)*sqrt(4-x^2) giving a result of 0 -- not figuring out that it is an odd function that will cancel out.
The output IBP is the same as the input. At the limits +/- 2 the function is 0.
Running integrateByParts correctly this time (that I had not done previously, proving once again that paying close attention to the documentation is always appropriate) produces —
syms x
func = ((x^3*cos(x/2)+1/2)*(sqrt(4-x^2)));
F = int(func,x,-2,2)
iBP1 = integrateByParts(F,diff(sqrt(4-x^2)))
Fi1 = release(iBP1)
Fi1 = simplify(Fi1, 500)
iBP2 = integrateByParts(F,diff((x^3*cos(x/2)+1/2)))
Fi2 = release(iBP2)
Fi2 = simplify(Fi2, 500)
F =
int((4 - x^2)^(1/2)*(x^3*cos(x/2) + 1/2), x, -2, 2)
iBP1 =
-int((4 - x^2)^(1/2)*(2*x^3*cos(x/2) - ((x^2 - 4)*(x^3*cos(x/2) + 1/2))/x^2 + ((x^2 - 4)*(3*x^2*cos(x/2) - (x^3*sin(x/2))/2))/x + 1), x, -2, 2)
Fi1 =
-int((4 - x^2)^(1/2)*(2*x^3*cos(x/2) - ((x^2 - 4)*(x^3*cos(x/2) + 1/2))/x^2 + ((x^2 - 4)*(3*x^2*cos(x/2) - (x^3*sin(x/2))/2))/x + 1), x, -2, 2)
Fi1 =
-Inf
iBP2 =
-int(x^3*cos(x/2)*((4 - x^2)^(1/2) + ((4 - x^2)^(1/2)*(x^3*cos(x/2) + 1/2)*((x^3*cos(x/2))/4 - 6*x*cos(x/2) + 3*x^2*sin(x/2)))/(3*x^2*cos(x/2) - (x^3*sin(x/2))/2)^2 - (x*(x^3*cos(x/2) + 1/2))/((4 - x^2)^(1/2)*(3*x^2*cos(x/2) - (x^3*sin(x/2))/2))), x, -2, 2)
Fi2 =
-int(x^3*cos(x/2)*((4 - x^2)^(1/2) + ((4 - x^2)^(1/2)*(x^3*cos(x/2) + 1/2)*((x^3*cos(x/2))/4 - 6*x*cos(x/2) + 3*x^2*sin(x/2)))/(3*x^2*cos(x/2) - (x^3*sin(x/2))/2)^2 - (x*(x^3*cos(x/2) + 1/2))/((4 - x^2)^(1/2)*(3*x^2*cos(x/2) - (x^3*sin(x/2))/2))), x, -2, 2)
Fi2 =
NaN
I ran this in MATLAB Online, since it requires more than the allotted 55 seconds to run it here. It turns out that different definitions of (as described in the documentation) produce different results, neither of them finite.
.

Sign in to comment.

Answers (1)

func = @(x) ((x.^3.*cos(x./2)+1/2).*(sqrt(4-x.^2)));
integral(func,-2,2)
If you use integral it will work as you expected

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 13 Mar 2023

Commented:

on 13 Mar 2023

Community Treasure Hunt

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

Start Hunting!