使自定义函数适合数据

问题描述 投票:1回答:3

我有一系列数据,例如:

0.767838478
0.702426493
0.733858228
0.703275979
0.651456058
0.62427187
0.742353261
0.646359026
0.695630431
0.659101665
0.598786652
0.592840135
0.59199059

我知道最适合形式的等式:

y=ae^(b*x)+c

Formula

如何使自定义函数适合此数据?

在没有正确答案的情况下,已经在LibreOffice论坛上询问过Similar question。如果你能帮助我知道怎么做,我将不胜感激。优选地,答案适用于任何自定义函数,而不是适用于此特定情况的变通方法。

curve-fitting openoffice-calc libreoffice-calc data-fitting trendline
3个回答
1
投票

有多种可能的解决方案。但有一种方法如下:

为了确定趋势线函数a中的band y = a*e^(b*x),有使用原生Calc函数(LINESTEXPLN)的解决方案。

因此我们可以将y = a*e^(b*x)+c视为y-c= a*e^(b*x),所以如果我们知道c,那么y = a*e^(b*x)的解决方案也可以采取。怎么知道c? Exponential Curve Fitting描述了一种方法。然后进行b,a和c的近似。

我将Exponential Curve Fitting : source listing的delphi代码的主要部分翻译为StarBasicCalcc的微调部分直到现在才翻译。作为专业和发烧友程序员的待办事项。

例:

enter image description here

数据:

x   y
0   0.767838478
1   0.702426493
2   0.733858228
3   0.703275979
4   0.651456058
5   0.62427187
6   0.742353261
7   0.646359026
8   0.695630431
9   0.659101665
10  0.598786652
11  0.592840135
12  0.59199059

公式:

B17=EXP(INDEX(LINEST(LN($B$2:$B$14),$A$2:$A$14),1,2))

C17=INDEX(LINEST(LN($B$2:$B$14),$A$2:$A$14),1,1)

y = a*e^(b*x)也是用于图表趋势线计算的函数。

B19=INDEX(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,1)

C19=INDEX(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,2)

D19=INDEX(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,3)

码:

function trendExpPlusC(rangey as variant, rangex as variant) as variant

 'get values from ranges
 redim x(ubound(rangex)-1) as double
 redim y(ubound(rangex)-1) as double
 for i = lbound(x) to ubound(x)
  x(i) = rangex(i+1,1)
  y(i) = rangey(i+1,1)
 next

 'make helper arrays
 redim dx(ubound(x)-1) as double
 redim dy(ubound(x)-1) as double
 redim dxyx(ubound(x)-1) as double
 redim dxyy(ubound(x)-1) as double
 for i = lbound(x) to ubound(x)-1
  dx(i) = x(i+1) - x(i)
  dy(i) = y(i+1) - y(i)
  dxyx(i) = (x(i+1) + x(i))/2
  dxyy(i) = dy(i) / dx(i)
 next

 'approximate b
 s = 0
 errcnt = 0
 for i = lbound(dxyx) to ubound(dxyx)-1
  on error goto errorhandler
  s = s + log(abs(dxyy(i+1) / dxyy(i))) / (dxyx(i+1) - dxyx(i))
  on error goto 0
 next
 b = s / (ubound(dxyx) - errcnt)

 'approximate a
 s = 0
 errcnt = 0
 for i = lbound(dx) to ubound(dx)
  on error goto errorhandler
  s = s + dy(i) / (exp(b * x(i+1)) - exp(b * x(i)))
  on error goto 0
 next
 a = s / (ubound(dx) + 1 - errcnt)

 'approximate c 
 s = 0
 errcnt = 0
 for i = lbound(x) to ubound(x)
  on error goto errorhandler
  s = s + y(i) - a * exp(b * x(i))
  on error goto 0
 next
 c = s / (ubound(x) + 1 - errcnt)

 'make y for (y - c) = a*e^(b*x)
 for i = lbound(x) to ubound(x)
  y(i) = log(abs(y(i) - c))
 next

 'get a and b from LINEST for (y - c) = a*e^(b*x)
 oFunctionAccess = createUnoService( "com.sun.star.sheet.FunctionAccess" )
 args = array(array(y), array(x))
 ab = oFunctionAccess.CallFunction("LINEST", args)

 if a < 0 then a = -exp(ab(0)(1)) else a = exp(ab(0)(1))

 b = ab(0)(0)

 trendExpPlusC = array(a, b, c)

exit function

errorhandler:
 errcnt = errcnt + 1
 resume next

end function

0
投票

公式y = beax是LibreOffice图表趋势线的exponential regression equation

exponential equation chart


0
投票

LibreOffice导出所有设置LibreOffice的所有设置,全部在LibreOffice文件夹中。

C:\ Users \ a←安装操作系统时,输入名称。\ AppData←文件管理器〜“隐藏项目”打开,将显示AppData文件夹。\ Roaming \ LibreOffice

备份LibreOffice文件夹,重新安装时,将LibreOffice文件夹放在其原始位置。

注意: 1.如果安装是预览版,因为预览版的名称是LibreOfficeDev,所以将显示LibreOfficeDev文件夹。 2.正式版可与预览版一起安装,如果安装了正式版和预览版,将显示LibreOffice文件夹和LibreOfficeDev文件夹。 3.要清除所有设置,只需删除LibreOffice文件夹,然后打开程序,将创建一个新的LibreOffice文件夹。

LibreOffice导出我制作公共路径的单个工具栏

C:\ Users \ a←安装操作系统时,输入名称。\ AppData←文件管理器〜“隐藏项目”打开,将显示AppData文件夹。\ Roaming \ LibreOffice \ 4 \ user \ config \ soffice。 cfg \ modules \请连接下面各个软件的分支路径。

分支路径

\modules\StartModule\toolbar\The "Start" toolbar I made is placed here.

\modules\swriter\toolbar\The "writer" toolbar I made is placed here.

\modules\scalc\toolbar\The "calc" toolbar I made is placed here.

\modules\simpress\toolbar\The "impress" toolbar I made is placed here.

\modules\sdraw\toolbar\The "draw" toolbar I made is placed here.

\modules\smath\toolbar\The "math" toolbar I made is placed here.

\modules\dbapp\toolbar\The "base" toolbar I made is placed here.

备份文件,重新安装时,将文件放在原始位置。

注意:

  1. 由于我自己制作的工具栏,默认文件名,会自动使用Numbering,所以要打开文件,可以知道工具栏的名称。
  2. 前端文件名“custom_toolbar_”无法更改,更改将导致错误,后面的文件名可以更改。例如:custom_toolbar_c01611ed.xml→custom_toolbar_AAA.xml。
  3. 做好工具栏,可以复制到其他地方使用。例如:在“编写器”中做好工具栏,可以复制到“calc”的地方使用。

LibreOffice自制符号工具栏

步骤1启动“录制宏功能”工具\选项\高级\启用宏录制(勾选),在“工具\宏”中,将出现“录制宏”选项。

步骤2录制宏工具\宏\录制宏→录制操作(单击“Ω”输入符号→选择符号→插入)→停止录制→存储在“Module1”中的宏名称为Main→Modify Main name→Save。

步骤3添加项目新工具栏工具\自定义\工具栏→添加→输入名称(例如:符号)→确定,新工具栏将显示在左上角。

步骤4将宏添加项目新工具栏工具\自定义\工具栏\类别\宏\我的宏\标准\模块1 \主→单击“主”→添加项目→修改→重命名(可以用符号命名)→确定→确定。

© www.soinside.com 2019 - 2024. All rights reserved.