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

3 次查看(过去 30 天)
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)"

采纳的回答

Ravi Kumar
Ravi Kumar 2018-11-29
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 个评论
Ravi Kumar
Ravi Kumar 2018-11-29
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.
Jan Schäppi
Jan Schäppi 2018-11-29
This has solved my problem, I would never have come up with it myself. Thank you so much for your help!

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by