Nonconstant coefficients PDE tool: Error telling me that function handle specifying function for coefficient must accept two input argument and return one output argument, yet that is the form that I have

1 Ansicht (letzte 30 Tage)
Hello everyone, I'm trying to solve a system of 2PDEs in 1D with nonconstant coefficients (i.e. coefficients dependent on x value and gradient) and I have specified a function for the coefficients and then want to pass it to specifyCoefficients to solve my PDE. I get the following error:
Error using pde.CoefficientAssignment/checkCoefFcnHdlArgCounts (line 531)
Function handle specifying a coefficient must accept two input arguments and return one output argument
What I don't understand is why, since that is the form it is in, i.e. Matrix=function(region, state) so one output, two inputs. Here is the relevant code:
numberofPDE=2;
model=createpde(numberofPDE);
geometryFromEdges(model,g);
mhandle=@mcoeffunction;
specifyCoefficients(model,'m',mhandle,'c',@ccoeffunction,'d',d,'a',A, 'f', f);
applyBoundaryCondition(model,'Edge',4,'u',@boundary, 'Vectorized','on');
hmax = h/16;
msh = generateMesh(model, 'Hmax', hmax, 'MesherVersion', 'R2013a');
result=solvepde(model);
where:
function Mmatrix=mcoeffunction(region,~)
N=4;
Nr=numel(region.x);
Mmatrix=zeroes(N,Nr);
I6=width*(2*density2*(y2^5*(- c22^2/5 + (2*c32)/5) - y3^5*(- c22^2/5 + (2*c32)/5) - (c22*y2^4)/2 + (c22*y3^4)/2 - y2^3/3 + y3^3/3 - (c32^2*y2^7)/7 + (c32^2*y3^7)/7 + (c22*c32*y2^6)/3 - (c22*c32*y3^6)/3) - 2*density1*(y1^5*(c21^2/5 + (2*c31)/5) - y2^5*(c21^2/5 + (2*c31)/5) + (c21*y1^4)/2 - (c21*y2^4)/2 + y1^3/3 - y2^3/3 + (c31^2*y1^7)/7 - (c31^2*y2^7)/7 + (c21*c31*y1^6)/3 - (c21*c31*y2^6)/3) - density3*((2*c33^2*y3^7)/7 - (4*c33*y3^5)/5 + (2*y3^3)/3));
I4=width*density3*((2*c33*y3^5)/5 - (2*y3^3)/3) - 2*density1*((c31*y1^5)/5 + (c21*y1^4)/4 + y1^3/3 - (c31*y2^5)/5 - (c21*y2^4)/4 - y2^3/3) - 2*density2*(- (c32*y2^5)/5 + (c22*y2^4)/4 + y2^3/3 + (c32*y3^5)/5 - (c22*y3^4)/4 - y3^3/3);
I2=width*(- 2*density1*(y1^3/3 - y2^3/3) - 2*density2*(y2^3/3 - y3^3/3) - (2*density3*y3^3)/3);
Mmatrix(1,:)=-I2*ones(1,N);
Mmatrix(2,:)=(((pi/(2*L))*sin(pi*region.x./(2*L)))/(1-cos(pi*region.x./(2*L))))*I4;
Mmatrix(4,:)=-I6*ones(1,N);
end
I6, I4, I2 are just numeric values. I have tried with tilde, without tilde, makes no difference. Normally state would be there instead of tilde, but it isn't used here. I get the error from the Mmatrix, since that is the first one it checks.
Anyone have any idea what's going on here? Regards, Leon

Akzeptierte Antwort

Damian Sheehy
Damian Sheehy am 23 Jun. 2016
You may have a syntax error in the body of the mcoeffunction function and the error it is producing may be misdiagnosed. I would suggest testing your function as follows:
% Setup some data to pass to the function
systemsize = 1;
location.x = 0;
location.y = 0;
location.z = 0;
location.subdomain=1;
state.u = zeros(systemsize, 1);
state.ux = zeros(systemsize, 1);
state.uy = zeros(systemsize, 1);
state.uz = zeros(systemsize, 1);
state.time = 0;
% Now test the function call:
mhandle=@mcoeffunction;
result = mhandle(location, state)

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by