in reply to trigonometric functions give an uncaught user exception

The problem is that you need an additional parens on line 8. my $b = $r1 * ( cos($w_beta1) - (cos($w2 / 2) ) + $r2 * cos($w2 / 2));
Could happen to anyone... DrSax