PDE toolbox, specifying coefficients, error telling me "Function specifying a coefficient must accept two input arguments and return one output argument."
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
mar tav
il 10 Gen 2021
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
il 19 Gen 2021
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
Risposte (1)
Jothi Saravanan
il 12 Nov 2020
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 Commento
MEHDI Heydari
il 12 Nov 2020
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
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!