I have to solve a series of differential equations along with a constraint that has to be satisfied at each point of time. To solve the differential equations, I first solves the following in order to obtain ?(t) and x(t)
sol1 = NDSolve[{?'[t] == -((c1^2 - 4*k1*?*?[t] -
2*c1*(?[t] + ?) + (?[t] + ?)^2)/(
4 k1)), x'[t] == -((c2^2 - 4*k2*(?*x[t] + ?1 (x[t] - [Lambda][t])) - 2*c2*(x[t] + ?) + (x[t] + ?)^2)/(4 k2)), ?[T] == 0, x[T] == 0}, {?, x}, {t, 0, 100}];
Then using those values I calculate ?1(t) and ?2(t)
?1[t_] := (c1 - {?[t] /. sol1} - ?)/(2*k1);
?1[t][[1, 1]];
?2[t_] := (c2 - {x[t] /. sol1} - ?)/(2*k2);
?2[t][[1, 1]];
Having ?1(t) and ?(t), ?2(t) and x(t) I solve the following differential equations where
d[t_] := a + b*Sin[(2*?*t)/25];
s = NDSolve[{y3'[t] == d[t] - ?2*y3[t], y2'[t] == ?2*y3[t] - (?1 - ?2[t][[1, 1]]) y2[t], y1'[t] == ?1*y2[t] - ?1[t][[1, 1]]*y1[t],
y3[0] == Subscript[y, 0], y2[0] == Subscript[y, 0],
y1[0] == Subscript[y, 0]}, {y3, y2, y1}, {t, 0, 100}];
Now I have to check if the constraint is the satisfied, the constraint is the following: if
d[t] - (?1[t]*{y1[t] /. s} + ?2[t]*{y2[t] /. s}) >= 0
then ? == 0
Otherwise calculate the ?(t) from below
? == (-2*d[t]*k1*k2 + c1*k2*{y1[t] /. s} + c2*k1*{y2[t] /. s} - k2*{y1[t] /. s}*{?[t] /. sol1} - k1*{y2[t] /. s}*{x[t] /. sol1})/(k2*{y1[t] /. s} + k1*{y2[t] /. s})]
and then I have to solve everything with the new value of ?.
The model parameters are
? = 0.1; c1 = 10; c2 = 30; k1 = 100; k2 = 300; T = 100; \
?1 = 0.1; ?2 = 0.3; Subscript[y, 0] = 1000; a = 4000; b \
= 200;
Is there anyways to code this model to check for ?(t) and assign the value for it based on the defined condition? I also need to plot d[t] - (?1[t]*{y1[t] /. s} + ?2[t]*{y2[t] /. s})
to see for what intervals my constraint is violated.
p.s. I'm using mathematica v.9.0. Thanks in advanced for any help