LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Solve 2 odes - nonlinear

Hi,

 

I have been trying to solve 2 odes over time in labview but I can't quite get it. I think my problem is that they are non-linear and I am going about it the wrong way. I have been trying to get a result from the Runge Kutta 4th Order.vi but it does not give me an output.

 

my equations are:

 

dxi/dt=(Ch*xi*(r - (xi^2 + yi^2)^(1/2)))/((xi^2 + yi^2)^(1/2)*((r - (xi^2 + yi^2)^(1/2))^2 + 1)^(1/2))+(Cr*(xi - xj))/(Lr*exp(((xi - xj)^2 + (yi - yj)^2)^(1/2)/Lr)*((xi - xj)^2 + (yi - yj)^2)^(1/2))

 

dy/dt=(Ch*yi*(r - (xi^2 + yi^2)^(1/2)))/((xi^2 + yi^2)^(1/2)*((r - (xi^2 + yi^2)^(1/2))^2 + 1)^(1/2))+(Cr*(yi - yj))/(Lr*exp(((xi - xj)^2 + (yi - yj)^2)^(1/2)/Lr)*((xi - xj)^2 + (yi - yj)^2)^(1/2))

 

I have constants for all parameters except for xi and yi which should change. I know that (xi^2 + yi^2)^(1/2))^2 should be equal to r in the end.

 

If some one can point me in the corect direction that would be great.

 

Thanks

Adam

0 Kudos
Message 1 of 5
(2,470 Views)

bump

 

I can solve this in matlab so i know what it is supposed to return. I have now been trying to solve it using the mathscript but i dont understand the syntax. 

 

The ode solvers seem to only work with functions and i dont understand how to set it up. from the example here:http://zone.ni.com/reference/en-XX/help/371361E-01/lvtextmath/msfunc_ode15s/

 

% The lorenz function is defined by:
% function dy = lorenz(times, y)
% dy = zeros(3, 1);
% dy(1) = 10*(y(2)-y(1));
% dy(2) = 28*y(1)-y(2)-y(1)*y(3);
% dy(3) = y(1)*y(2)-8/3*y(3);
[t, y] = ode15s('lorenz', [0, 5], [1; 1; 1])

 

now my dy(1) and dy(2) come from other parts of the program and have numerical values from my initial conditions but if i wire them in and have the following:

 

 

function dU = dAPF(t,U)

dU=[dUx,dUy];

 

x0=[12;17];

tspan=[0 1];

 

dUx=dU(1);

dUy=dU(2);

 

[t,U]=ode15s(dAPF,tspan,x0);

 

 

The error i get is:

 

A function is defined in this script. You must save and call the 
function with appropriate input values to execute the function.
I guess it makes sense because i have a function m-file and a separate m-file for the solver.
Any idea on how i can get his to work?

 

0 Kudos
Message 2 of 5
(2,446 Views)

Hi Adam

 

I will be looking into your ODE issue for you and trying to help you solve the problem and continue with your application. As I understand you are trying to solve 2 ODE's using LabVIEW but are coming across some issues and hence not getting the data you would expect.

 

There are a few different things that I think you would benefit from looking into, so I have included a few links for you to look at.

 

1) If you have the code working in Matlab already, have you thought of converting the code into LabVIEW instead of rewriting?

 

2) There is now a tool available that will convert expressions directly into code, this may help you place the nodes that you need. The videos on this page show the functionality of this tool.

 

3) In the LabVIEW add-on Control Design and Simulation Module, there is an example that simulates the Lorenz Attractor along with a number of other functions, this add-on may be something to consider.

 

4) and lastly in LabVIEW itself I found a few examples on ODE, that use differing methods. Looking at these may help discover where the issue is with your code. Examples in LabVIEW can be found by navigating to help>>find examples>>browse>>analyzing and processing signals>>mathematics>>ODE searching ODE in the example pop-up box may also throw up some useful documents.

 

If you would like to have a look into these and let me know how your application is going that would be great. If you are still having some issues we can go further into the problem, just let me know how it goes.

 

Thank you

Stephanie L
Applications Engineer
National Instruments UK and Ireland
0 Kudos
Message 3 of 5
(2,418 Views)

Hi Adam

 

How is you program going? Have you got any further with solving your ODE's?

The reference help available for mathscript is the most detailed documentation we have on the available functions, but I am continuing to look for some additional examples.

 

Thanks

Stephanie L
Applications Engineer
National Instruments UK and Ireland
0 Kudos
Message 4 of 5
(2,379 Views)

Hi,

 

Thanks for the reply, I have not had much time to look into this further but I did look at the info on the maths node. It seems very usefully however it does not support summations and there will be summations in my final equations. I have mainly been trying to make my Matlab code more robust and then I will try and convert it. Hopefully I can give the Labview another go in a few days.

 

Adam

0 Kudos
Message 5 of 5
(2,370 Views)