在gnuplot中拟合曲线:重复拟合会产生不同的结果

如何解决在gnuplot中拟合曲线:重复拟合会产生不同的结果

我一直在尝试将方程y = Ax ^ 2 + Bx + C拟合到以下数据集(data.txt):

-9.39398e+09 1.52819e-19
-9.07008e+09 1.50337e-19
-8.74617e+09 1.44628e-19
-8.42227e+09 1.37837e-19
-8.09817e+09 1.31042e-19
-7.77427e+09 1.24624e-19
-7.45037e+09 1.18873e-19
-7.12646e+09 1.11213e-19
-6.80256e+09 1.00253e-19
-6.47865e+09 8.95713e-20
-6.15475e+09 7.92741e-20
-5.83066e+09 6.94736e-20
-5.50675e+09 6.02803e-20
-5.18285e+09 5.1667e-20
-4.85894e+09 4.37442e-20
-4.53504e+09 3.65056e-20
-4.21113e+09 3.00328e-20
-3.88723e+09 2.4281e-20
-3.56332e+09 1.93223e-20
-3.23923e+09 1.49467e-20
-2.91533e+09 1.13226e-20
-2.59142e+09 8.33933e-21
-2.26752e+09 5.93767e-21
-1.94361e+09 4.05992e-21
-1.61971e+09 2.64039e-21
-1.29581e+09 1.623e-21
-9.71713e+08 9.0523e-22
-6.47809e+08 4.05351e-22
-3.23904e+08 8.97219e-23
0 0
3.23904e+08 8.97219e-23
6.47809e+08 4.05351e-22
9.71713e+08 9.0523e-22
1.29581e+09 1.623e-21
1.61971e+09 2.64039e-21
1.94361e+09 4.05992e-21
2.26752e+09 5.93767e-21
2.59142e+09 8.33933e-21
2.91533e+09 1.13226e-20
3.23923e+09 1.49467e-20
3.56332e+09 1.93223e-20
3.88723e+09 2.4281e-20
4.21113e+09 3.00328e-20
4.53504e+09 3.65056e-20
4.85894e+09 4.37442e-20
5.18285e+09 5.1667e-20
5.50675e+09 6.02803e-20
5.83066e+09 6.94736e-20
6.15475e+09 7.92741e-20
6.47865e+09 8.95713e-20
6.80256e+09 1.00253e-19
7.12646e+09 1.11213e-19
7.45037e+09 1.18873e-19
7.77427e+09 1.24624e-19
8.09817e+09 1.31042e-19
8.42227e+09 1.37837e-19
8.74617e+09 1.44628e-19
9.07008e+09 1.50337e-19
9.39398e+09 1.52819e-19

在gnuplot中,我键入了命令:

fit a*x**2 + b*x + c 'data.txt' via a,b,c

吐出的结果是:

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
a               = -1.73185e-20     +/- 2.658e-11    (1.535e+11%)
b               = 1                +/- 0.1325       (13.25%)
c               = 1                +/- 1.076e+09    (1.076e+11%)

correlation matrix of the fit parameters:
                a      b      c      
a               1.000 
b              -0.000  1.000 
c              -0.739  0.000  1.000 

当我使用a,b,c的值进行绘图时,数据与拟合线之间没有拟合。

所以我再次给出命令

fit a*x**2 + b*x + c 'data.txt' via a,c

然后gnuplot发出以下输出:

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
a               = -1.73185e-20     +/- 3.278e-21    (18.93%)
b               = -2.24969e-22     +/- 1.645e-11    (7.313e+12%)
c               = 1                +/- 0.1327       (13.27%)

correlation matrix of the fit parameters:
                a      b      c      
a               1.000 
b               0.000  1.000 
c              -0.739 -0.001  1.000

a,b,c的值已更改,但这也不能令人满意地拟合数据。 所以我再次给出命令:

fit a*x**2 + b*x + c 'data.txt' via a,c

这次吐出了以下结果:

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
a               = 1.96019e-39      +/- 5.98e-33     (3.051e+08%)
b               = -2.24969e-22     +/- 2.98e-23     (13.25%)
c               = -1.11942e-21     +/- 2.421e-13    (2.162e+10%)

correlation matrix of the fit parameters:
                a      b      c      
a               1.000 
b               0.000  1.000 
c              -0.739 -0.000  1.000 

这也不能令人满意。

然后再次重复执行fit命令并获得以下信息:

After 4 iterations the fit converged.
final sum of squares of residuals : 2.4063e-39
abs. change during last iteration : -2.64182e-48


Hmmmm.... Sum of squared residuals is zero. Can't compute errors.

