I am trying to generate a lambda
programmatically. This is an example:
This is the matrix that I need to generate:
m = [[a(t), b(t)],
[c(t), d(t)]]
This is a time dependent matrix. If the a
, b
, c
, d
functions were always the same I would create a lambda like this:
m = lambda{|t| [[a(t), b(t)], [c(t), d(t)]]}
and call it with:
m.call(x)
The functions are not completely general, but they can come only from a limited list. The problem is that I don't know which ones, from this list, the functions are going to be before I perform some calculations. In my case, for example, I have only three possible functions, so the lambda could be:
m = lambda{|t| [[f1(t), f2(t)], [f2(t), f3(t)]]}
or
m = lambda{|t| [[f3(t), f3(t)], [f1(t), f2(t)]]}
or any other combination of the three functions.
Is there a way to define lambdas
programatically? Is this the best approach?
In the real code this matrix could be quite large, easily 500x10,000 (500,000) elements. It is calculated in a first loop. After that the loop goes through t
values. For each t
the functions do not change of course.
Also, these functions are simple mathematical expressions such power, exp, etc...