MATLAB Answers

Error: Function specifying a coefficient must accept two input arguments and return one output argument (PDE Toolbox).

조회 수: 2(최근 30일)
Gabriel S
Gabriel S 2020년 3월 25일
댓글: Gabriel S 2020년 3월 26일
Hello all.
I am trying to establish a function in order to specify nonconstant coefficients "f" for an elliptic equation for the solvepde command. For that end, I created a funcion as specified here, however, the following error message appears:
Error using pde.CoefficientAssignment/checkCoefFcnHdlArgCounts (line 499)
Function specifying a coefficient must accept two
input arguments and return one output argument.
The code I am trying to run is displayed below (the "..." are ommited information to conserve space, but include constants and variables):
N = 15;
model = createpde(N);
%4.2.1. Creating the PDE Model - Geometry (Cylinder)
gm = multicylinder (D_red/2,[d_aq1 L_aq1 (L_red-d_aq1-L_aq1)], 'ZOffset',[0 d_aq1 (L_aq1+d_aq1)]);
model.Geometry = gm;
generateMesh(model);
pdegplot(model,'FaceLabels','on','FaceAlpha',0.5);
%4.2.2. Setting Boundary Conditions (Initial conditions not needed
%for steady-state problems)
h1 = [0 0 0 0 0 1 1 1 1 1 1 1 0 0 0]';
r1 = [0 0 0 0 0 C0_gas C0_NH3 C0_N2 C0_H2 C0_H2O C0_HF C0_O2 0 0 0]';
h3 = [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0]';
q3 = zeros(N,1);
g5 = [0 0 0 0 0 0 0 0 0 0 0 0 0 (phi_aq1/lambda_wred) 0]';
h6 = [1 1 1 1 1 0 0 0 0 0 0 0 1 0 1]';
r6 = [C0_solid C0_UO3 C0_UO2 C0_U3O8 C0_UO2F2 0 0 0 0 0 0 0 T0 T0 P0]';
h2 = zeros(N,1);
applyBoundaryCondition(model,'dirichlet','Face',6,'h',h6,'r',r6);
applyBoundaryCondition(model,'dirichlet','Face',1,'h',h1,'r',r1);
applyBoundaryCondition(model,'dirichlet','Face',2,'h',h2,'r',h2);
applyBoundaryCondition(model,'dirichlet','Face',4,'h',h2,'r',h2);
applyBoundaryCondition(model,'mixed','Face',3,'h',h3,'r',@r5function,'q',q3,'g',@g3function);
applyBoundaryCondition(model,'mixed','Face',7,'h',h3,'r',@r5function,'q',q3,'g',@g3function);
applyBoundaryCondition(model,'mixed','Face',5,'h',h3,'r',@r5function,'q',q3,'g',g5);
%4.2.3. Setting PDE Coefficients (Elliptic equation type)
c = [0 0 0 0 0 0 De De De De De De lambdaeff lambda_wred 0]';
specifyCoefficients(model,'m',0,'d',0,'c',c,'a',0,'f',@fcoeffunction);
%5. Functions
function bcMatrix = g3function(location,state)
nr1 = length(location.x);
bcMatrix = zeros(N,nr1);
bcMatrix(14,:) = (h/lambda_wred)*(state.u(13,:)-state.u(14,:)) + (sigma*Em_wred/lambda_wred)*((state.u(13,:).^4) - (state.u(14,:).^4));
end
function bcMatrix = r5function(location,state)
nr2 = length(location.x);
bcMatrix = zeros(N,nr2);
bcMatrix(13,:) = state.u(14,:);
end
function f = fcoeffunction(location,state)
nr3 = length(location.x);
f = zeros(N,nr3);
f(1,:) = ...
f(2,:) = ...
f(3,:) = ...
f(4,:) = ...
f(5,:) = ...
f(6,:) = ...
f(7,:) = ...
f(8,:) = ...
f(9,:) = ...
f(10,:) = ...
f(11,:) = ...
f(12,:) = ...
f(13,:) = ...
f(15,:) = ...;
end
I also tried to remove all f(1,:) ... f(15,:) in order to test if the error was located in the expressions, but it persists. Also, it seems the error is located within this function, since setting "f" to zero solves the problem. What could I be doing wrong? Thanks in advance.

채택된 답변

Ravi Kumar
Ravi Kumar 2020년 3월 26일
Chage f = zeros(N,nr3); to f = zeros(15,nr3);
N is not in the scope of the function fcoeffunction.
Regards,
Ravi
  댓글 수: 1
Gabriel S
Gabriel S 2020년 3월 26일
Dear Mr. Ravi,
By replacing N as you suggested, as well as other constants I specified outside the funcion "fcoeffunction", the code worked! Thank you very much!

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by