Using time t as a input in functions?

7 views
Skip to first unread message

Wei, Jingjin

unread,
May 6, 2019, 5:16:20 PM5/6/19
to DynaSim Users
Hi dynasim users,

I was trying to use time t in a custom function, but it seems that it doesn't work. Code is like:

output_value = function(t);

And the function could simply be output = input, so it's not about a bug in the function.

Error saying Undefined function or variable 't'.

My question is does dynasim not allow this, and is the workaround putting t related variable in the final equation, not in a separate line using a custom function?

Best,
Jingjin

Erik Roberts

unread,
May 6, 2019, 5:29:54 PM5/6/19
to Wei, Jingjin, DynaSim Users
IIRC there’s 2 options, depending on if you want the whole time vector at once (option 1), or the individual time points (option 2)

1)
```
output_value = function(T)
```

or
2)
```
output_value(t) = function(t)
```

-Erik


-- 
You received this message because you are subscribed to the Google Groups "DynaSim Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynasim-user...@googlegroups.com.
To post to this group, send email to dynasi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dynasim-users/BN7PR03MB36334781D2141F87CFD3D852A7300%40BN7PR03MB3633.namprd03.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Wei, Jingjin

unread,
May 6, 2019, 5:39:12 PM5/6/19
to Erik Roberts, DynaSim Users
Hi Erik,

I tried option 2, 'Index exceeds matrix dimensions'. Well the output here is a scaler, so the error message makes sense since in output(t) t is treated as a index.

Best,
Jingjin

From: dynasi...@googlegroups.com <dynasi...@googlegroups.com> on behalf of Erik Roberts <erobe...@gmail.com>
Sent: Monday, May 6, 2019 5:29 PM
To: Wei, Jingjin
Cc: DynaSim Users
Subject: Re: [DS] Using time t as a input in functions?
 

Jason Sherfey

unread,
May 6, 2019, 7:09:00 PM5/6/19
to Wei, Jingjin, Erik Roberts, DynaSim Users
Hi Jingjin,

I'm not totally sure what you're trying to do, but here are some tips on how dynasim treats some time variables:

  • "T" will be replaced by the complete time vector computed before simulation.
  • "t" will be replaced at each time step during integration by the current time (a scalar value in milliseconds).
  • "k" will be replaced at each time step during integration by an index value for the current time step.

For instance:
Using the k index:
input = get_input(options); % obtain input vector for the entire simulation (before integration begins)
dV/dt = input(k) + ...; % obtain the k-th value of the input vector during the k-th integration step

Using the t variable:
input(t) = sin(2*pi*t/1e3); % obtain scalar input value at a given time point "t"
dV/dt = input(t) + ...; 

Hope this helps.

Cheers,
Jason


Wei, Jingjin

unread,
May 6, 2019, 9:43:54 PM5/6/19
to Jason Sherfey, Erik Roberts, DynaSim Users
Hi Jason,

I forgot to reply all, it was solved. Thanks!

Best,
Jingjin

From: dynasi...@googlegroups.com <dynasi...@googlegroups.com> on behalf of Jason Sherfey <jssh...@gmail.com>
Sent: Monday, May 6, 2019 7:08 PM
To: Wei, Jingjin
Cc: Erik Roberts; DynaSim Users
Reply all
Reply to author
Forward
0 new messages