MATLAB Answers

Applying 'if' condition within location-dependent thermal Properties

1 view (last 30 days)
Grzegorz
Grzegorz on 21 Jul 2021
Answered: Jan on 21 Jul 2021
Hallo!
I am using an external function ro_ult to calculate location-dependent mass density for a single-cell, 3-D thermal PDE analysis:
function ro_ult = ro_ult(location, state)
ro_s = 1300;
ro_d = 1800;
if location.y <=0
ro_ult = @(location,state) ro_d-(ro_d-ro_s)*exp(location.y/0.06);
else
ro_ult=1.6;
end
end
Any attempt to use the function produces a following error:
Not enough input arguments.
Error in <a href="matlab:matlab.internal.language.introspective.errorDocCallback('ro_ult', 'ro_ult.m', 4)" style="font-weight:bold">ro_ult</a> (<a href="matlab: opentoline('ro_ult.m',4,0)">line 4</a>)
if location.y <=0
Error in <a href="matlab:matlab.internal.language.introspective.errorDocCallback('pde_lun20_2h_walec6prb', 'pde_lun20_2h_walec6prb.m', 152)" style="font-weight:bold">pde_lun20_2h_walec6prb</a> (<a href="matlab: opentoline('pde_lun20_2h_walec6prb.m',152,0)">line 152</a>)
'MassDensity',ro_ult,...
I will be most thankfull for any help in this matter.

Answers (1)

Jan
Jan on 21 Jul 2021
After defining
ro_ult = @(location,state) ro_d-(ro_d-ro_s)*exp(location.y/0.06);
ro_ult is a function handle, which expects two inputs. Then code like this:
ro_ult = ro_ult(location, state);
... 'MassDensity',ro_ult,...
calls the function ro_ult without input arguments, which produces the shown message.
Calling the output exactly as the name of the function is extremely confusing. Maybe
... 'MassDensity',ro_ult,...
occurs without calling the function ro_ult() before. The function does not contain useful comments also. So it is not clear why it replies a number or a function handle depending on a value. Maybe you mean:
function x = ro_ult(location, state)
% Insert useful comments here...
ro_s = 1300;
ro_d = 1800;
if location.y <= 0
x = ro_d - (ro_d - ro_s) * exp(location.y / 0.06);
else
x = 1.6;
end
end

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by