From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

help with syntax of ode_bdf15

Hello,

 

I would like some help with the syntax of my mathscript function.  I created an m file and saved it as a function with the following inputs:

 

function dosc = osc_dy(t,osc,param)

 

param is a cluster of elements, t is the current time, and osc is the variable that I am trying to solve.  So when I feed a fake set of data to the function, I confirm that the function is working as intended in my mathscript code.  Now I would love to use it in my ode_bdf15 function to solve for the OSC parameter, so I set it up as follows:

 

[t,OSC] = ode_bdf15(osc_dy(t,OSC,param),param.tspan,y0);

 

mathscript then promptly has a hard time compiling after adding this code, so I figure something is wrong with my script.  In addition, it says that OSC is not defined.  If I trick it and put this in the code:

 

OSC = ones(10,1);

 

the error code goes away, but it still has problems compiling.  I've also supplied a solution to the vector that I am trying to solve for...

 

Unfortunately, the code is proprietary so I cannot send it out here.

 

I appreciate any help,

Matt

 

0 Kudos
Message 1 of 10
(8,581 Views)

Hi,

 

Unfortunately, the MathScript RT does not support additional parameter inputs in user-defined function for ODE functions.

 

http://zone.ni.com/reference/en-XX/help/373123C-01/lvtextmath/msfunc_ode_bdf15/

Message 2 of 10
(8,568 Views)

well, that's a problem for me.  Is there a sneaky way to pass this param variable to the function?  Maybe a global variable?

0 Kudos
Message 3 of 10
(8,557 Views)

Hey Matt, 

 

It would depend on what that extra parameter actually is, but you could feasibly script a more specific function that only need the two parameters then use that. 

For example, if the extra parameter determines the coefficients of the function you could modify the .m file programatically before calling the ode function so that the function already has that parameter applied. 

 

Does that sound feasible? 

 

Let me know, 


Zach

Applications Engineer
National Instruments
CLD Certified
0 Kudos
Message 4 of 10
(8,538 Views)

it is a structure variable in matlab.  I find with 2011 and beyond, the mathscript will accept a cluster and I can use that for my structure in my code.  However, in the Matscript Window, it seems that I cannot reference the cluster via param.tspan, or any of the parameters with a "." after param.  Gonna google that now, but maybe someone can tell me?

 

I was also told here that maybe if I had both the function that I have in the Matscript labview code and the osc_dy function back to back in the Mathscript window, that I may not need to pass the param variable to the osc_dy... is this true?

 

Thanks,

Matt

0 Kudos
Message 5 of 10
(8,536 Views)

I got it to partially work!!  I at least got the ode_bdf15 function to work by following this:

 

OSC = ode_bdf15('osc_dy', param.tspan,y0,options)

 

where now the osc_dy function is only osc_dy(OSC,t)

 

 

I am now stuck on sending this param structure variable throughout the code!  ARGH!  This is how I have it now:

 

labview vi feeds all necessary variables to mathscript node.

 

Mathscript node calls TransientSensor(t, Qin, Tin, Lin, Ldata, hdata, param) which is a defined function in an m file from the mathscript window.

 

Soon as I'm in the function, I declare param to be a global variable, by stating:

 

global param;

 

BUT, the first time I get to use param, I get that I cannot use the "." unless the variable is a structure, which I think it is!  So this code here:

 

param.d

 

gives me an error.  Really long-winded question, but this is it:  How do I get it to realize that I am using a structure so that this global param structure can be used?

 

Thanks everyone!

Matt

0 Kudos
Message 6 of 10
(8,518 Views)

I figured out that if I claim the code "global param" it negates the feed wire in, not allowing me to use the ".".  So this worked:

 

global param_struc;

param_struc = param;

OSC = TransientSensor(...,...,...,param_struc);

 

BUT the ode function that is calling my m file still only accepts 2 parameters, so I still cannot use the global param in the external m function.

 

This is really frustrating.

 

Matt

 

0 Kudos
Message 7 of 10
(8,483 Views)

Could you add one of the other inputs to the struc? 

That would essentially be like passing in multilple variables through a cluster into a subVI in LabVIEW. 

 

Did you try modifying your .m file based on the the input before running the mathscript node? 

Applications Engineer
National Instruments
CLD Certified
0 Kudos
Message 8 of 10
(8,464 Views)

I got the problem solved.  It was simply a syntax mistake on my part.

 

Going from a cluster into the mathscript node turned the cluster into a structure in mathscript.  I made the mistake of immediately calling the same structure a global.  So my cluster came into a variable called param.  Then I had "global param;" as the first line of code.  This cleared what I had intended to put in.  So this is how I did it... I renamed param to param_struc.  Then I wrote:

 

global param;

param = param_struc;

 

then my code from there worked.  I still needed to put "global param;" as the first line in my m file, though.

 

Thank you all for your support.

Matt

Message 9 of 10
(8,427 Views)

I got the problem solved.  It was simply a syntax mistake on my part.

 

Going from a cluster into the mathscript node turned the cluster into a structure in mathscript.  I made the mistake of immediately calling the same structure a global.  So my cluster came into a variable called param.  Then I had "global param;" as the first line of code.  This cleared what I had intended to put in.  So this is how I did it... I renamed param to param_struc.  Then I wrote:

 

global param;

param = param_struc;

 

then my code from there worked.  I still needed to put "global param;" as the first line in my m file, though.

 

Thank you all for your support.

Matt

0 Kudos
Message 10 of 10
(8,426 Views)