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

1 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2023-3-13
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.
.

请先登录,再进行评论。

回答(1 个)

VBBV
VBBV 2023-3-13
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

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by