You are implementing the function fun wrong.

If you want
y = a1*sin(a2*x - a3)

fun should be something like:
fun(x,a) = a[1]*sin(a[2]*x[1] - a3) - x[2]

in this case, the function is not converging. Later today I will try to 
find out what is going on.

On Tuesday, January 19, 2016 at 12:40:37 AM UTC-2, [email protected] 
wrote:
>
>
>
> Code: 
>
> x = [0.0 0.2 0.4 1.0 1.6 1.8 2.0 2.6 2.8 3.0 3.8 4.8 5.0 5.2 6.0 6.2 7.4 
> 7.6 7.8 8.6 8.8 9.0 9.2 9.4 10.0 10.6 10.8 11.2 11.6 11.8 12.2 12.4];
> y = [-0.183 -0.131 0.027 0.3 0.579 0.853 0.935 1.133 1.269 1.102 1.092 
> 1.143 0.811 0.91 0.417 0.46 -0.516 -0.334 -0.504 -0.946 -0.916 -0.975 
> -1.099 -1.113 -1.297 -1.234 -0.954 -1.122 -0.609 -0.593 -0.403 -0.51];
>
>
> x0 = vec(x)
> y0 = vec(y)
>
> a = [1.5 1.5 1.0]
> eps = 0.000000000001
> maxiter= 200.0
>
> fun(xm,a) = a[1].*sin(a[2].*xm - a[3]);
>
> xy=hcat(x0,y0);
>
> coefs,converged,iter = CurveFit.nonlinear_fit(xy,fun,a,eps,maxiter);
>
>

Reply via email to