LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Variables in the ode solver function for MathScript

Solved!
Go to solution

Hi

 

I am using LabView for a long time now and I started to use the more text based tools. To solve a system of differential equations there is this quite elegant tool to do this in a MathScript Node with the ode solve algorithms (for example "ode_adams"). As the LabView help says, I defined a function and saved it as a .m file. I loaded this function in mathscript and it solve the differential equations.

 

So far so good, but my problem is that I can't get any variables into the function. I can only put numbers in the function but no variables. Unfortunatly I need to define the variables outside the function in the MathScript node.

 

Does anyone have an idea how to handle the variables in this case?

I attatched a picture of the function and the test VI (LV2014).

 

Greetings

Download All
0 Kudos
Message 1 of 5
(3,346 Views)

Hi

 

It seems that there is not an obvious solution for you guys ether. Or maybe I did not the explain it well enough.

After I figuered out how to post pictures directly, here an update:

 

 

This is how it looks like: In the MathScript Node the differential equation system defined in the .m file "model" is solved by the ode solve function. I can give the solver the starting times and the parameter NX. I would like to give it the parameter k12 and k23, too. Unfortunatly I still could not figure out how.

MathScriptNode_ODE_Test.jpg

 

This is how the function "model" in the .m file looks like. To make it work, I had to define the k parameter as a number inside the function. It works, but it is cumbersome to change the numbers in an external function if I want to include the solver in a Labview program.

Function_model.jpg

 

I'm pretty sure there has to be a way to define the parameter in the MathScript note and give it to the function. I probably just fail on the syntax.

If anyone has any idea, please let me know.

 

Greetings

 

PS: This is what the LabView help states about the ode solver. Does not the say anything about using additional variables.

LabViewHelp_ODE.jpg

0 Kudos
Message 2 of 5
(3,257 Views)

But you can use k12, k23 in mathscript node. Then it is Matlab forum question, not labview.

But general considerations: Are they not local for this function only, and not accessible in model function?

Can you add intermediate global matalb variable that will be accessible inside model?

You are passing N and times as parameters, why can not you do the same with k-s? Who can prevent you from joining k-s and Ns? 

 

 

'model', [t0 tend], [N1 N2 N3 k12 k23]

Message 3 of 5
(3,249 Views)

Thanks for the answer.

 

Your right, I can use the variable in the mathscript node, but the values are not transfered to the external function. I can set them whatever I want, the ones defined in the function are used.

 

To define these as global variables is a good idea. I'm going to try this.

 

The ODE solver prevents me from doing this: 'model', [t0 tend], [N1 N2 N3 k12 k23]. If there are three Ns definded in the differential equation system, it wants three values. Otherwise it gives an error that the size of the vector does not match the parameter number definded in the function.

 

Greetings

 

 

0 Kudos
Message 4 of 5
(3,245 Views)
Solution
Accepted by topic author Karido

Global variables solve this problem:

 

Solution:

Variablen_ODE_MathScript.jpgGlobal_Function.jpg

 

Greetings

Message 5 of 5
(3,232 Views)