LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

solve a formula by iteration

 

I am running a  differential equation through labview.   The method of solving the equation is via iteration. You enter a value and see what end result you get. Using the end result you adjust the input value on the next iteration to progress to the answer you want.

 

I have a few methods of doing this - I can send the input values round on a shift register and keep adjusting automatically until I hit the right number.

 

But this is taking a number of attempts to reach the solution to equation - and hence the programme is slow.

 

Is there a programming method to do this?

 

I would imagine that this must be a solvable mathmatical problem. 'What is the fewest number of attempts to identify a number@ - but I can't find much on the internet.

 

Spike.

 

 

 

 

 

 

0 Kudos
Message 1 of 11
(4,512 Views)

sjh wrote:

 

I am running a  differential equation through labview.   The method of solving the equation is via iteration. You enter a value and see what end result you get. Using the end result you adjust the input value on the next iteration to progress to the answer you want.

 

I have a few methods of doing this - I can send the input values round on a shift register and keep adjusting automatically until I hit the right number.

 

But this is taking a number of attempts to reach the solution to equation - and hence the programme is slow.


A shift register is the correct way and the speed only depends on the complexity of the problem and the convergence characteristics.

 

Your description is too generic to really tell what the bottlenecks are. Can you tell us a bit more about your problem?

 

 Also don't forget that LabVIEW has a few tools to solve differential equations. Maybe there is something that you could use. Have a look in the mathematics...differential equations palette.

Message Edited by altenbach on 10-10-2009 12:06 PM
Message 2 of 11
(4,507 Views)

Ok, I will try.

 

The input variable is between 0 & 1.

 

The software will start at an input of 0.1 into a dfferential equation and this may give an output of 40 mins. (in 15 sec steps).

 

I either multiply or divide the input by 0.5 depending on whether the 40 mins is above or below target. This is via  a shift register and back into the differential equation where I get another result.

 

At some point using 0.5 the programme will oscilate either side of the required result. I use this oscilation to change  ftom 0.5 to 0.75.

 

The programme continues multiplying or dividing by 0.75 until oscilation and then moves on to 0.9.

 

this process continues with numbers that approach closer and closer to 1 until i get an exact match. An exact match stops the loops and the programme moves on.

 

the time I am looking to match via differentiation may be as high as 120 mins. using 15 second steps you need a minimum of 480 iterations of a 'while loop' to get a result . this assumes that the input is right first time.

 

If the method of determining the input is not as efficent as possible, then the programme execution will be far longer than necessary.

 

 

A typical input value may be 0.002 to give the matched result.

 

The software needs to perform  say 60 to 100 differential equations each of which will need matched with a known end result.

 

The software to do the differential equation is fine, it is the process of determining input most efficently would help me out greatly.

 

let me know if the above is clear.

 

 

You will be pleased to know that this is associated with the other problem you helped me out with!!!!! 

 

Regards

 

SJH 

 

 

 

 

 

 

 

 

 

 

     

 

 

0 Kudos
Message 3 of 11
(4,483 Views)

sjh,

I'm afraid I'm struggling to understand your explanation, perhaps you could attach your VI and we can have a look at it.  

 

Kind Regards,

Dominic Walker

Dominic Walker
Cardiff University
Electrical and Electronic Engineering Student
0 Kudos
Message 4 of 11
(4,431 Views)

I have attached a simplified version of what I am doing. The inner while loop would contain an eqaution that can only be solved by inputing a value and see what the answer is. the input is then adjusted until you hit the right answer.

 

I am looking for the most efficient way of finding the correct input value.

Message Edited by sjh on 10-12-2009 03:20 PM
0 Kudos
Message 5 of 11
(4,394 Views)
Message Edited by sjh on 10-12-2009 03:21 PM
0 Kudos
Message 6 of 11
(4,390 Views)

A good first start would be to eliminate the Wait for 500 ms. This is adding a half second to every loop iteration. Try using a Wait 0. That will speed things up dramatically and still allow LabVIEW to context switch if necessary.

 

Also, you should seriously consider cleaning up your code. Not to be harsh but it is a mess and very difficult to follow.  Things you want to avoid are:

  • Hidden wires. You have lots of wires that significant portions of them are hidden and not visible.
  • Minimize bends in your wires.
  • Try to avoid havingyour wires flow backwards. In general you want wires to run from left to right and top to bottom.
  • Avoid placing controls or indicators on top of wires. In general, avoid running wires under other objects.

I am a bit curious why you placed your differential equation in a loop. It is set to always exit on the first iteration.

 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 11
(4,382 Views)

 

It is an example................

 

The real thing would create too many questions that don't relate to the problem. (as is the case with this one).

 

The code that performs the differential equation would sit in the inner 'while loop' - this has been replaced with a simple equation so that I can demostrate what is going on. (the actual programme is performing hundreds of thousands of equations to solve a number of problems simultaniously)

 

The 500 ms wait is only in this example  I use 5 ms normally.  But it allows those viewing the software to see what is happening.

 

The question is:

 

The example code modifys the input value in response to the result of the equation. I need to reduce the number of steps the programe takes to find the soultion. I have demostrated one method of doing this - but I need more efficent methods.

 

In the real programme each run of the differential equation can take 20 seconds or so. Any reduction in the number of times I need to run the equations will speed the total programme significantly.

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 8 of 11
(4,367 Views)

I would highly recommend that you separate your UI task from the calculations themselves. Even you 5 ms delay in your actual code will impact your performance significantly. If you look at something like a producer consumer architecture where you can optimize your calculation task for performance while still providing a responsive UI for your users. It will be impossible for anyone to give you specific advice for speeding up your calculation if you don't post the actual algorithm. The best anyone can do is to give you general advice.

 

As for the code, spaghetti code is spaghetti code whether it is production code or an example. As written it is very difficult to follow.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 11
(4,360 Views)

Hey sjh,

What version of Labview do you have? Base, Full, or Professional?  There are several Differential Equation VIs available in the Mathematics section of the functions palette if you have Full or above.  Perhaps these can help?

Kind Regards,

Dominic Walker
Cardiff University
Electrical and Electronic Engineering Student
0 Kudos
Message 10 of 11
(4,333 Views)