[Haskell-beginners] nested guards

David Frey dpfrey at shaw.ca
Fri Feb 3 21:16:45 CET 2012


http://www.haskell.org/haskellwiki/Case

That link shows how to write a select function that offers 
functionality similar to a switch statement in C.  Then you could use 
guards for the top-level switching and the select function for the 
second level.


On Fri, 3 Feb 2012 19:55:03 +0100, Thomas Engel wrote:
> Hello,
>
> I'm new to haskell. I want to write a function for a s-curve
> acceleration in haskell.
> A solution in VBA is already working.
>
> Are there nested guards in haskell available or how can I rewrite
> this function?
>
> The function should calculate the acceleration for a given distance,
> max acceleration, velocity, jerk at time since start
>
> acc_skurve::Float->Float->Float->Float->Float->Float
> acc_skurve str acc v jerk taktuell
>  | str <= str2jerk                  |taktuell <= (0.5 * str /
> jerk)**(1/3::Float)    = jerk * taktuell
>                                     |taktuell <= (4 * str /
> jerk)**(1/3::Float)      = jerk**(2/3::Float) * 2**(2/3::Float) *
> str**(1/3::Float) - jerk * taktuell
>                                     |taktuell <= (27/2 * str /
> jerk)**(1/3::Float)   = - jerk * taktuell + 2**(2/3::Float) *
> str**(1/3::Float) * jerk**(2/3::Float)
>                                     |taktuell <= (32 * str /
> jerk)**(1/3::Float)     = -2 * 2**(2/3::Float) * str**(1/3::Float) *
> jerk**(2/3::Float) + jerk * taktuell
>  | str > str2jerk && str < str2acc  |taktuell <= acc / jerk
>                                                          = jerk *
> taktuell
>
>                                     |taktuell <= - acc / 2 / jerk +
> sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))     = acc
>
>
>                                     |taktuell <=  acc / 2 / jerk +
> sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))      = acc / 
> 2
> - jerk * taktuell + sqrt(acc^3 + 4 * str * jerk^2) / (2 * sqrt(acc))
>
>                                     |taktuell <=  3 * acc / 2 / jerk
> + sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))  = acc / 2 
> -
> jerk * taktuell + sqrt(acc^3 + 4 * str * jerk^2) / (2 * sqrt(acc))
>                                     |taktuell <=  sqrt(acc^3 + 4 *
> str * jerk^2) / (sqrt(acc * jerk))                           = - acc
>
>
>                                     |taktuell <=  acc / jerk +
> sqrt(acc^3 + 4 * str * jerk^2) / (sqrt(acc * jerk))              = -
> acc + jerk * taktuell - sqrt(acc^3 + 4 * str * jerk^2) / sqrt(acc)
>
>  | str >= str2acc                   |taktuell <= acc / jerk
>      = jerk * taktuell
>
>                                     |taktuell <= v / acc
>      = acc
>                                     |taktuell <= acc / jerk + v / acc
>      = acc - jerk * taktuell + v * jerk / acc
>                                     |taktuell <= str / v
>      = 0
>                                     |taktuell <= str / v + acc / jerk
>      = jerk * str / v - jerk * taktuell
>                                     |taktuell <= str / v + v / acc
>      = - acc
>                                     |taktuell <= str / v + acc / jerk
> + v / acc = -(str / v + acc / jerk + v / acc - taktuell) * jerk
>    where str2jerk = 2 * acc^2 / jerk^2
>          str2acc  = acc^2 * v + v^2 * jerk / (jerk * acc)
>
>
> best regards
> Thomas
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners




More information about the Beginners mailing list