该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
here is the problem:
if x(4)>=0 & x(4)<=0.5 (1)
a=cos(pi*x(4)); (2)
elseif x(4)>=0.5 & x(4)<=1 (3)
a=0; (4)
else return; (5)
i don't know how do you define the region of x(4), but
problem 1:the statement (1) and (3) are conflict as x(4)<=5 and x(4)>=5
problem 2: (1) and (3) only state the value a when 0.5<= x <= 1
what happen when x(4) is out of this region? Matlab doesn't know what to do when x(4)> 1; thus, the command [T2,X2]=ode45(@myode,[0,10],[4;2;4/3;0])
won't work.
i changed your codes in line (5): else a=0; it appears that x(4) IS bigger than 1, when x(1)=4.
so, here is my guess:
1) you forgot put the conditions when x(4)1
2) if you correctly define the boundaries of x(4), then it only has one explanation: based on your system, the initial value of x(1) only have slight fluctuation about 1.5; that's x(1) has to be around 1.5 with very little difference.