通过功能自动检测工作空间变量之间的关系 [英] Automatic detection of relations between workspace variables through functions

查看:48
本文介绍了通过功能自动检测工作空间变量之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个函数来检测我在工作空间中获得的变量之间的这种关系:

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

v1 - fft(v2) = 0

其中v1,v2是我工作区的变量.

Where v1, v2 are variables of my workspace.

有时我需要知道哪些变量具有一定的数值​​关系.如果我有三十岁,我不想以手动方式"寻找这种关系,只需为每对不同的变量引入一个句子即可.

Sometimes I need to know which variables have a certain numerical relation. If I have thirty, I don´t want to be looking for this relation in "manual way", just introducing a sentence for each pair of different variables.

我想要一个函数,在其中引入(或在需要时修改此函数)句子(例如我之前写的内容),并且该函数向我显示我要查找的一对变量. 有人知道怎么做吗?

I would like a function in which I introduce (or I modify this function every time I need it) the sentence (for instance what I wrote before) and the function show me the pair of variables a I am looking for. Does anyone know how to do it?

推荐答案

您可以使用 who()以编程方式获取当前存在的变量列表.然后,您可以使用 eval()来获取其值.那时,您可以使用一个相当简单的嵌套循环来遍历所有可能的对,以寻找这种关系.

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.

注释1:使用eval()进行常规"编程被认为是不好的风格;它仅应真正用于此类元编程任务.

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

注2::如果工作空间中有N个变量,则有N^2个有序对.如果N很大,可能要花一些时间进行迭代.

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.

注释3:本质上是在寻找变量之间的相等性,这在浮点数中可能并不是特别可靠.

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

这篇关于通过功能自动检测工作空间变量之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