필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Ayush Kumar
Ayush Kumar 2023년 3월 13일
댓글: Star Strider 2023년 3월 13일
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
Walter Roberson
Walter Roberson 2023년 3월 13일
The output IBP is the same as the input. At the limits +/- 2 the function is 0.
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에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by