MATLAB Conditional statement problem in ODE code in Matlab

I am new in matlab and recently, I have tried coding in matlab. So far, I have been getting error msg

"Warning: Failure at t=2.859413e+002. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (1.015868e-012) at time t."

I have referred back to my codes and realized that the problems occurs due to the conditional statement. To cut the story short, the ode doesn't seem to want to read the if, else-if statement in my codes.

e.g

if yY(1)<=Y(1)<yY(2)
hY = -0.0014*(Y(1)-yY(1))^3+ 0.0200*(Y(1)-yY(1))^2+ 0.8515*(Y(1)-yY(1));
elseif yY(2)<=Y(1)<yY(3)
hY = -0.0014*(Y(1)-yY(2))^3+ 0.0151*(Y(1)-yY(2))^2+ 0.8935*(Y(1)-yY(2))+ 1.0431;
elseif yY(3)<=Y(1)<yY(4)
hY = -0.0012*(Y(1)-yY(3))^3+ 0.0088*(Y(1)-yY(3))^2+ 0.9306*(Y(1)-yY(3))+ 2.4600;
else
hY = 1.0000*(Y(1)-yY(19))+ 510.8083;
end

It only wants to read the first highlighted piece of the code.

Anyone help please!!!
 

Wrichik Basu

Gold Member
2018 Award
907
759
Your statements are syntactically wrong. Each if-else should have used &&:
if((yY(1)<=Y(1)) && (Y(1)<yY(2)))
 

Want to reply to this thread?

"Conditional statement problem in ODE code in Matlab" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top