A few suggestions… First: (1) bracket code chunks between triple back-ticks. This will give a “computer code” syntax. If you follow the opening three back-ticks by “julia”, I assume this will give possible Julia specific syntax. (2) bracket in-line code by single back-tick, without keyword “julia”.
Your line:
tval() = rand(range(0, stop=50, length=10000))
[notice typesetting of code chunk as described in point (1) above]
This function draws a random element from the list of time values [0,…,50]. OK.
Next, you create vector vec
(notice typesetting as described in point (2) above) by drawing 10_000
times from this function [syntax for doing this is comprehension]. So vec
contains 10_000
time points (?) in the interval (0,50), in artibrary order.
- Is this really what you want, or
- should the elements of
vec
be sorted?
If you mean that vec
should be time points when some ramping takes place, then it would seem more natural to sort the elements of vec
??
Your next code is:
ramp(x,t) = vec(t)
This won’t work. vec
is a vector, and not a function. The correct syntax to pick out elements from vec
is, e.g., vec[1]
to pick out the first element, etc.
[Perhaps you have seen some Julia code where you can choose between using vector syntax and function syntax, e.g., in solutions of differential equations, where you actually can write both sol[1]
and sol(1.5)
. But that possibility is created in a very specific way, and is not allowed in general. The way to create this dual vector and function syntax is to create your own data structure where sol
is a vector (or more generally: an array). Then, in that data structure, you can create a “functor” which is a function with the same name as the data structure. In DifferentialEquations
, this functor sets up a data interpolation of the elements in the solution array.
But you have not created such a data structure, and you can therefore not use function syntax on your array.]
If you instead want to convert vec
to a function, you would need to create a data interpolation function from vec
.
Anyways, it would be simpler to answer your questions if you explain what you want vec
to produce, and what ramp
should produce.