The goal is simple: Output a nonzero real solution
x to the equation
sin(x) = -mx, given input
m, in the fewest number of bytes.
- Your answer must be correct to 3 significant figures.
- You may output any real solution other than the trivial solution
x=0. You can assume
mis such that at least one solution exists. You may also assume
An obviously suboptimal python solution using gradient descent:
from math import * from random import * a=x=0.001 m = 5. def dE(x):return 2*(sin(x)+m*x+1)*(cos(x)+m) for i in xrange(1000): x-=dE(x)*a print x
-0.25 -> ±2.4746 -0.1 -> ±2.8523 or ±7.0682 or ±8.4232 0.2 -> ±4.1046 or ±4.9063