Message Boards Message Boards

0
|
4599 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Little Bit of Help with NDSolve

 khi = 100
 Kc = 21
 nc = 5
 nut = 46
 a = .5
 
 30
 
 100

21

5

46

0.5

ode = khi*(1/(1 + (C[t]/Kc)^nc))*nut - a*C[t]

-0.5 C[t] + 4600/(1 + C[t]^5/4084101)

NDSolve[{C'[t] == ode, C[0] == 30}, C[t], {t, 0, 31}]

{{C[t] -> \!\(\*
TagBox[
RowBox[{"InterpolatingFunction", "[",
RowBox[{
RowBox[{"{",
RowBox[{"{",
RowBox[{"0.`", ",", "31.`"}], "}"}], "}"}], ",", "\<\"<>\"\>"}], "]"}],
False,
Editable->False]\)[t]}}
I have been having an issue with the above code, I got the solution to work yesterday and when I logged in this morning to tweak it a little bit, I was back to square one getting error messages about the first list of equations in the NDSolve. Is there anyone who could help me fix this?
POSTED BY: Josh Wofford
2 Replies
Posted 11 years ago
1: There have been long standing, but rare, problems with not having a semicolon between individual expressions. It seems to have never been possible to track down exactly when or why these rare problems will appear, but when they do the problem is often very difficult to recognize. So to be cautious I use and recommend others use a semicolon between every expression, unless you know exactly why and when to not use this rule.

2: In the name of efficiency Mathematica remembers the last value assigned to each variable, sometimes for minutes or hours or years depending on how often you exit Mathematica or click on Evaluation->Quit Kernel->Local Kernel->Quit. Mathematica will silently assume you expect to use that previously stored value and will give no obvious hint that it has done this. This can greatly speed things up and under other circumstances can silently lead to incorrect results or no result at all. This leads to the classic IT department question "Did you try turning it off and back on again?" Or you can use the Clear directive to remove specific prior assigned values. There are even things above, beside and beyond Clear, like ClearAll, Unset, ClearAttributes and Remove that you might take a look at, but the implications of some of those might not be completely transparent. If you had somehow previously assigned some value to C[ t ] or C'[ t ] this might have explained why it wasn't working for you, but it seems that it is amost never possible to track down exactly why something like this actually specifically didn't work.

3. Many many names that begin with a capital letter have deep preassigned meaning inside of Mathematica and using those as user defined variables can often lead to warning messages you don't know how to interpret or incorrect results or even nothing at all. This leads to the classic Mathematica advice "don't start any user variable with an uppercase letter" which is rarely followed by "unless you really know what you are doing. You can also check in the help system for a name and see if it has predefined meaning. C for some usually integer n is one such predefined name.

Combining all these.
 In[1]:= Clear[khi, Kc, nc, nut, a, ode,c];
 khi = 100;
 Kc = 21;
 nc = 5;
 nut = 46;
 a = .5;
 ode = khi*(1/(1 + (c[t]/Kc)^nc))*nut - a*c[t];
 NDSolve[{c'[t] == ode, c[0] == 30}, c[t], {t, 0, 31}]
 
Out[8]= {{c[t] -> InterpolatingFunction[{{0.,31.}},<>][t]}}
See if you can find any circumstance where this fails, and if so then please report back so I can enhance my set of superstitions and folklore and guidelines for the future.
Thanks
POSTED BY: Bill Simpson
Ok, so after taking a break and reopening the notebook, the code decided it wants to work again. Any advice though would be appreciated.
POSTED BY: Josh Wofford
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract