Function handle in a if statement
조회 수: 7 (최근 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!