Function handle in a if statement

12 views (last 30 days)
Hi everyone, I am trying to solve a complex ode equation with if statement meanwhile some expression is a function of a and T. However Matlab doesn't seem to like my expression in the if statement. Can I know what is wrong with my expression? Thank you for everyone's help!
T_g =@(a,T) ((lambda_Tg_grind.*a(T_g1_grind - T_g0_grind))./(1 - (1 - lambda_Tg_grind).*a)); + T_g0_grind;
delta_Tg = @(a,T) T - T_g;
% Find Activation energy for k1 and k2
mER1_g = @(a,T) -((T_g.^2).*(c1./c2)).*8.314;
mER2_g = @(a,T) -((c1.*c2.*(T_g + delta_Tg).^2)./(c2 + delta_Tg).^2).*8.314;
k1_grindling = @(a,T) A1_grind*exp(mER1_f/T); % are they different?
k2_grindling = @(a,T) A2_grind*exp(mER2_f/T);
% T_g conditions
Condition = @(a,T) T_g + delta_Tg;
if isoTemp > Condition % THIS LINE
k_2d = @(a,T) k_2d.*exp(mER2_g.*((1./T) - (1./(T_g - delta_tg))));
elseif T_g <= isoTemp && isoTemp <= Condition
k_2d = @(a,T) k_2d_tg.*exp((c1.*(T - T_g))./(c2 + (T - T_g)));
elseif isoTemp < T_g
k_2d = @(a,T) k_2d_tg.*exp(mER1_g.*(1./T - 1./T_g));
end
To explain a bit about my code and problem:
a is waiting to be solved in later lines by ode15i where T is the input. And the error that I have is: (highlighted in above %THIS LINE)
Undefined operator '>' for input arguments of type 'function_handle'.
Error in BlackBox (line 323)
if isoTemp > Condition

Accepted Answer

OCDER
OCDER on 17 Jul 2018
Edited: OCDER on 17 Jul 2018
You cannot use an inequality for a function handle, as it makes no sense.
Condition = @(a,T) T_g + delta_Tg;
if isoTemp > Condition % THIS LINE MAKES NO SENSE. isoTemp > @(a, T) T_g + delta_Tg ????
end
Perhaps you mean to get the value returns from a function handle?
if isoTemp > Condition(1, 10) % OK. Value of the function handle at a = 1, T = 10.
end
But careful, your T_g and delta_Tg are also function handles, so you would need to do something like :
Condition = @(a,T) T_g(a, T) + delta_Tg(a, T);
  8 Comments
OCDER
OCDER on 17 Jul 2018
Well, the if statement is BEFORE your ode15i, so no a value is being passed on to Condition. you'll have to redesign your script here... Did you want a main function to switch the function handles WHILE doing the ode15i? You'll have to rewrite this script then.
Ho Nam Ernest Yim
Ho Nam Ernest Yim on 17 Jul 2018
Once again, thank you for all the help guys!! lots of appreciate!! I am trying to fix the logic of the code now. Thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!