Function handle in a if statement
8 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
OCDER
2018 年 7 月 17 日
編集済み: OCDER
2018 年 7 月 17 日
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 件のコメント
OCDER
2018 年 7 月 17 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!