10 views (last 30 days)
Show older comments
Minjun Bae on 13 Jan 2020
Commented: Ravi Kumar on 19 Jan 2021
Open in MATLAB Online
Hi all,
I keep running into the error while I am specifying coefficients, namely c, a, and f, and the problem is I do not know why.
It would be very much appreciated if somebody kindly pointed me into the right direction.
- Below is my code:
Mypde = createpde(1);
geometryFromEdges(Mypde, dl);
mesh = generateMesh(Mypde, 'Hmax', 1e-6);
-----------------------
function amatrix = acoeffunction(region,state)
%Given
gv=-2.7460e-6;
I_tkns=7e-8;
F=9.6485e4;
%Now define variables
dP = @(state.u) 30*(state.u^4)-60*(state.u)^3+30*(state.u)^2;
E_chem = gv*dP;
E_over = -E_chem/F;
ED_rate = -I_tkns*E_over;
%Build a matrix for the a coefficient.
n1=2; %length of the vector, representing coefficients
nr = numel(region.x*region.y) %number of columns, region x and y are multiplied because it is a 2D problem.
amatrix = zeros(n1,nr); %allocate a
amatrix(1,:) = ED_rate*V_li*state.ux/state.u
amatrix(2,:) = ED_rate*V_li*state.uy/state.u
- In order for me to test whether the function is correct, I simply put a constant for all other coefficients, and the handle function for a indicated above.
specifyCoefficients(Mypde, 'm', 0, 'd', 1, 'c', 1, 'a', @acoeffunction, 'f', 1)
- The error I am getting is shown below:
Error using pde.CoefficientAssignment/checkCoefFcnHdlArgCounts (line
500)
Function specifying a coefficient must accept two
input arguments and return one output argument.
Error in pde.CoefficientAssignment/checkFcnHdlArgCounts (line 273)
self.checkCoefFcnHdlArgCounts(self.f, systemsize, ndims);
Error in pde.CoefficientAssignment (line 105)
obj.checkFcnHdlArgCounts(systemsize, numdims);
Error in pde.PDEModel/specifyCoefficients (line 139)
coef =
pde.CoefficientAssignment(self.EquationCoefficients,argsToPass{:});
Thank you so much in advance.
If you find any other problems in my script, please let me know.
Have a great day.
8 Comments Show 6 older commentsHide 6 older comments
Show 6 older commentsHide 6 older comments
Charlotte Rougier on 31 Jan 2020
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_792327
Hi, have you managed to solve this? I have the same issue. Thanks!
ADSW121365 on 4 Mar 2020
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_805183
⋮
- Link
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_805183
See AlsoThe Statement System.out.printf("%10s", 123456) Outputs ___________. (Note: * Represents A Space)A. 123456****B.File Exchange - MATLAB CentralImplementation of a Sliding Mode Controller for Single Ended Primary Inductor Converter -Journal of Power ElectronicsNetwork that can be pruned by using first-order Taylor approximation
Also seeking a solution to this.
Minjun Bae on 5 Mar 2020
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_805964
Hi guys,
I was able to solve this problem.
When you specify a handle function for a coefficient value, if your code includes some functions or variables that are not recognized by the system, this error comes up.
Double check if your code has some contents undefined.
For example,
function fmatrix = fcoeffunction(location,state)
fmatrix=zeros(3,nr)
fmatrix(1,:)=0;
fmatrix(2,:)=0;
fmatrix(3,:)=0;
This also will cause the same error because 'nr' has not been defined in the function handle.
Therefore, nr = numel(location.x) has to be defined before you call nr for defininf fmatrix.
MEHDI Heydari on 20 May 2020
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_852833
Open in MATLAB Online
Hello Minjun,
I did the same steps as you state, but still getting the same error.
I really appriciate if you can comment on my code below.
%c coefficient Matrix
function cMatrix=cCoeff(location, state)
s=0.000610655417342708;
n1=6;
n2=numel(location.x);
cMatrix=zerose(n1,n2);
cMatrix(1,:)= s^2*45337.*exp(-3887./state.u(2,:))/3600;
cMatrix(3,:)=cMatrix(1,:);
cMatrix(4,:)=0.0004*(state.u(1,:)./(1+state.u(1,:))).^2-0.0066*...
(state.u(1,:)./(1+state.u(1,:)))+0.2224;
end
Ravi Kumar on 20 May 2020
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_853103
You seem to have a typo in assiging zeros, zerose(n1,n2) must be zeros(n1,n2).
MEHDI Heydari on 26 Jun 2020
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_914593
⋮
Thanks so much for your attention.
You are right! It works after the correction
mar tav on 10 Jan 2021
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_1254768
Dear MEHDI Heydari
would you please guide me? I have the same problem as you, but my function is
function [cmatrix] = ccoeffunction(location, B_HMM)
n1 = 4;
nr = numel(location.x);
cmatrix = zeros(n1,nr);
cmatrix(1,:) = B_HMM(1,:);
cmatrix(2,:) = B_HMM(2,:);
cmatrix(3,:) = B_HMM(3,:);
cmatrix(4,:) = B_HMM(4,:);
end
I want to assign the B_HMM matrix as the c coefficient.
Ravi Kumar on 19 Jan 2021
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_1273259
The ccoeffunction should take two argument, location, state. You are using second argument to pass additional arguments. You can pass additional argument using a wrapper.
In your main scrtip:
B_HMM = ...
ccoefWrapper = @(location, state) ccoeffunction(location, state, B_HMM)
specifyCoefficients(model,'m',...,'c', ccoefWrapper,'f',...)
Then write the function:
function [cmatrix] = ccoeffunction(location, state,B_HMM)
n1 = 4;
nr = numel(location.x);
cmatrix = zeros(n1,nr);
cmatrix(1,:) = B_HMM(1,:);
cmatrix(2,:) = B_HMM(2,:);
cmatrix(3,:) = B_HMM(3,:);
cmatrix(4,:) = B_HMM(4,:);
end
You need to fillin appropriately for ... in the example I have shown above.
Regards,
Ravi
Sign in to comment.
Sign in to answer this question.
Answers (1)
Jothi Saravanan on 12 Nov 2020
Open in MATLAB Online
Hi, I am getting the same error. Can someone say what is the mistake I made?
clc; tic; % Clears the screen
clear all;
e=0.5;
mu=0.00689;
V=265.988178;
omega=1047.197;
C=0.0000508;
R=0.508/2;
phi=45;
L=0.127;
%v=12*mu/h^3;
phi=45;
model = createpde();
rect1 = [3,
4,
-1,
1,
1,
-1,
0.3,
0.3,
-0.3,
-0.3];
r=decsg(rect1);
geometryFromEdges(model,r);
applyBoundaryCondition(model,'dirichlet','Edge',1:4,'u',1*10^5);
specifyCoefficients(model,'m',0,...
'd',0,...
'c',1,...
'a',0,...
'f',@fcoeffunction);
generateMesh(model,'Hmax',0.083);
results = solvepde(model);
p= results.NodalSolution;
function f = fcoeffunction(location,state)
N = 1; % Number of equations
nr = length(location.x); % Number of columns
f = zeros(1,nr); % Allocate f
dh=-e*cosd(phi)*sind(location.x+phi)+e*sind(phi)*cosd(location.x+phi);
dt=0.1*omega(e*cosd(phi)*cosd(location.x+phi)+e*sind(phi)*sind(location.x+phi);
o=location.y^2-(L^2/4);
h=C+e*cosd(location.x);
r=(omega*dh+2*dt);
f(1,:)=3*mu*r*o/h^3;
end
1 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
MEHDI Heydari on 12 Nov 2020
Direct link to this comment
https://ms-www.mathworks.com/matlabcentral/answers/500024-pde-toolbox-specifying-coefficients-error-telling-me-function-specifying-a-coefficient-must-accep#comment_1129468
Open in MATLAB Online
Hi,
There are some errors in your fcoeffunction. Creat new function save it with the name fcoeffunction and then it will run!
function f = fcoeffunction(location,~)
eA=0.5;
mu=0.00689;
omega=1047.197;
C=0.0000508;
L=0.127;
%v=12*mu/h^3;
phi=45;
nr = length(location.x); % Number of columns
f = zeros(1,nr); % Allocate f
dh=-eA*cosd(phi)*sind(location.x+phi)+eA*sind(phi)*cosd(location.x+phi);
dt=0.1*omega*eA*cosd(phi)*cosd(location.x+phi)+eA*sind(phi)*sind(location.x+phi);
o=location.y.^2-(L^2/4);
h=C+eA*cosd(location.x);
r=(omega*dh+2*dt);
f(1,:)=3*mu*r.*o./(h.^3);
end
Sign in to comment.
Sign in to answer this question.
See Also
Categories
Mathematics and OptimizationPartial Differential Equation ToolboxGeneral PDEsBoundary Conditions
Find more on Boundary Conditions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office