Help with integral2 calculator

I'm trying to create a basic double integral calculator. How do I refine the code I have so far?
fun = @(x,y) input('enter integrand = ')
xmin = @(y) input('enter lower x boundary = ')
xmax = @(y) input('enter upper x boundary = ')
ymin = @(x) input('enter lower y boundary = ')
ymax = @(x) input('enter upper y boundary = ')
Q = integral2(fun,xmin,xmax,ymin,ymax)

 Respuesta aceptada

Star Strider
Star Strider el 21 de Abr. de 2018

Use the str2func (link) function. I would also use vectorize (link):

fun = input('enter integrand = ', 's') 
fun = str2func(['@(x,y) ' vectorize(fun)])
Q = integral2(fun, xmin, xmax, ymin, ymax)

3 comentarios

As always, my pleasure.

That becomes a bit more complicated, because you must test for a numeric input, and if it’s not numeric, then use str2func:

ymax = input('enter upper y boundary = ','s')
n = str2double(ymax);
if isnan(n)
    ymax = str2func(['@(x) ' vectorize(ymax)]);
else
    ymax = n;
end

You’ll need to do this in each limit, or at least those for which you expect a function input.

kd
kd el 22 de Abr. de 2018
Thank you so much. You probably saved me 3 days of trial and error.
Star Strider
Star Strider el 22 de Abr. de 2018
As always, my pleasure!
This is an interesting problem.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Preguntada:

kd
el 21 de Abr. de 2018

Comentada:

el 22 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by