find_fit error with trig data

asked 2022-03-26 01:02:45 +0200

chazzs gravatar image

This is using the example built-in to the help,

set_random_seed(0)
data = [(i, 1.2 * sin(0.5*i-0.2) + 0.1 * normalvariate(0, 1)) for i in xsrange(0, 4*pi, 0.2)]
var('a, b, c, x')
model(x) = a * sin(b * x - c)
sol = find_fit(data, model)
f(x) = model(a=sol[0].rhs(), b=sol[1].rhs(),c=sol[2].rhs())
p=plot(f(x),(x,0,13))
p+=list_plot(data,color='red')
show(p)
data

This is all good, except change 4*pi to 13 and find_fit no longer works. Any idea why?
C

edit retag flag offensive close merge delete

Comments

Even

1.2 * sin(0.5*i-0.2) + 0.1

without normalvariate(0, 1) seems faulty with either 4*pi or 13.

tolga gravatar imagetolga ( 2022-03-26 09:14:13 +0200 )edit