Automatic detection of relations between workspace variables through functions

前端 未结 1 1711
情话喂你
情话喂你 2021-01-28 07:54

I\'m trying to write a function what detect this relation between the variables I have got in the workspace:

v1 - fft(v2) = 0

Where v1, v2 are

相关标签:
1条回答
  • 2021-01-28 08:41

    You can use who() to programatically obtain a list of variables that currently exist. You can then use eval() to get their values. At that point, you can use a fairly trivial nested loop to iterate over all possible pairs, looking for that relationship.

    Note 1: Using eval() for "normal" programming is considered bad style; it should only really be used for meta-programming tasks like this.

    Note 2: If you have N variables in the workspace, there are N^2 ordered pairs. This may take a while to iterate over if N is large.

    Note 3: You're essentially looking for equality between variables, which may not be particularly reliable in floating-point.

    0 讨论(0)
提交回复
热议问题