Final set of parameters 
======================= 

a               = 1.96019e-39    
b               = 2.01689e-41    
c               = -1.11942e-21

现在a,b,c的值可以很好地拟合数据。

我的问题是:

  1. 为什么在第一次,第二次和第三次尝试中a,b,c的值不能很好地拟合数据?

  2. 我可以使用最后计算出的a,b,c值吗?

  3. 在上一次尝试的输出中,我应该担心以下消息:“ Hmmmm...。残差平方和为零。无法计算错误。” ?

解决方法

我认为您的值的数值范围太宽,我猜想由于截断错误,某些计算(例如残差)是错误的。

如果您将第一列乘以10 ^ -9,第二列乘以10 ^ 18来规范化数据

startHttpServerBtn.addActionListener((e)
                -> new Thread(() -> {
        String[] args = new String[1];
        args[0] = "--spring.profiles.active=dev";
        BootWebApplication.main(args)
    }).start());

然后

BootWebApplication.main(new String[0]);

稳定


如果A,B,C是归一化数据中的拟合参数,则可以通过以下方法获取初始的a,b,c参数(与原始数据相对应的参数):

-9.39398 0.152819
-9.07008 0.150337
-8.74617 0.144628
-8.42227 0.137837
-8.09817 0.131042
-7.77427 0.124624
-7.45037 0.118873
-7.12646 0.111213
-6.80256 0.100253
-6.47865 0.0895713
-6.15475 0.0792741
-5.83066 0.0694736
-5.50675 0.0602803
-5.18285 0.051667
-4.85894 0.0437442
-4.53504 0.0365056
-4.21113 0.0300328
-3.88723 0.024281
-3.56332 0.0193223
-3.23923 0.0149467
-2.91533 0.0113226
-2.59142 0.00833933
-2.26752 0.00593767
-1.94361 0.00405992
-1.61971 0.00264039
-1.295810 0.001623
-0.971713 0.00090523
-0.647809 0.000405351
-0.323904 0.0000897219
0 0
0.323904 0.0000897219
0.647809 0.000405351
0.971713 0.00090523
1.295810 0.001623
1.61971 0.00264039
1.94361 0.00405992
2.26752 0.00593767
2.59142 0.00833933
2.91533 0.0113226
3.23923 0.0149467
3.56332 0.0193223
3.88723 0.024281
4.21113 0.0300328
4.53504 0.0365056
4.85894 0.0437442
5.18285 0.051667
5.50675 0.0602803
5.83066 0.0694736
6.15475 0.0792741
6.47865 0.0895713
6.80256 0.100253
7.12646 0.111213
7.45037 0.118873
7.77427 0.124624
8.09817 0.131042
8.42227 0.137837
8.74617 0.144628
9.07008 0.150337
9.39398 0.152819

说明/更新2:

让(xi,yi),i = 1,2,.. n为您要拟合的初始数据:

gnuplot> fit a*x**2 + b*x + c 'data.txt' via a,b,c
iter      chisq       delta/lim  lambda   a             b             c            
   0 2.4049966612e-03   0.00e+00  4.62e-02    1.960970e-03   6.941376e-15  -1.162140e-03
   1 2.4049966612e-03  -1.79e-09  4.62e-03    1.960970e-03   6.941376e-15  -1.162140e-03
iter      chisq       delta/lim  lambda   a             b             c            

After 1 iterations the fit converged.
final sum of squares of residuals : 0.002405
rel. change during last iteration : -1.78522e-14

degrees of freedom    (FIT_NDF)                        : 56
rms of residuals      (FIT_STDFIT) = sqrt(WSSR/ndf)    : 0.00655335
variance of residuals (reduced chisquare) = WSSR/ndf   : 4.29464e-05

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
a               = 0.00196097       +/- 3.136e-05    (1.599%)
b               = 6.94138e-15      +/- 0.0001416    (2.04e+12%)
c               = -0.00116214      +/- 0.00128      (110.1%)

correlation matrix of the fit parameters:
                a      b      c      
a               1.000 
b               0.001  1.000 
c              -0.745 -0.001  1.000 

但是,对于您的计算机,最好使用:

a = A / (10^18 * 10^18) = A * 10^-36
b = B / (10^9 * 10^18) = B * 10^-27
c = C / 10^18 = C * 10^-18

其中X = 10 ^ -9 x,Y = 10 ^ 18 y

要从A,B,c中找到a,b,c,只需进行识别即可:

y ≈ a x^2 + b x + c

因此,您有:

Y ≈ A X^2 + B X + C

现在可以吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res