Double Integral with interpolateSolution() from PDE solver in MATLAB

조회 수: 4 (최근 30일)
gbsh
gbsh 2017년 7월 19일
편집: Svetlana Pease 2017년 9월 7일
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?

답변 (2개)

Torsten
Torsten 2017년 7월 19일
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
Alan Weiss
Alan Weiss 2017년 7월 20일
편집: Alan Weiss 2017년 7월 20일
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 2017년 9월 6일
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?

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


Svetlana Pease
Svetlana Pease 2017년 9월 7일
편집: Svetlana Pease 2017년 9월 7일
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)).

카테고리

Help CenterFile Exchange에서 Boundary Conditions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by