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

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

Similar Messages

  • Problem in solving ODE

    Hi,
    I am trying to simulate aircraft equations. I need to solve 12 ODEs simultaneously using R-K 4th order.  I have created a VI for the  same.  But when I close the VI file, all the data like initial conditions(X0), F(X) and Variable names(X) get lost. Everytime I open the file I need to feed all the values, equations again evenif I save the file before closing.
    Please tell me how to save this data. I am using arrays (controls, indicators) to give the input to the ODE solver block. Kindly help me as I am spending most of my time in writing those big equations again and again.
    Rashmi
    [Dept of Aerospace Engg, IIT Bombay]

    Rashmi,
    I agree with André, you can from the front panel select the current data (after you've put in what you want) as the default.  Or you could have all of this information in an external file (.ini, for example) and pull that in.  Or you could use property nodes and set the values at the start of the program.  Or lastly rather than having these be controls, have them be constants.
    Regards,
    Jared Boothe
    Staff Hardware Engineer
    National Instruments

  • Can I solve 3 nonlinear equations in LabWindows/CVI

    I have 3 nonliear equations with 3 unknowns (x^2, y^2, and z^2) and get the roots?

    There is no CVI function for finding nonlinear roots, but you can use any other C routine, e.g. the ones provided in the GNU Scientific Library 

  • Solving nonlinear equation with VI

    Hi,
    I want to use LabView to solve a nonlinear equation. I read forums and figured out that I can use Nonlinear System Solver. vi and I noticed there are two options to write the equation: 1) F(X) is formula and 2) F(X) is VI. I could use the first option and write the equation with that but I did not understand how to use a sub-Vi to provide the equation. Would any one please tell me how to do that?
    Thank you 

    Soran,
    Read the detailed help for the solver VI. 
    The VI usually executes much faster than the formula parser/evaluator. Since solvers (and curve fitters, which have the same options) may need to evaluate the function many times while solving, that time can become significant.
    In the help is a link to a template for the VI you need. You must use the exact connector pane and reference type. While you can create your own VI, it is much easier to use the template. On the block diagram create the code to generate your equation values in the configuration required by the solver. Be careful to put the parameters in the correcto order.
    Lynn

  • About the Nonlinear System Solver

    Hi, I am trying to solve a nonlinear system that is a little complicated to get the solution manually:
    B*Sin(P)/(2*sin(B)*b)=0
    B*Sin(W)/(2*sin(A)*b)=0
    A+B+P+W-180=0
    I tried to use the Nonlinear System Solver entering the formulas and
    all I get is an error code -23001 (Error -23001 occurred at an
    unidentified location Possible reason(s):
    Analysis:  Syntax error of parser. "
    I don't know what I am doing wrong, I am doing it similarly to the
    attached VI, with my own equations and controls. I even tried to change
    the equations so I would delete the "sin" (sine), just to make a test
    (about syntax and the solver not understanding that command?), and I
    got the same error.
    Help is much appreciated,
    Thanks

    Also remember that the argument to trigonometric functions must be in radians here.
    Are you sure that A and Beta are not [0<A<π/2], [0<Beta<π/2].
    How about the "180" in the last formula. Shouldn't it be π instead?
    Is b 83 degrees or just a constant of 82?
    LabVIEW Champion . Do more with less code and in less time .

  • Distance along an ellipse arc (nD Nonlinear System Solver (VI).vi)

    I'm hoping to get some help solving an issue I've come up against. I appreciate that what I'm asking requires some of your time, so I've tried hard to do my due diligence before posting here. I'll really appreciate any help I can get. I'm using LabVIEW 2014 Professional on Windows 7.
    I've stripped away all the details of the specific application I'm working on and tried hard to isolate just the issue that is causing me difficulties.
    I've posed the problem below and I attached some investigation code (sorry, there is quite a bit) that represents my current solution (with the issue).
    Problem: Given an ellipse (with a major and a minor axis and a frame of reference), a distance to travel and any point on the ellipse, calculate the end point on the ellipse where the elliptical arc length between the two points equals the given distance to travel.
    I'll restate the problem, but with physical values. Given an ellipse, centered on the origin, with axes of 10mm and 8mm, and a starting point (5mm, 0mm); what is the end point on the ellipse after travelling 1 mm along the ellipse?
    This initially seemed like a simple calculation (and it is for a circle), but for an ellipse, the math turns out to be somewhat more complicated and requires numerical computation.
    Issue: I was given some python code that solves this problem and embarked on a LabVIEW solution. The python code uses the function optimize.fsolve from the scipy library to solve one aspect of the problem. I'm not too familiar with the LabVIEW VIs available to do the equivalent, but settled on "LabVIEW 2014\vi.lib\gmath\zero.llb\nD Nonlinear System Solver (VI).vi" (my code still has other options disabled in the code). When I use this solver VI, I do not always get the same answer from this VI. Sometimes it finds one root and sometimes two. For points separated by less than half the circumference of the ellipse, there should always be 2 roots (one in the clock-wise and one in the counter clock-wise direction). Any ideas why the solver does not always return 2 roots?
    Current Solution: My investigation VI takes two points on an ellipse (defined by a start angle and end angle) and calculates the distance between them along the ellipse. Then, I take the start point and the distance and try to calculate the end angle (which I can use to find the end point). Run once, it usually finds the right answer, but run 100 times it often returns the answer 19. I should mention that I'm not 100% positive there are no issues with the code used to support this calculation and I'm open to any suggested changes or improvements, but the issue currently causing problems is the inconsistent operation of the solver VI.
    Again, I appreciate this is long and thank you for reading this far; I hope you find this as fun a problem as I do!
    Chris
    Solved!
    Go to Solution.
    Attachments:
    NI Forums.zip ‏265 KB

    Hello Mark,
    Thanks for your reply, I was concerned that I had sent up an air ball on this one! And thank you for taking the time to review the code.
    You are correct, I am having an issue with the results of the nD Nonlinear System Solver (VI).vi. And that is a good poiint you raise, regarding the choice of the starting points. I'm not intending to use random values, I think I'm using a number very close to the start angle (in this case 20.001 degrees) as a start and 2pi (or 360 degrees) as the end. When I read the description of the start and end from the documentation:
    Start is an array describing the left corner of the n-dimension interval. The randomly chosen start points of the zero-finding algorithm can be found in the n-dimensional rectangle spanned by Start and End.
    End is an array describing the right corner of the n-dimension interval. The randomly chosen start points of the zero-finding algorithm can be found in the n-dimensional rectangle spanned by Start and End.
    I have to admit I don't *understand* what this means and I am currently guessing for the choices of start and end. I will think on this some more and review your links.
    As far as my final goal, I'm going to use this code I shared for generating an ellipitical motion profile on the PC to send to a cRIO and have executed on a FPGA.
    I'll report back after I work on this some more, but if you have some more insights, please share.
    Chris
    (BTW, I have an open support item for this #7444649 and it was suggested I also post on the forums)

  • Simulation Loop ODE Solver

    I keep getting Error 2324: Labview Simulation Module: The ODE solver cannot meet the error tolerance using the minimum step size. I've broken my code down and my signal multiplication function seems to be the cause. If I don't multiply things it works fine. If I do, I get the error. Any ideas?
    Thanks,
    Brian
    Solved!
    Go to Solution.
    Attachments:
    Signal Multiplication.JPG ‏46 KB

    Brian,
    The Simulation Loop has some parameters that needed to be changed. In general, you can try to reduce the stepsize (double-click on the terminal on the left of the Simulation Loop) and change the minimal step size. Also, it is worth to change the relative and absolute tolerance to relax the values. If you increase, you can have some results.
    Additional to that, in general, if you try to use a "pure" PID, you run into some numerical issues because of the transfer function has no limits and, also, if you try to have "KD" different than zero, it won't even run the simulation. To avoid this problem, use a value for the high frequency time constant higher than zero. This way, you won't run into this problem.
    If you still have questions, please feel free to reply with you actual code and version of LabVIEW that you use.
    Cheers!
    Barp - Control and Simulation Group - LabVIEW R&D - National Instruments

  • ODE Solver providing result in MATLAB but not in LabVIEW

    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).
    Attachments:
    Farag 2 Bus - LabVIEW.zip ‏56 KB

    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.
    Attachments:
    ODE.zip ‏76 KB

  • Solving a system of nonlinear equations

    Hey guys,
    I am currently trying to solve a set of nonlinear equations in LabView with the help of MathScript and MATLAB code. I'm trying to create a working code since hours, but I haven't achieved this goal yet.
    System of equations:
    x^2 + y^2 + z^2 - R1^2 == 0
    x^2 + (y-Y0)^2 + z^2 - R2^2 == 0
    (x-X0)^2 + y^2 + z^2 - R3^2 == 0
    R1, R2, R3, X0, Y0 are known.
    Possible solution in MATLAB (assuming X0 = Y0 = 100, R1^2 = R3^2 = 11000, R2^2= 9000):
    Create myfun.m with content:
    function F = myfun(x);
    F = [x(1)^2 + x(2)^2 + x(3)^2 - 11000;
    x(1)^2 + (x(2)-100)^2 + x(3)^2 - 9000;
    (x(1)-100)^2 + x(2)^2 + x(3)^2 - 11000];
    end
    Set intial value for iteration:
    x0 = [50 50 50]
    Solve:
    fsolve(@myfun, x0)
    => Works fine!
    Now I tried to just plug all of this stuff into a MathScript Node:
    function F = myfun(x);
    F = [x(1)^2 + x(2)^2 + x(3)^2 - 11000;
    x(1)^2 + (x(2)-100)^2 + x(3)^2 - 9000;
    (x(1)-100)^2 + x(2)^2 + x(3)^2 - 11000];
    x0 = [50 50 50];
    Sol = fsolve(@myfun, x0);
    This is where the problem starts.
    When I try to run the program, I get the follwing error message:
    A function is defined in this script. You must save and call the
    function with appropriate input values to execute the function.
    I can't really figure out, what I did wrong and I would be very thankful, if somebody could help me.
    Regards,
    fuchrist
    Solved!
    Go to Solution.

    Hi,
    MathScript does not support inline user-defined function (UDF). What you need to do is
    Define the UDF in a .m file. Give that .m file the same name as your UDF.
    Save the .m file in MathScript Search Path. By default, the search path is the LabVIEW Data folder.
    Pass the name of .m file as the first string input to function fsolve in MathScript Node.
    I attach my .m file and snapshot of MathScript Node. The result I got is [50, 60, 70] which should be correct.
    Attachments:
    myfun.zip ‏1 KB

  • Nonlinear Differential Equation solver

    Hello..
    I am trying to slove first order DE of the form.. dP/dz = A ln{ [1+[(P(z)/B)*exp(-C)]] / 1+P(z)/B } where A,B and C are numerical values. I tried to plot Z vs P(z)  using ODE slovers but didnt get the result. I am attaching the expected plot also. I found some examples like ODE circuit in LV help but end up in empty graph after trying to slove this above equation. which methode is correct to slove this equation, please suggest some way.. Thank you very much.
    Attachments:
    solution plot.png ‏6 KB

    It's been a long time since I thought about diffEQ.  Please post what you think should be a solution -- it's probably easier for me to figure out why your graph is empty than it is to figure out how to solve an ODE from scratch. 

  • Memory function in Control and Simulation loop - ODE solver problem

    Hello,
    I am currectly using the control & simulation loop to simulate the behaviour of what is essentially a spring-damper-mass system. In the process the change in time (dt) is being used to integrate an arbitrary value. I am using a built in memory function to store the time, to calculate the time change (dt).
    The simulation is rather complex, due to the necessary accuracy needed, not all the ODE solvers can handle it. Currently I am using Adams-Moulton method, this works fine for the simulation. However it cannot detect the change in time, the change is constantly zero. This problem worked it self out by using another ODE solver, but then the simulation was rather messed up (even when I tuned the step sizes and tolerances). So I am quite confident that Adams-Moulton is one of the best suited ODE solver for the problem at hand.
    Is there another way to store the previous time and use it calculate the time difference, than using the memory function? Has anyone experienced such problems before?
    I have been doing alot of error searching using the probe, but I am quite sure that there is a problem with the ODE solver and the memory function. See picture below, showing in basic how the change in time is being calculated.
    I am rather new to LabVIEW, so if there could be something else I have missed I will be glad to hear it.
    PS! I have tuned the minimum step size/relative and absolute tolerances for the Adams-Moulton to simulate the behaviour of the system correctly.
    Solved!
    Go to Solution.

    Hi Willy,
    I am sorry, I can not upload the VI some of the content is confidential. I have attached a larger picture of the section were the change in volume and time is calculated, dV and dt. Also I have marked the two memory functions used. Hopefully this can help.
    My parameters:
    - ODE solver Adams-Moulton
    - Relative tolerance      1e-8
    - Absolute tolerance     1e-7
    - Minimum step size     0,0005
    - Maximum step size    0,01
    - Initial step size           0,01
    - Auto discrete time      On
    - Decimation                 0
    - Synz loop to timing source off
    Attachments:
    06-05-2014 21-20-00.png ‏52 KB

  • Error -23011 occurred at LabVIEW Analysis ODE Solver/inconsistency in dimensions of X(0), F and X!

    Hi,
    I have been trying to simulate ODE but getting following error:
    Error -23011 occurred at LabVIEW Analysis ODE Solver/inconsistency in dimensions of X(0), F and X!.
    The screenshot of the code is attached.
    Please let me know if anyone knows the reason of having this error.
    Thank you.
    -HB
    Solved!
    Go to Solution.
    Attachments:
    Screen Shot 2014-12-02 at 09.58.08.png ‏60 KB

    Hi,
    I have added another code which includes the "simple chemical reaction" which I am trying to model using ODE in LabVIEW, but I am continously having the same problem.
    Kindly see the attachment and try to help me out solving this issue. I couldn't found this kind of error listed on NI forum.
    Thank you.
    Regards
    Hasan
    Attachments:
    test_hb.vi ‏22 KB

  • Curve Fit of ODE, should I use Lev-Mar or Constrained Nonlinear Optimization?

    I wanna do a curve fitting of differential equations, following is the equations:
    dx/dt = u*x-a*x
    ds/dt = b*u*x+c*x
    dp/dt = d*u*x+e*x+f*p
    and u = um*s/(km+s+s^2/ki)
    I've tried "nonlinear curve fit( Lev-Mar)", but I met difficulties when writing the f(x,a) of Lev-Mar.
    Then I tried "Constrained Nonlinear Optimization", I found that the example "Estimate Nonlinear Spring Constant.vi"
    in the "labview\examples\math\curvefit.llb" was similar to the fitting I tried to do, but there was only one parameter
    need to estimate in this example,but what I need is to estimate 3 parameters.
    However,I modified the example to my equations, it failed again.
    How can I achieve this? is it possible to do this fit only using Labview VIs or need Matlab Script Node?
    Any help will be appreciated.

    I forgot to mention that in the equations above,  a,b,c,d,e,f is constant,
    and the data of x,s,p corresponding with the data of time is already known,
    and which parameters I wanna identify is um,km,and ki
    帖子被myafu在12-22-2006 01:33 AM时编辑过了

  • Can anyone help me solving a 2nd order diffrenntial equation using ode solver

    i have to study DC excited LCR circuit and plot V v/s I 
    please help

    HI Gerdw 
    sorry I mistook  ur signature
    but see if u can check from any of these files
    Thank you
    Attachments:
    ques37ode.vit ‏16 KB
    ode.jpg ‏49 KB
    ode2.jpg ‏76 KB

  • Using Constraints on my optimization problem (currently implemented in Unconstrained Nonlinear Opt.VI)

    I have an function f(x) that I minimize to find parameters for an algorithm. The algorithm consists of a coordinate transformation matrix. The transformation matrix parameters are currently found using the Unconstrained Optimization VI (simplex). I have had quite a bit of success using this VI and defining my algorithm as an objective function. I previously used Excel Solver for this application. The data set changes over time and certain parameters are tracked.
    Whenever I perform an optimization, I move the minimum parameters found to the initial guess parameters. I am finding that my initial guess parameters will remain stable for a while but at times will guess incorrectly. This can happen if I feed the algorithm bad data. It is difficult to determine that the data is bad initially, but it causes the minimization to trail off in some crazy direction that is inconsistent with the real world. This happens after repetitive minimizations and is a result of using my found results for the next iteration. However, in an ideal world, my last found results would be the best initial guess for the next optimization I perform.
    One major improvement would be to constrain my initial guess parameters. In particular, I would like to constrain the parameters I use in finding the transformation matrix (in my objective function) with lower and upper limits: 9 < R < 12, for example. Can anyone with experience using the optimization VIs, knowing the information above, help point me in the right direction? I came across the Constrained Nonlinear Optimization VI but it appears to work much different than the Simplex method; so I am not sure if this would work. I will try this next. Any thoughts?
    Chris Walker
    Certified Labview Developer

    I tried using the Constrained Nonlinear Optimization VI. I first tried it without any constraints (min or max constraints) on my parameters and it appeared to work. I could change the initial guess parameters and they would eventually end up the same minimization each time (with the same set of data). Once I add the parameter constraints, however, the VI freezes on the first iteration and I have to abort. I am not sure why and I do not get any errors.
    After some testing, it appears that the cno_isisubopt.vi subvi inside the Constrained Nonlinear Optmiziation VI is locking up. The code is attached. If I had to guess, this probably has to do with the input L advancing to Infinity and never allowing the while loop to stop. I am not sure what the internal workings of this VI are so this appears rather difficult to debug!
    This is an error that is not tracked or handled by the Constrained Nonlinear Opt Labview VI; thus freezing my program.
    Chris Walker
    Certified Labview Developer
    Attachments:
    4-4-2012 9-36-53 PM.jpg ‏158 KB

Maybe you are looking for