MATLAB: Heat distribution in a cylindrical rod

pdethermal model

Hi,
I am new to Matlab and am try to follow the example at the following link https://www.mathworks.com/help/pde/examples/heat-distribution-in-a-circular-cylindrical-rod.html The problem is the following; when it comes to defining thermal conductivity, I can easily define it as a function of "state or region. However, when it comes to defining it as a function of both region and state I am running into trouble. I am trying the following
% The rod is composed of a material with the following thermal properties.
mu = 1.65E-2; % thermal conductivity, W/(m-degree K)

nu = 3;
lambda = 8.6E-4; % thermal conductivity, W/(m-degree K)
gamma = 1.09;
PDE Toolbox allows definition of the non-constant coefficients as function of spatial coordinates and solution.
k1func = @(region,state) lambda*state.u.^gamma;
k2func = @(region,state) mu*state.u.^nu;
kfunc = @(region,state) (k1func+k2func).*region.y;
For a steady-state analysis, specify the thermal conductivity of the material.
thermalProperties(thermalModelS,'ThermalConductivity',kfunc);
and I get the following error
Error using pde.ThermalMaterialAssignment/checkCoefFcnHdlArgCounts (line 378)
Function handle specifying a material property must accept two
input arguments and return one output argument.
Any idea, what am I doing wrong?

Best Answer

Hello Vivek,
It looks like you have a simple syntax error when using the two initial anonymous functions ("k1func" and "k2func") in the final anonymous function ("kfunc"). I'm not sure why it gives you that error, but when called, MATLAB would be trying to add two function handles together, and the multiply them by region.y. I think you meant to call the functions inside the anonymous function definition:
kfunc = @(region,state) (k1func(region,state)+k2func(region,state)).*region.y;
This will pass the "kfunc" input arguments "region" and "state" along to "k1func" and "k2func" each time "kfunc" is called.