'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??
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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)
Accepted Answer
Steven Lord
on 7 Sep 2018
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 Comments
madhan ravi
on 7 Sep 2018
Edited: madhan ravi
on 7 Sep 2018
hi @steven thank you for answering I tried. what you told:
>> syms x y b
fun = @(x,y)x.^2;
subplot(2,1,1)
ezsurf(fun)
xmin = 0;
xmax = 4;
ymin =0;
ymax = @(x,b) b.*sqrt(x);
b=1
Q = integral2(fun,xmin,xmax,ymin,ymax)
b =
1
Not enough input arguments.
Error in @(x,b)b.*sqrt(x)
Error in integral2Calc>integral2t/tensor (line 190)
top = YMAX(x);
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] =
integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q =
integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
>>
Steven Lord
on 8 Sep 2018
The fifth input to your integral2 call and the fifth input to my integral2 call are different. In your call, you're passing an anonymous function that requires two inputs into integral2. In mine, I pass an anonymous function that requires only one input into integral2.
madhan ravi
on 8 Sep 2018
Still the same.
...
ymax = @(x,b) b.*sqrt(x);
b=1
Q = integral2(fun,xmin,xmax,ymin,@(x) ymax(x, b))
madhan ravi
on 8 Sep 2018
It works @steven thank you but is it not possible to keep the limit as symbolic variable that’s the main motive here?
Steven Lord
on 8 Sep 2018
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
on 8 Sep 2018
Thank you so much for sparring your time and I highly appreciate your efforts ?->(Indian way of thanking)
More Answers (0)
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)