Skip to main content

differential equations - Strange DAE solution


I have a system, consisting of one differential equation and one algebraic equation


req = (1 - xD)/τD - δxD xD ν;
ν = νmax (2/(1 + Exp[(-2 (u - u0))/kv]) - 1);
eqh = u == Istim + gE ν (xD - 0.5);
τD = 2; δxD = 0.01; νmax = 100; u0 = 150; kv = 20; \
Istim = 126; gE = 5;
eqs1 = xD'[t] == (req /. {xD -> xD[t], u -> u[t]});
eqs2 = eqh /. {xD -> xD[t], u -> u[t]}

ics = xD[0] == 0.99;

I try to solve it with the next command:


eqsol = NDSolve[{eqs1, eqs2, ics}, {xD[t], u[t]}, {t, 0, 1}];

Then I want to make sure that this is correct solution, so I plot both variable xD[t] and u[t] and expect to find them on the curve defined by implicit equation from the system.


ParametricPlot[Evaluate[{u[t], xD[t]} /. eqsol], {t, 0, 1}, 
PlotRange -> Full]

I also can plot that curve by expressing the variable xD[t] as a function of the variable u: xD=xD(u).



xDimp = Solve[eqh, xD];
Plot[Evaluate[xD /. xDimp], {u, u0, 300}]

But I found that these curves don't coincide with each other. I suspect that the integration was executed wrong, but no errors were displayed during the integration. By observing the apt derivative I investigated that the function u(t) can be explicitly found from the implicit equation only for xD>0.54. This solution satisfies me. Due to this constraint I set the initial value as xD=0.99. But shall I define this constraint explicitly? Or else I don't know where the error can be.



Answer



Your equation set actually has 3 solutions. Just enlarge the domain of definition of Plot a bit:


curve = Plot[Evaluate[xD /. xDimp], {u, -300, 400}, 
Epilog -> {Dashed, Line[{{-300, 0.99}, {400, 0.99}}]}]

Mathematica graphics



Clearly there're three possible values of u that satisfys the i.c. xD==0.99. What's found by NDSolve automatically is the leftmost one:


solplot1 = ParametricPlot[Evaluate[{u[t], xD[t]} /. eqsol], {t, 0, 1}, PlotStyle -> Red];

curve~Show~solplot1

Mathematica graphics


Why does NDSolve find the leftmost one only? The answer is hidden in the obscure tutorial tutorial/NDSolveDAE#1966826857. In short, since the i.c. for u isn't explicitly given in the code, NDSolve will try to determine it from an initial guess u[0] == 1, which converges to the leftmost solution in this case.


To make NDSolve converge to other solutions, we need to use other initial guesses:


eqsol2 = NDSolve[{eqs1, eqs2, ics}, {xD[t], u[t]}, {t, -1, 1/2}, 
Method -> {"DAEInitialization" -> {"Collocation",

"DefaultStartingValue" -> #}}][[1]] & /@ {-120, 150, 400}

solplot2 = ParametricPlot[Evaluate[{u[t], xD[t]} /. eqsol2], {t, -1, 1/2},
PlotStyle -> {Green, Orange, Red}];

curve~Show~solplot2

Mathematica graphics


If you don't want to play with those options, explicitly giving i.c. of u to NDSolve is OK, of course:


ustart = u /. FindRoot[eqh /. xD -> 0.99, {u, #}] & /@ {0, 160, 300}

(* {-119., 152.142, 371.} *)
eqsol3 = NDSolve[{eqs1, eqs2, ics, u[0] == #}, {xD[t], u[t]}, {t, -1, 1/2}][[1]] & /@
ustart

Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

equation solving - Invert and fit implicitly defined curve

I need to fit an implicitly defined curve. I thought I could get some data out of Solve , and then using FindFit . Therefore, I would like to find the relation the parametric curve defined by $F(x,y)=0$: Solve[-(1/2) + 1/2 (0.41202 BesselK[0, 0.1 Sqrt[x^2 + y^2]] + (0.101483 x BesselK[1, 0.1 Sqrt[x^2 + y^2]])/Sqrt[x^2 + y^2]) == 0, y] But I can't get an output: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >> Edit: In particular, I would like to fit the data coming from the curve with the expression of another curve, and not with a function $f(x)$. In particular, since this clearly looks like a cardioid , I would like it to fit to something like it. What other strategies could I try?

dynamic - How can I make a clickable ArrayPlot that returns input?

I would like to create a dynamic ArrayPlot so that the rectangles, when clicked, provide the input. Can I use ArrayPlot for this? Or is there something else I should have to use? Answer ArrayPlot is much more than just a simple array like Grid : it represents a ranged 2D dataset, and its visualization can be finetuned by options like DataReversed and DataRange . These features make it quite complicated to reproduce the same layout and order with Grid . Here I offer AnnotatedArrayPlot which comes in handy when your dataset is more than just a flat 2D array. The dynamic interface allows highlighting individual cells and possibly interacting with them. AnnotatedArrayPlot works the same way as ArrayPlot and accepts the same options plus Enabled , HighlightCoordinates , HighlightStyle and HighlightElementFunction . data = {{Missing["HasSomeMoreData"], GrayLevel[ 1], {RGBColor[0, 1, 1], RGBColor[0, 0, 1], GrayLevel[1]}, RGBColor[0, 1, 0]}, {GrayLevel[0], GrayLevel...