Jump to content

Calling sub-vi from formula node


Recommended Posts

Hi all,

is it possible to call a (sub)-vi from the formula node?

Motivation:

I would like to minimize a pretty complicated function that I have already coded in G.

I thought about using the "Conjugate Gradient nD.vi" which should be well suited for this problem. Unfortunately the vi needs a formula-string as input. My (already coded) function is full of matrix operations with complex numbers and I can't easily re-write it in the formula-string-style :-(

So it would be a great benfit if I could call my sub-vi from the formula-string.

Are there any other solutions than calling Matlab (which I don't have availible) from LabView?

Have a nice day,

Toni

X-Post to NI-LabView-Forum

Download File:post-2-1156834705.zip

Link to comment

I am sorry, my description of the problem was mistakable.

I attached a picture to better illustrate my problem. In the upper half the "Conjugate Gradient nD.vi" is used as described in the examples that ship with LabView and works just fine.

In the lower half of the picture I outlined what I would like to realize. Basically I want to do a curve fitting of a model to measurement values. So I would start a simulation with a rough guess of the variables which are fed into the simulation vi. After calculating the response of the model, the measured values care compared with the simulated ones and a cost function is caluclated. This cost function should be minimized by the "Conjugate Gradient nD.vi". The minimum output is fed into the simulatin vi again and after a few iterations the simulated values hopefully fit the measured values.

I cannot use the curve-fit vis that ship with LabView because I need a specialized model that I have to fit.

post-239-1108501035.jpg?width=400

Link to comment
I am sorry, my description of the problem was mistakable.

I attached a picture to better illustrate my problem. In the upper half the "Conjugate Gradient nD.vi" is used as described in the examples that ship with LabView and works just fine.

In the lower half of the picture I outlined what I would like to realize. Basically I want to do a curve fitting of a model to measurement values. So I would start a simulation with a rough guess of the variables which are fed into the simulation vi. After calculating the response of the model, the measured values care compared with the simulated ones and a cost function is caluclated. This cost function should be minimized by the "Conjugate Gradient nD.vi". The minimum output is fed into the simulatin vi again and after a few iterations the simulated values hopefully fit the measured values. 

I cannot use the curve-fit vis that ship with LabView because I need a specialized model that I have to fit.

3906[/snapback]

Hi Anton, what it sounds like you are looking for is a way to script LabVIEW. You should look at LuaVIEW, which allows one to create Lua scripts that can be accessed from LabVIEW. In other words, you can edit variables from the Lua script within a LabVIEW vi, you can call LabVIEW vi's from within the Lua script, and you can even edit a script as a string within a LabVIEW vi and then execute it! Dynamic scripting allows you to do some pretty powerful things. Unfortunately LuaVIEW would be more complicated than a simple formula-node and has a learning curve, but it's capability is far greater.

The Lua language is a pretty cool and simple high-level language that is amazingly powerful in light of it's simplicity. It's a functional programming language, which basically means that functions are like variables, so you can use them in your data structures. It's primary use is to add scripting capability to other software packages, for example its currently the workhorse in the gaming industry to program the 'intelligence' of computer-controlled characters.

Link to comment

If you want to least-square fit a model equation to a data set, I think what you need is Non-Linear Lev-Mar Fit.vi

Edit the VI Target Fnc & Deriv NonLin.vi to compute the model equation F(x;a) where a is the set of parameters to adjust for minimization. You are not limited to use formula nodes to compute the result.

If F(x;a) is linear relative to a (e.g. F(x;a) = a1*sin(x) + a2*exp(-x) +a3*...) you can use General LS linear Fit.vi.

If your cost function is not a least-square, then maybe you should expose your problem with more details to see if we could find a solution.

Link to comment

Hi Jeff, hi Jean-Pierre,

thanks for your suggestions.

@Jeff: Thanks for bringing Lua into my scope; I wasn't ware of it. I will still try using G if possible because I have the feeling that I should get more comfortable to the possibilities of LabView unless I try something else.

@Jean-Pierre: I wanted to try different cost-functions but you are right I will start with least-square.

I will reply if I figured out more.

Toni

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.