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.
Why is my integration output the mathematical expression and not the solution?
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to solve the following question:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1322250/image.png)
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 π.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1322255/image.png)
댓글 수: 4
Walter Roberson
2023년 3월 13일
The output IBP is the same as the input. At the limits +/- 2 the function is 0.
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1322410/image.png)
.
답변 (1개)
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
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!