I'm currently trying to simulate a step response in a simple tank system with NDSolve. I would like it to start at say time 2 (the precise time is not important). As an example I use here a very simplified system
Controller[t_] := 100*UnitStep[t - 2]/(1 + t^2);
eqs1 = {V0'[t] == 3/(t^2 + 1) + Controller[t]};
init1 = {V0[0] == 2};
sol1 = NDSolve[{eqs1, init1}, {V0}, {t, 0, 10}];
Plot[Evaluate[{V0[t]} /. sol1], {t, 0, 10}]
Both this and the system without controller work perfectly fine.
But what if I wanted to use as a coefficient for UnitStep a value taken from a list instead of a fixed value?
I would like to pick a value from a list of pre-generated inputs for the coefficient, based on the current time. So as an example if I had a list of 11 elements
inputlist={5, 2, 5, 10, 3, 7, 2, 7, 4, 8, 2}
How could I tell Mathematica to pick up one of these values (sequentially if possible)? I tried
Controller[t_] := inputlist[[Round[t+1]]]*UnitStep[t - 2]/(1 + t^2);
But it doesn't work and gives the error
The expression
Round[1+t]cannot be used as a part specification.
Is there a clean way to step over a list like that inside NDSolve?
Controller[t_?NumericQ]:=..should solve the issue! – PlatoManiac Jan 28 '15 at 12:47Controller[t_?NumericQ]:=..is that it always evaluatesfalse, so no input is ever given in the execution. The system remains without disturbance. – Kratos Jan 28 '15 at 14:55t_?NumericQshould be the solution to your problem (it works for me). Why do you think it always returnsFalse? It clearly does not for me. You have to do aClearAll[Controller]before making the new definition, otherwise the old definition will be still used for non-numeric arguments. I would finally suggest to use function names starting with lower case letters for your own functions (e.g.controllerinstead ofController), there is a danger of conflicts with system symbols otherwise... – Albert Retey Jan 29 '15 at 09:42