Double Integral with interpolateSolution() from PDE solver in MATLAB

4 visualizaciones (últimos 30 días)
gbsh
gbsh el 19 de Jul. de 2017
Editada: Svetlana Pease el 7 de Sept. de 2017
I have results from the PDE solver in MATLAB and I need to a double integral, I would assume by using the integral2() function.
The problem is I cannot form an input that is acceptable by the integral2 function, directly that is. I have tried using an anonymous function like this
f = @(x,y) interpolateSolution(result, x, y)
And this works perfectly but when I do integration on it.
integral2(f, 0, 5, 0, 8)
I get an error like this
Error using integral2Calc>integral2t/tensor (line 241)
Integrand output size does not match the input size.
I do not understand why I can't do this. I've been able to perform a fit using the toolbox and get a fit for the solution for which then I can create an anonymous function and perform integration. It works when using the fit, but not when I use the interpolateSolution() function. I would settle for the fit, but it takes too much time to solve the PDE, fit it, and perform integration and I'm trying to do an optimization study. Is there a better way to do integration on the results directly from PDE solver?

Respuestas (2)

Torsten
Torsten el 19 de Jul. de 2017
From the documentation:
The function f must accept two arrays of the same size and return an array of corresponding values. It must perform element-wise operations.
Is this the case for your function "interpolateSolution" ?
Best wishes
Torsten.
  5 comentarios
Alan Weiss
Alan Weiss el 20 de Jul. de 2017
Editada: Alan Weiss el 20 de Jul. de 2017
I don't really know what is going on. But maybe you can ensure that the returned function values have the correct size by this sort of function:
function f = intfun(x,y,result)
f = interpolateSolution(result,x,y);
f = reshape(f,size(x));
Call the function like this, assuming that result is in your workspace:
integral2(@(x,y)intfun(x,y,result),0,5,0,3)
Or maybe, in a single anonymous function,
f = @(x,y)reshape(interpolateSolution(result,x,y),size(x));
But as I say, this may fail because I don't really know what is going on.
Alan Weiss
MATLAB mathematical toolbox documentation
Thomas Förster
Thomas Förster el 6 de Sept. de 2017
I have the same problem. Using the reshape the interpolation finds a value without an error, but I don't know if it is the right solution. Is there any new information on why this error occurs?

Iniciar sesión para comentar.


Svetlana Pease
Svetlana Pease el 7 de Sept. de 2017
Editada: Svetlana Pease el 7 de Sept. de 2017
This is the recommendation from the interpolateSolution page:
interpolateSolution converts query points to column vectors xq(:), yq(:), and (if present) zq(:). The returned solution is a column vector of the same size. To ensure that the dimensions of the returned solution are consistent with the dimensions of the original query points, use reshape. For example, use uintrp = reshape(gradxuintrp,size(xq)).

Community Treasure Hunt

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

Start Hunting!

Translated by