'I get error saying Input function must return 'double' or 'single' values. Found 'sym'.' because max is defined in symbolic variable, how to overcome this issue??

조회 수: 27 (최근 30일)
syms x y b
fun = @(x,y)x.^2;
subplot(2,1,1)
ezsurf(fun)
xmin = 0;
xmax = 4;
ymin =0;
ymax = @(x) b.*sqrt(x);
Q = integral2(fun,xmin,xmax,ymin,ymax)

채택된 답변

Steven Lord
Steven Lord 2018년 9월 7일
Your ymax function returns a sym result. If you specify the limits as function handles in your call to integral2 those function handles must return a numeric result, not a symbolic result.
If you want to integrate with a symbolic limit, work solely with symbolic variables and call the int function twice instead of calling integral2.
If you want to be able to specify b when you call integral2 rather than when you define the ymax function:
ymax = @(x, b) b.*sqrt(x);
Now when you call integral2 (I'm assuming you've defined fun, xmin, xmax, and ymin before this call) specify b:
% Use b = 1
Q = integral2(fun, xmin, xmax, ymin, @(x) ymax(x, 1));
% Use b = x.^2
Q = integral2(fun, xmin, xmax, ymin, @(x) ymax(x, x.^2));
  댓글 수: 7
Steven Lord
Steven Lord 2018년 9월 8일
Not with integral2, no. If you want to integrate with a symbolic limit, work solely with symbolic variables and call the int function twice instead of calling integral2.
madhan ravi
madhan ravi 2018년 9월 8일
Thank you so much for sparring your time and I highly appreciate your efforts ?->(Indian way of thanking)

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

추가 답변 (0개)

카테고리

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