Conditional statement problem in ODE code in Matlab

  • MATLAB
  • Thread starter musikmaniac
  • Start date
  • #1
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!!!
 

Answers and Replies

  • #2
Wrichik Basu
Insights Author
Gold Member
2020 Award
1,755
1,575
Your statements are syntactically wrong. Each if-else should have used &&:
if((yY(1)<=Y(1)) && (Y(1)<yY(2)))
 

Related Threads on Conditional statement problem in ODE code in Matlab

  • Last Post
Replies
14
Views
5K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
3
Views
4K
Replies
3
Views
4K
  • Last Post
Replies
0
Views
4K
  • Last Post
Replies
3
Views
1K
  • Last Post
Replies
4
Views
4K
  • Last Post
Replies
6
Views
2K
Replies
0
Views
15K
Top