Something must be a floating point scalar?

조회 수: 12 (최근 30일)
Mathidiot Superfacial
Mathidiot Superfacial 2016년 3월 14일
댓글: Walter Roberson 2022년 4월 10일
f=@(x,y) sqrt(9-x.^2-y.^2);
xmax=@(y) sqrt(9-y.^2);
volume=integral2(f,0,xmax,0,3)
But it says XMAX must be a floating point scalar? What's wrong?

채택된 답변

James Tursa
James Tursa 2016년 3월 14일
편집: James Tursa 2016년 3월 14일
The error message seems pretty clear. The x limits must by scalar values. The y limits can be functions of x. Just rearrange things so that is the case. Since f is symmetric with respect to x and y, you can just switch arguments.
integral2(f,0,3,0,xmax)
  댓글 수: 2
Mathidiot Superfacial
Mathidiot Superfacial 2016년 3월 14일
what if f is not symmetrical with respect to x and y? Can you still switch like that? for an integral is like SS f(x,y)dxdy, and say there is the code to evaluate like integral2(f,a,b,c,d) then are a and b always the bounds of the inner integral's variable? Or would a and b still be the bounds of x even when I'm trying to evaluate in reverse order like SS f(x,y)dydx ?
Walter Roberson
Walter Roberson 2016년 3월 14일
편집: Walter Roberson 2016년 3월 14일
For 2D integrals, theory says that it does not matter which order you evaluate the integration. So define the function handle to be integrated so that the first parameter is the one with fixed bounds and the second parameter is the one with variable bounds. Remember it is not required that x be the first parameter.
f = @(y, x) x.^2 + x.*sin(y).^2;
xmax=@(y) sqrt(9-y.^2);
integral2(f, 0, 3, 0, xmax )

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Albert Justin
Albert Justin 2022년 4월 10일
Enter the function f(x,y)=@(x,y) x.*y
Enter the outer integral lower limit:0
Enter the outer integral upper limit:a
Enter the inner integral lower limit:@(x) x.^2
Enter the inner integral upper limit:@(x) 2-x
i get the same error
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 4월 10일
a = 5;
f = @(x,y) x.*y
f = function_handle with value:
@(x,y)x.*y
xmin = 0
xmin = 0
xmax = a
xmax = 5
ymin = @(x) x.^2
ymin = function_handle with value:
@(x)x.^2
ymax = @(x) 2-x
ymax = function_handle with value:
@(x)2-x
integral2(f, xmin, xmax, ymin, ymax)
ans = -1.2823e+03

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by