"Too many input arguments" when using integral2

xmin = 0;
xmax = 1;
ymin = 0;
ymax = @(x) x.^3;
fun= @(x)x;
fun2= @(y)y;
xbar = quad2d(fun,xmin,xmax,ymin,ymax);
fprintf('xbar = \n',xbar);
ybar = integral2(fun2,xmin,xmax,ymin,ymax);
fprintf('ybar = \n',ybar);
I'm working on setting up a quick program for help finding the centroids of areas bounded by functions, and I get the above error as soon as the code gets to the "fun" within the first quad2d function. I tried using the "integral2" function instead, and I get the same error.
I tried looking around the help boards here but none of the solutions for "Too many inputs..." seem to be for my specific problem. Is there an error with the way I'm trying to write the function, or can it just not be done symbolically this way?

 Respuesta aceptada

Star Strider
Star Strider el 27 de Abr. de 2016
You have a couple unrelated problems.
1. Your functions need to be functions of x and y, even if you don’t use the other argument;
2. You need numeric format descriptors in your fprintf statements.
This works:
xmin = 0;
xmax = 1;
ymin = 0;
ymax = @(x) x.^3;
fun= @(x,y)x;
fun2= @(x,y)y;
xbar = quad2d(fun,xmin,xmax,ymin,ymax);
fprintf('xbar = %f\n',xbar);
ybar = integral2(fun2,xmin,xmax,ymin,ymax);
fprintf('ybar = %f\n',ybar);

2 comentarios

Alan Kuffner
Alan Kuffner el 28 de Abr. de 2016
Huh. Go figure it's the little things. Thanks a ton!
Star Strider
Star Strider el 28 de Abr. de 2016
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Abr. de 2016

Comentada:

el 28 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by