What is wrong about my "specifyCoefficients" function use for PDEModel?

I am trying to solve the Schnakenberg Model, a (nonlinear) PDE system in 2D:
=
=
My code by now is the following:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Define Model
nEquations = 2;
model = createpde(nEquations);
%% Define Geometry
geometryFromEdges(model,@lshapeg);
%% Define Schnakenberg Model Nonlinear Function
a = 1; b = 0.5; gamma = 200; d = 20;
R = @(c) gamma*[a - c(1)+c(1)*c(2)*c(2);
b - c(1)*c(2)*c(2)];
D = [1 0; 0 d];
%% Solve Problem on Model
m_mod = zeros(2); d_mod = eye(2); a_mod = zeros(2);
c_mod = [D(1,1) 0 0 0;
0 0 0 0;
0 0 0 0;
0 0 0 D(2,2)];
f_mod = @(location,state) R(state.u);
specifyCoefficients(model,'m',m_mod,'d',d_mod,'c',c_mod,'a',a_mod,'f',f_mod);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
However as an output I get the following:
Error using pde.CoefficientAssignment/checkMCoefSize (line 398)
Size of the matrix 'm' is not consistent with
the pde.PDEModel/PDESystemSize property.
Error in pde.CoefficientAssignment/checkAllMatrixCoefSizes (line 240)
self.checkMCoefSize(self.m, systemsize);
Error in pde.CoefficientAssignment (line 103)
obj.checkAllMatrixCoefSizes(systemsize, numdims);
Error in pde.PDEModel/specifyCoefficients (line 139)
coef = pde.CoefficientAssignment(coefcont,argsToPass{:});
Error in ForumAttempt (line 21)
specifyCoefficients(model,'m',m_mod,'d',d_mod,'c',c_mod,'a',a_mod,'f',f_mod);
Where did I go wrong? I think I followed the Instructions at https://ch.mathworks.com/help/pde/ug/equations-you-can-solve.html
where it states "For systems of N equations, the coefficients m, d, and a are N-by-N matrices, f is an N-by-1 vector, and c is a 2N-by-2N tensor (2-D geometry)"

 Accepted Answer

Can you try using:
specifyCoefficients(model,'m',0,'d',d_mod,'c',c_mod,'a',0,'f',f_mod);
and see if you get the solution?
Regards,
Ravi

5 Comments

Hey Ravi
Thanks a lot for the fast answer, I now get the following error:
Error using pde.CoefficientAssignment/checkDCoefSize (line 411):
%%%%%%%%%%%%%%%%%%%%%%%%%%
Size of the matrix 'd' is not consistent with
the pde.PDEModel/PDESystemSize property.
Error in pde.CoefficientAssignment/checkAllMatrixCoefSizes (line 242)
self.checkDCoefSize(self.d, systemsize);
Error in pde.CoefficientAssignment (line 103)
obj.checkAllMatrixCoefSizes(systemsize, numdims);
Error in pde.PDEModel/specifyCoefficients (line 139)
coef = pde.CoefficientAssignment(coefcont,argsToPass{:});
Error in ForumAttempt (line 22)
specifyCoefficients(model,'m',m_mod,'d',d_mod,'c',c_mod,'a',a_mod,'f',f_mod);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Is it possible that specifyCoefficients is not defined for more than one equation contrary to the Matlab documentation?
Hi Jan,
Change value of 'm' from 'm_mod' to '0'. Your equations are first-order in time, 'm' is to be used only if your eqations are second order in time. Specifying '0' literal implies 'm' is not part of equation, if you specify zeros(2) then the problem becomes a wave eqation with 'd' representing damping.
Regards,
Ravi
Ah okay I understand what you mean. However this gives me the same error:
%%%%%%%%%%%%%%%%%%%%%%
Error using pde.CoefficientAssignment/checkDCoefSize (line 411)
Size of the matrix 'd' is not consistent with
the pde.PDEModel/PDESystemSize property.
Error in pde.CoefficientAssignment/checkAllMatrixCoefSizes (line 242)
self.checkDCoefSize(self.d, systemsize);
Error in pde.CoefficientAssignment (line 103)
obj.checkAllMatrixCoefSizes(systemsize, numdims);
Error in pde.PDEModel/specifyCoefficients (line 139)
coef = pde.CoefficientAssignment(coefcont,argsToPass{:});
Error in ForumAttempt (line 21)
specifyCoefficients(model,'m',0,'d',d_mod,'c',c_mod,'a',0,'f',f_mod);
%%%%%%%%%%%%%%%%%%%%%%%%%
Sorry didn't notice this earler.This shold be the final one.
specifyCoefficients(model,'m',0,'d',d_mod(:),'c',c_mod(:),'a',0,'f',f_mod);
Refer to the documentation of c-coefficient for example:
"To write the coefficient c for inclusion in the PDE model via specifyCoefficients, give c as either of the following:
  • If c is constant, give a column vector representing the elements in the tensor.
  • If c is not constant, give a function handle. The function must be of the form"
You need to arrage c-coefficient correctly so that c_mod(:) represent the correct tensor.
This has solved my problem, I would never have come up with it myself. Thank you so much for your help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!