在maxcurv

时间:2019-06-12 16:30:48

标签: r rstudio

我正在尝试使用R&RStudio查找数据集的最大曲率点。我发现了一个六阶多项式,可以在土壤物理学软件包的maxcurv中使用。问题似乎是maxcurv函数可以包含的变量数量受到限制。

多项式函数定义如下:

rev.function = function(x) coef.1 + (coef.2*x^1) + (coef.3*x^2) + (coef.4*x^3) + (coef.5*x^4) + (coef.6*x^5) + (coef.7*x^6)

coef。#代表不同的系数。

使用6阶多项式作为函数会产生错误:

  

解析错误(text = x,keep.source = FALSE):     :2:0:输入意外结束   1:〜coef.1 +(coef.2 * x ^ 1)+(coef.3 * x ^ 2)+(coef.4 * x ^ 3)+(coef.5 *    ^

但是,如果我尝试四阶多项式,则maxcurv函数将正常工作。不幸的是,四阶不足以描述所讨论的数据。研究该问题并没有产生很多问题,因为常见的错误是“缺少花括号”是一个典型问题,但是对于maxcurv函数,文档明确指出不要在函数中使用花括号。

重现该问题的代码:

library(soilphyscics

# provide range and starting guess for maxcurv
x.min = 0.515717
x.max = 184.8616  
x0 = 100

# polynomial coefficients, coef.1 = "intercept"
coef.1 = 1.591340e-05
coef.2 = -6.501014e-06
coef.3 = 8.233991e-08
coef.4 = 2.355853e-08
coef.5 = -8.129282e-10
coef.6 = 8.136946e-12
coef.7 = -2.072380e-14

# 6th order polynomial, need to find the point of maximum curvature.
rev.function = function(x) coef.1 + (coef.2*x^1) + (coef.3*x^2) + (coef.4*x^3) + (coef.5*x^4) + (coef.6*x^5) + (coef.7*x^6)

# Apply maxcurv funtion to the polynomial
# from previous experience, "spline" method seems to do well. 
maxcurv(x.range = c(x.min, x.max), fun = rev.function, graph = TRUE, method = "spline", x0ini = x0)
# Error


# 4th order polynomal, works with max curve but does not fit my data well (as tested with ANOVA)
rev.function = function(x) coef.1 + (coef.2*x^1) + (coef.3*x^2) + (coef.4*x^3)
maxcurv(x.range = c(x.min, x.max), fun = rev.function, graph = TRUE, method = "spline", x0ini = x0)
# No error

所以问题是:如何在maxcurv函数中使用我的6阶多项式?还是我缺少一些简单的语法?

0 个答案:

没有答案