LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

help with downhill optimization

Solved!
Go to solution

Hi all,

 

I am trying to solve this one equation with one unknown using optimization.  It's a non-linear equation and I was searching around for something that works like excel's solver.  The downhill optimization seems close to what I want to do, but it is not optimizing.  Would anyone mind looking at this code and try to determine what I'm doing wrong?

 

FYI, I've checked the answer by putting 0.02 as the X in my function and it is giving the right value.  The function is set up to be like:  Calc(X) - Actual = 0.  The "=0" portion should be implied (maybe this is what is wrong?)

 

Thanks,

Matt

 

 

 

Download All
0 Kudos
Message 1 of 6
(3,049 Views)

The problem seemed to be the initial value of your function and the type of your function. If you try to plot it, you will notice the discontinuity around 21.049 as shown below:

graph.png 

If you start from the left (like 21) then the minimization function will only be able to converge. If you start on the right (like 22), then you will find the X = 21.049 as minimum.

 

Here is the code for it:

Optimization.png

 

Hope this helps

Barp - Control, Simulation, RTT and HIL - National Instruments
Message 2 of 6
(3,016 Views)
Solution
Accepted by topic author Matt-UHart

I just noticed that... If you are trying to get the Func - Measured, then you are trying to detect zero crossing of it instead of minimum. In this case, then you have to make the f(x) present the minimum when crossing zero. You can use the minimization function but you have to change f(x) to be abs(f(x)). Then, finding the minimum means detecting where the function crosses zero.

 

If this also doesn't help, maybe it would be good to have your original problem posed and, if possible, which function you were trying to use in Excel.

Barp - Control, Simulation, RTT and HIL - National Instruments
Message 3 of 6
(3,012 Views)

ahh thank you!  I will try the absolute value when I get in the office on Monday.  In the meantime, I coded a simple Newton Rahpson method to work with my function that seems to do the job as well.

 

Thanks again!

Matt

0 Kudos
Message 4 of 6
(3,006 Views)

oh also I do not expect solutions above 21%... in fact, all answers should be greater than zero but less than 5%.  You must be correct that I need to do the absolute value and give it a better first approximation.

 

Thanks,

Matt

0 Kudos
Message 5 of 6
(3,005 Views)

Thank you!  The absolute value did the trick!

 

Thanks again!

Matt

0 Kudos
Message 6 of 6
(2,981 Views)