0

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?

Kratos
  • 45
  • 6
  • 1
    I guess Controller[t_?NumericQ]:=.. should solve the issue! – PlatoManiac Jan 28 '15 at 12:47
  • The problem with Controller[t_?NumericQ]:=.. is that it always evaluates false, so no input is ever given in the execution. The system remains without disturbance. – Kratos Jan 28 '15 at 14:55
  • @antonio 1)Are you sure that this is a model of a tank system. See http://wolfram.com/xid/0jvpj762zmgvepb9y3y1-veaqch, Bernoulli's law does not end up with the equation you have. 2) Are you mixing discrete- and continuous-time dynamics? – Suba Thomas Jan 28 '15 at 15:48
  • 2
    I think that t_?NumericQ should be the solution to your problem (it works for me). Why do you think it always returns False? It clearly does not for me. You have to do a ClearAll[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. controller instead of Controller), there is a danger of conflicts with system symbols otherwise... – Albert Retey Jan 29 '15 at 09:42
  • 4
    I agree with Albert Retey, please take a look at this topic, especially that answer – Kuba Dec 17 '15 at 21:58

0 Answers0