Charts 将自定义函数拟合到数据
我有一系列数据,例如:Charts 将自定义函数拟合到数据,charts,curve-fitting,libreoffice-calc,data-fitting,trendline,Charts,Curve Fitting,Libreoffice Calc,Data Fitting,Trendline,我有一系列数据,例如: 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 如何使自定义函数适合此数据 已经在LibreOffice论坛上被问及,但没有得到正确的回答。如果你能帮
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
如何使自定义函数适合此数据
已经在LibreOffice论坛上被问及,但没有得到正确的回答。如果你能帮我知道怎么做,我将不胜感激。最好是适用于任何自定义函数的答案,而不是适用于此特定情况的变通方法。公式y=beax适用于LibreOffice图表趋势线
有多种可能的解决方案。但一种方法是: 为了确定趋势线函数
y=a*e^(b*x)
中的a
和b
,有使用本机Calc
函数的解决方案(LINEST
,EXP
,LN
)
因此,我们可以将y=a*e^(b*x)+c
视为y-c=a*e^(b*x)
,因此如果我们知道c
,也可以采用y=a*e^(b*x)
的解决方案。如何认识c?中描述了一种方法。然后对b、a和c进行近似
我将delphi代码的主要部分从翻译成StarBasic
,用于Calc
。直到现在,c
的微调部分才被翻译。作为专业和热心的程序员为您服务
例如:
数据:
公式:
B17
:=EXP(索引(LINEST(LN($B$2:$B$14),$A$2:$A$14),1,2))
C17
:=索引(LINEST(LN($B$2:$B$14),$A$2:$A$14),1,1)
y=a*e^(b*x)
也是用于图表趋势线计算的函数
B19
:=索引(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,1)
C19
:=索引(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,2)
D19
:=索引(TRENDEXPPLUSC($B$2:$B$14,$A$2:$A$14),1,3)
代码:
函数trendExpPlusC(rangey作为变量,rangex作为变量)作为变量
'从范围中获取值
重拨x(ubound(rangex)-1)为双精度
重播y(ubound(范围X)-1)为双精度
对于i=lbound(x)到ubound(x)
x(i)=范围x(i+1,1)
y(i)=范围y(i+1,1)
下一个
'生成辅助程序数组
重拨dx(ubound(x)-1)作为双精度
重播dy(ubound(x)-1)为双精度
重拨dxyx(ubound(x)-1)为双精度
重拨dxyy(ubound(x)-1)为双精度
对于i=lbound(x)到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)
下一个
”“大概是b
s=0
errcnt=0
对于i=lbound(dxyx)到ubound(dxyx)-1
关于错误转到错误处理程序
s=s+log(abs(dxyy(i+1)/dxyy(i))/(dxyx(i+1)-dxyx(i))
错误转到0
下一个
b=s/(ubound(dxyx)-errcnt)
“大概是
s=0
errcnt=0
对于i=lbound(dx)到ubound(dx)
关于错误转到错误处理程序
s=s+dy(i)/(exp(b*x(i+1))-exp(b*x(i)))
错误转到0
下一个
a=s/(ubound(dx)+1-errcnt)
'近似c
s=0
errcnt=0
对于i=lbound(x)到ubound(x)
关于错误转到错误处理程序
s=s+y(i)-a*exp(b*x(i))
错误转到0
下一个
c=s/(ubound(x)+1-错误)
'使y代表(y-c)=a*e^(b*x)
对于i=lbound(x)到ubound(x)
y(i)=对数(abs(y(i)-c))
下一个
'从LINEST获取a和b的(y-c)=a*e^(b*x)
oFunctionAccess=createUnoService(“com.sun.star.sheet.FunctionAccess”)
args=数组(数组(y)、数组(x))
ab=oFunctionAccess.CallFunction(“LINEST”,args)
如果a<0,则a=-exp(ab(0)(1)),否则a=exp(ab(0)(1))
b=ab(0)(0)
trendExpPlusC=阵列(a、b、c)
退出功能
错误处理程序:
errcnt=errcnt+1
下一步继续
端函数
LibreOffice导出所有设置
LibreOffice的所有设置,都在LibreOffice文件夹中
C:\Users\a←安装操作系统时,名称
已输入。\AppData←文件管理器~“隐藏项目”打开时,AppData
将显示文件夹。\Roaming\LibreOffice
备份LibreOffice文件夹,重新安装时,将LibreOffice文件夹放在原始位置
注意:1.如果安装是preview edition,因为preview edition的名称是LibreOfficeDev,所以LibreOfficeDev文件夹将被删除 显示。
2.正式版可以与预览版一起安装,如果同时安装了正式版和预览版,则LibreOffice 将显示文件夹和LibreOfficeDev文件夹。
3.要清除所有设置,只需删除LibreOffice文件夹,然后打开程序,将创建一个新的LibreOffice文件夹 LibreOffice导出我制作的单个工具栏 公共路径 C:\Users\a←安装操作系统时,名称 已输入。\AppData←文件管理器~“隐藏项目”打开时,AppData 文件夹将被删除 已显示。\Roaming\LibreOffice\4\user\config\soffice.cfg\modules\Please 连接下面单个软件的分支路径 分支路径
\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在 “工具\宏”,将出现“录制宏”选项 步骤2录制宏工具\Macros\Record宏→记录动作(点击“Ω”输入符号→选择符号?
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
\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.