필터 지우기
필터 지우기

MATLAB executing else block in event locator function even though if condition is true

조회 수: 1 (최근 30일)
I am trying to simulate a two-tank liquid level problem. One of the 'states' (control engg. terminology) is defined by a differential equation that I am integrating using ode45. The integration stops when the associated event function gets value=1 based on a condition [which is that the difference between the liquid levels in both tanks is less than a certain value(0.001)]. While debugging I see that the if condition evaluates true after certain number of iterations but MATLAB still executes the else block thus making the integration endless.
UPDATE:It looks like it is executing the if block now but the integration is not terminating even though value=1 is executed. Here is the code:
%ODE function
function hdot = q4_ode_func(t, h)
constants;
hdot=zeros(2,1)
h1=h(1); h2=h(2);
diff1=h1-h0;
diff2=h1-h2;
if(diff1>0)
Qv1=1;
else
Qv1=-1;
end
if(diff2>0)
Qv2=1;
else
Qv2=-1;
end
hdot(1) = (1/A)*(-Qv1-Qv2);
hdot(2) = (1/A)*(Qv1+Qv2);
%Event locator function
function [value,isterminal,direction] = q2
constants;
if h(2)<4.8
value=1;
else
value =0;
end
isterminal = 1;
direction = 0;
end
  댓글 수: 1
Image Analyst
Image Analyst 2017년 1월 18일
Just how is function q2 supposed to get array h when h is not passed into it via the argument list, nor is it a global variable, nor do you get it via getappdata()?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Naming Conventions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by