Re: NDSolve and hybrid dynamics (Differential Algebraic Equation DAE)
- To: mathgroup at smc.vnet.net
- Subject: [mg113556] Re: NDSolve and hybrid dynamics (Differential Algebraic Equation DAE)
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Tue, 2 Nov 2010 05:02:50 -0500 (EST)
The equations are not the same if you change y[t] to y[x[t]]. Further, if you want the break in y[t] when x[t] is 0.1 then that must be the boundary condition on x rather than x[-Pi] == 0.5 eqns = {x'[t] == y[t] + Sin[t], y[t] == Piecewise[{{1, t < t1}}, 2], x[t1] == 1/10}; sol = {x[t], y[t]} /. DSolve[eqns, {x[t], y[t]}, t][[1]] // Simplify {1/10 - 2*t1 + Cos[t1] + Piecewise[{{t - Cos[t], t < t1}}, 2*t - Cos[t]], Piecewise[{{1, t < t1}}, 2]} Simplify[sol, t == t1] {1/10, 2} Solve[(Simplify[sol[[1]], t < t1] /. t -> t1) == 1/10, t1][[1]] {t1 -> 0} sol = Simplify[sol /. t1 -> 0] {11/10 + Piecewise[{{t - Cos[t], t < 0}}, 2*t - Cos[t]], Piecewise[{{1, t < 0}}, 2]} Plot[sol, {t, -5, 5}, Frame -> True, Axes -> False, Exclusions -> 0, ExclusionsStyle -> Red] Bob Hanlon ---- Ravi Balasubramanian <ravi.balasubramanian at yale.edu> wrote: ============= Thank you, Bob. I guess I oversimplified the original problem. The variable y is state-dependent such as y[x] := Piecewise[{{1, x < 1/10}}, 2] I tried the following system of equations, but it failed: eqns = {x'[t] == y[t] + Sin[t], y[t] == Piecewise[{{1, x[t] < 1/10}}, 2], x[-Pi] == 1/2}; sol = {x[t], y[t]} /. NDSolve[eqns, {x[t], y[t]}, {t, -5, 5}] NDSolve::ndsz: At t == -3.33251, step size is effectively zero; singularity or stiff system suspected. I presume this is what you meant by breaking the problem into two regions, but that transition is dependent on x. With your suggestion of using Piecewise, I was able to run the same system by creating a function y y//Clear y[xVar_?NumericQ] := Piecewise[{{1, xVar < 1/10}}, 2] eqns = {x'[t] == y[x[t]] + Sin[t], x[-Pi] == 1/2}; xSoln = NDSolve[eqns, {x[t]}, {t, -5, 5}][[1, 1, 2]] Plot[xSoln, {t, -5, 5}, Frame -> True, Axes -> False, PlotStyle -> Thick] Plot[y[xSoln], {t, -5, 5}, Frame -> True, Axes -> False, PlotStyle -> Thick] Is there a way that I can get NDSolve to manage the y variable for me as part of the state because my system will have multiple such non-smooth variables? Ravi Bob Hanlon wrote: > If is a programming construct not a mathematical function. Use Piecewise > > eqns = {x'[t] == y[t] + Sin[t], > y[t] == Piecewise[{{1, t < 1/10}}, 2], > x[-Pi] == 1/2}; > > sol = {x[t], y[t]} /. DSolve[eqns, {x[t], y[t]}, t][[1]] > > {(1/2)*(-1 + 2*Pi + 2*Piecewise[{{t - Cos[t], t <= 1/10}}, > -(1/10) + 2*t - Cos[t]]), Piecewise[{{1, t < 1/10}}, 2]} > > Plot[sol, {t, -5, 1}, > Frame -> True, > Axes -> False, > Exclusions -> 1/10, > ExclusionsStyle -> Red] > > For NDSolve break the problem into two regions > > > Bob Hanlon > > ---- Ravi Balasubramanian <ravi.balasubramanian at yale.edu> wrote: > > ============= > Friends, > > I am trying to solve a hybrid dynamics problem using NDSolve. > > I am aware that I could use the event locator methods in NDSolve and > manually take care of the transitions (set initial conditions etc). But > my system is complicated, and I would have to do a lot of book-keeping. > > The following represents a simplified version of the problem. > > eqns = {x'[t] == y[t] + Sin[t], y[t] == If[t < 0.1, 1, 2], > x[-Pi] == 1/2}; > sol = NDSolve[eqns, {x[t], y[t]}, {t, -5, 5}] > > It is a first order differential equation in x[t], but it includes a > y[t] variable that is discontinuous. There should be solution for this > problem, but I get the following error message from NDSolve. > > LinearSolve::"nosol" : "Linear equation encountered that has no solution. > > The error is probably arising from the "If" condition. > > FYI, in my real system the y[t] variable is a Lagrange multiplier that > is enforcing a constraint. Under certain conditions, that constraint is > broken and the system transitions into another state. It will be great > if this problem can be solved with NDSolve keeping track of the y[t] > variable for me. Any suggestions greatly appreciated. > > Thanks! > > Ravi Balasubramanian > Yale University >