尽管我读了这篇文章,但我仍然不知道如何将其应用于我自己的数据,并希望有人能帮助我。
我有以下数据:
y <- c(11.622967, 12.006081, 11.760928, 12.246830, 12.052126, 12.346154, 12.039262, 12.362163, 12.009269, 11.260743, 10.950483, 10.522091, 9.346292, 7.014578, 6.981853, 7.197708, 7.035624, 6.785289, 7.134426, 8.338514, 8.723832, 10.276473, 10.602792, 11.031908, 11.364901, 11.687638, 11.947783, 12.228909, 11.918379, 12.343574, 12.046851, 12.316508, 12.147746, 12.136446, 11.744371, 8.317413, 8.790837, 10.139807, 7.019035, 7.541484, 7.199672, 9.090377, 7.532161, 8.156842, 9.329572, 9.991522, 10.036448, 10.797905)
t <- 18:65
现在我只想适合一个正弦波
与四个未知数,,和到它。ω φ Ç
我的代码其余部分如下
res <- nls(y ~ A*sin(omega*t+phi)+C, data=data.frame(t,y), start=list(A=1,omega=1,phi=1,C=1))
co <- coef(res)
fit <- function(x, a, b, c, d) {a*sin(b*x+c)+d}
# Plot result
plot(x=t, y=y)
curve(fit(x, a=co["A"], b=co["omega"], c=co["phi"], d=co["C"]), add=TRUE ,lwd=2, col="steelblue")
但是结果确实很差。
非常感谢您的帮助。
干杯。