Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted

03-28-2014 05:02 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hello everyone,

I'm trying to simulate a system of non-linear ODEs in LabVIEW. I have tested the code in MATLAB and got a very fast result (within seconds), and I am trying to simulate the same thing in LabVIEW but having some major issues. Certain things I noticed right away is that when the time step goes below 1 E -9, the variable step size solvers never converge (ie never stops executing). If I bring it down, then I get error 2324.

I'm pretty confident that the code in MATLAB and the code in LabVIEW are identical with regards to the state equations. Does anyone have any idea or faced this before? In MATLAB I am using the following command:

options=odeset('RelTol',1e-6,'Stats','on');

[Tt,y] = ode15s(@Diff_Eq5_core,[0 5],zeros(1,16),options);

It also works with the solver ODE23, which is what I tried to use with LabVIEW. I am attaching my LabVIEW code (very sorry for the messy wiring, I usually write code better then this but I was in a major hurry).

Highlighted
Options

03-31-2014 12:15 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hey Shehezaada,

I'm sorry to hear that you're encountering difficulties implementing your code. From the behavior you're describing I'm wondering if your parameters aren't being passed properly. From looking at your code (ODE-MainRHS) you've got a possible race condition with your indexed array elements and the local variables you're using. Try implementing a flat sequence structure or enforce date flow by wiring one of the indexed items to the for-loop. Otherwise your local variables may be using values from the previous run of the VI in your calculation which would certainly cause issues. Otherwise, I don't see anything else in your code that jumps out as a possible cause of the errors. I'd run back through your cases and compare your equations with the G code to ensure nothing got switched (or move to a Formula Node).

Hope this helps!

--Ryan_S

Highlighted
Options

03-31-2014 03:26 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi Ryan!

Thanks so much for the reply. I will definitely do as you suggested, I'm sorry you had to look through that messy code. It definitely needs cleanup and I'll just wire it right through to avoid the race condition. I'll get back to you. Thanks once more!

Highlighted
Options

03-31-2014 04:00 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

I noticed (in addition to what Ryan said) that your output is labeled f'(x). The detailed help for the ODE Solver.vi says the function VI should generate:

**ODE F(X,t)** is a strictly typed reference to the VI that implements **the right-hand side of an ordinary differential equation dX/dt=F(X,t)**. Create this VI by starting from the VI template located in labview\vi.lib\gmath\ode.llb\ODE rhs.vit.

Bold emphasis added.

Do you have the right equations?

Since I already cleaned up ODE-MainRHS.vi, I can save you some time. Please check it carefully. I did not confirm that the changes correclty implement the equations you are using.

Lynn

Highlighted
Options

04-01-2014 12:22 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Dear Lynn,

Thank you so much for your response and effort in making it cleaner. I will double check the equations for sure, and yes the right hand side of the ODE is F(X), the label is incorrect in this case.

Highlighted
Options

04-01-2014 08:35 PM - edited 04-01-2014 08:36 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hey guys,

So I redid the entire thing with the suggestions above - cleaning up and enforcing data flow, rechecking the equations, and I'm still not able to get ODE solvers to converge or give the proper result. I tried to implement a much simpler system of ODE (an example off the MathWorks website) and I was able to get identical results from MATLAB and LabVIEW for that attempt...so something tells me either the implementation of this system in LabVIEW for some of the equations is incorrect, OR the solvers/solver parameters are different from MATLAB and LabVIEW when it comes to stiff ODEs.

I'm able to solve this ODE system in MATLAB using ode15s (which uses BDF) and ode23s (which uses Rosenbrock). I'm using absolute and relative tolerances of 0.01 in MATLAB, (even somtimes up to 1e-6).

I'm attaching both versions of code (MATLAB and LabVIEW) for comparison. Also for in each case for the Differential Equation case structure I have put the equation that is supposed to be use to make it easier for double checking. If anyone could please take a look that would be great.

My next plan of action is to use the MathScriptRT Nodes to see if I can get it going with those.

Highlighted
Options

04-02-2014 12:39 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hey guys,

So I tried the MathScipt RT Function with all the solvers, still the same result - >doesn't converge. To verify the correctness of this method, I used a MATLAB script node and ran the identical code and I got the result. Please see the attached VI - LorenzTest.vi for the details. At the bottom there is a MATLAB scipt...you'll need to change the first line to replace my path with yours.

One glaring difference between the solvers for MATLAB and LabVIEW is that there is an option for LabVIEW ODE solvers to specify a minimum step size, whereas this does not exist in MATLAB. This leads me to believe that although the ODE names are similar for both LabVIEW and MATLAB, the inherent implementation is different. If I run the identical code, in LABVIEW, with the MATLAB Script vs the MathScript, then clearly the equations are not wrong. The only difference is the presence of an additional flag for LabVIEW solvers, which is the min step. I put in the minimum step size found by the MATLAB one but this is not working.

If anyone has any ideas, please let me know!