# How to properly use conditionals inside NDSolve

Currently I am working with Mathematica to learn the program, and I'm confused what exactly is wrong with this code.

s = NDSolve[{if[t < 1, Derivative[1][Ca][T] == -10*Ca[T] + 2 T,
Derivative[1][Ca] == -10*Ca[T]],
Derivative[1][Cb][T] == (10*Ca[T]) - 0.192, Ca[0] == 0,
Cb[0] == 0}, {Ca[T], Cb[T]}, {T, 0, 10}]


What I'm trying to do is set a conditional for the Ca derivative so that if T < 1 then it goes in the first derivative, but if not, it'll go in the second derivative.

Can anyone help me with this? Thanks.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Apr 26 '15 at 23:52
• You can format inline code and code blocks by selecting it and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. – Michael E2 Apr 26 '15 at 23:53
• Please note that precise and accurate syntax is essential for any programming language. In Mathematica, built-in symbols and functions start with capital letters, such as If. It is better to avoid starting your own variable and function names with a capital (i.e. avoid T, but especially built-in functions like D and N). – Michael E2 Apr 27 '15 at 0:03

Use Piecewise for discontinuous right-hand sides and coefficients. If, with a capital I, more a programming construct than an algebraic/functional one. NDSolve does discontinuity processing, which improves error estimation and step size when done accurately; using Piecewise helps with that.
s = NDSolve[{