0
|
10378 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
GROUPS:

Why does the solution contain imaginary number?

Posted 9 years ago
 Dear All, I have the below equation: sol = NDSolve[{q'[t] == (a q[t]^b newefr[t] - q[t]) + (a q[t]^b (newefr[t] - newefr1[t])), q[1] == 0.001}, q, {t, 1, 456}]  Then I want to extract the value of q for each time step by using below command:  Evaluate[q[t] /. sol]  For example for t=430: Evaluate[q[10] /. sol] result: {-8.60556*10^-13 - 1.18404*10^-16 i}  So may I know why does the solution contain imaginary number? Thanks in advance! Best Regards, Intan
4 Replies
Sort By:
Posted 9 years ago
 The imaginary value here is just Floating point noise. Happens all the time. You can use the function Re to take the real part of this or you can use Chop to set small values to zero.
Posted 9 years ago
 I would expect it to depend on what are the values/definitions of a, b, and newefr. None of which are shown in the question (making it effectively impossible to do more than speculate).
Posted 9 years ago
 Dear Sean,Thanks for your advices. I will try it out.For Daniel: Thanks for your comments. Herewith the values of those variables: a and b are constant values where a is 117.59 and b is 0.006286. As for newfr:  newefr = Interpolation[newefrain, InterpolationOrder -> 1] where: newefrain = Table[rainfun[t]*ff, {t, 1, 456}] and the outcome of newefrain is Out[51]={0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0.0782492, 0.0260832, 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0.782994, 1.04651, 0.13087, 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.078543, \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 2.38616, 0.585842, 0., 0.0266348, 0.454486, 0., \ 0.0534934, 0., 0., 0., 0.402633, 0.35009, 0.814511, 0.409046, \ 0.300972, 0.302013, 0.275445, 0.97566, 0.335963, 0., 0.0560349, 0., \ 0.168478, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0.225311, 0.539042, 0., 0., 0., 0., 0., 0., 0., 0., \ 0.142133, 0.775951, 4.71685, 6.55095, 6.29473, 3.17511, 1.15515, \ 0.481163, 0.403179, 0.0807243, 0.161803, 0.0809903, 0.243771, 0., \ 0.16287, 0., 0., 0., 0., 0.0407397, 0.0407619, 0., 0., 0., 0.204367, \ 0.204925, 0.0820594, 0.288304, 0.289402, 0.248868, 0.0415004, \ 0.124704, 0.0832257, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0.125041, 0., 0., 0.0834509, 0., 0., 0., 0., 0., 0.0835411, 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.125515, \ 0.420641, 0.550661, 0.254968, 0.0425175, 0., 0.170433, 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 2.23244, 0.44003, 0., 2.16525, 3.31956, 0.281362, 0., \ 0., 0., 0., 0.0938803, 0., 0., 0., 0., 0., 0., 0., 0., 0.0939732, 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0.0470098, 0., 0., 0., 0.0941125, 0.141378, 1.24098, \ 0.479622, 0.240392, 0., 0.0481016, 0.3863, 0.242018, 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.} Thanks for your attention. Best Regards, Intan.
Posted 9 years ago
 Are you able to run the NDSolve using exactly the information shown in this thread? I cannot.
Community posts can be styled and formatted using the Markdown syntax.