Grasshopper

algorithmic modeling for Rhino

hello, 

is it possible to solve an equation in grasshopper?

Views: 6653

Replies to This Discussion

The first solution within a specified degree of accuracy is the one I want, as fast as possible, and a binary search works fine for that, doesn't it?

No, divide-and-conquer search only works if a number of assumptions can be safely made, and this is not the case for equations with unknown behaviour. The initial division may be too coarse to find a specific peak, and this approach cannot handle discontinuities either.

Assume we're trying to find where a function becomes zero, within some domain. We know ahead of time that there may be any number of solutions; zero (x²+1), one (x+1), two (x²-1), many (Sin(x)) and even infinite (Sin(1/x)).

So we evaluate the equation at 9 values, dividing it into 8 spans (the dashed purple curve is how the search algorithm sees the equation). We immediately determine that none of the spans crosses the y=0 line, so either we give up or we focus on spans 5 & 6 as they got closest. We'll never find the two solution in span 3.

Or maybe the equation results in a discontinuous graph, like so:

It seems as though the answer must be somewhere in span 4, but no matter how hard we search there, we'll never find it.

As a programmer, you must be aware of exceptions like these, of course.  What I'm saying, though, is that there is a set of problems that are "well behaved", without discontinuities or anomalies.  For those, a much faster solution is needed.

Attached is an extremely stripped down version of the problem I mentioned earlier.

Instructions:

  1. Start with 'Roll=0', 'Volume=1543.943'
  2. Adjust 'Roll' to ~35 degrees
  3. "Solve" 'Z-offset' value to return to 'target' (original) volume of 1543.943

A fast solution is needed for this.  I believe a binary search will do the job.  And the problem is common enough for a Grasshopper component.  Maybe one of the plugins will do this?  Very basic though, so would rather have it built in than write code or install something else.

Thanks.

P.S.  The hull in this example is a really poor shape!  And this probably doesn't belong in this thread, since this isn't really about "solve mathematical equation"...

I do plan to add other solvers to Galapagos for GH2, uphill and binary searchers amongst them. These would be good alternatives for low-dimensional, or highly continuous problems. Having a somewhat faster way to trigger a galapagos run would also be beneficial.

You can always evaluate an expression using N samples, then intersect the graph with a line that represents the needed Y solution.

Attachments:

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service