当前位置:网站首页>MATLAB小技巧(29)多项式拟合 plotfit
MATLAB小技巧(29)多项式拟合 plotfit
2022-07-07 02:33:00 【mozun2020】
MATLAB小技巧(29)多项式拟合 plotfit
前言
MATLAB进行图像处理相关的学习是非常友好的,可以从零开始,对基础的图像处理都已经有了封装好的许多可直接调用的函数,这个系列文章的话主要就是介绍一些大家在MATLAB中常用一些概念函数进行例程演示!
多项式拟合是用一个多项式展开去拟合包含数个分析格点的一小块分析区域中的所有观测点,得到观测数据的客观分析场。展开系数用最小二乘拟合确定。但此方法的区域多项式拟合并不稳定,当资料缺测时更是如此,而且会导致分析在拟合的各个区域之间不连续。
在数据分析预测时,较常见的拟合方法,通过最小二乘法得到拟合多项式,从而可以预测得到为之参数的预测值,搜寻资料的时候遇到的这个示例,这里分享给大家,本文示例仿真MATLAB版本为MATLAB2015b。
一. MATLAB仿真
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%功能:多项式拟合
%环境:Win7,Matlab2015b
%Modi: C.S
%时间:2022-06-28
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% I. 清空环境变量
clear all
clc
tic
y=[100.3 101.1 102.1 101.1 101.6 104.4 102.5 102.1 103.9 103.9];
x=1:length(y);
A=polyfit(x,y,2) %2次相拟合,这个2可以修改的 模型系数
Z=polyval(A,x); %预测y
len=[1:20];
len1=polyval(Z,len); %预测走势
result=[y;Z]%实际值与预测值
error=abs(y-Z);%误差
bfb=error./y%相对误差
errorsum=sum(error)/length(y)%平均误差
bfbsum=sum(bfb)/length(y)%平均相对误差
figure(1)
plot(x,y,'r-',x,Z,'b-')
legend('实际值','拟合值')
title('实际值与预测值的比较','fontsize',15)
ylabel('Y','fontsize',15)
xlabel('X','fontsize',15)
figure(2)
plot(len,len1,'b-')
legend('拟合曲线')
title('拟合曲线图','fontsize',15)
ylabel('Y','fontsize',15)
xlabel('X','fontsize',15)
toc
二. 仿真结果
A =
-0.0144 0.5159 100.0167
result =
100.3000 101.1000 102.1000 101.1000 101.6000 104.4000 102.5000 102.1000 103.9000 103.9000
100.5182 100.9909 101.4348 101.8500 102.2364 102.5939 102.9227 103.2227 103.4939 103.7364
bfb =
0.0022 0.0011 0.0065 0.0074 0.0063 0.0173 0.0041 0.0110 0.0039 0.0016
errorsum =
0.6300
bfbsum =
0.0061
时间已过 2.561846 秒。
三. 小结
多项式拟合的仿真示例,后期可能会用到,这里做个笔记。每天学一个MATLAB小知识,大家一起来学习进步阿!
边栏推荐
- Leite smart home longhaiqi: from professional dimming to full house intelligence, 20 years of focus on professional achievements
- 面试中有哪些经典的数据库问题?
- How to find the literature of a foreign language journal?
- Kotlin之 Databinding 异常
- MySQL的安装
- C面试24. (指针)定义一个含有20个元素的double型数组a
- impdp的transform参数的测试
- LM小型可编程控制器软件(基于CoDeSys)笔记二十三:伺服电机运行(步进电机)相对坐标转换为绝对坐标
- Matlab / envi principal component analysis implementation and result analysis
- Navicat importing 15g data reports an error [2013 - lost connection to MySQL server during query] [1153: got a packet bigger]
猜你喜欢
Jmeter 5.5版本发布说明
哈趣投影黑馬之姿,僅用半年强勢突圍千元投影儀市場!
The difference between string constants and string objects when allocating memory
港科大&MSRA新研究:关于图像到图像转换,Fine-tuning is all you need
Handling hardfault in RT thread
学习笔记|数据小白使用DataEase制作数据大屏
Overview of FlexRay communication protocol
Go straight to the 2022ecdc fluorite cloud Developer Conference: work with thousands of industries to accelerate intelligent upgrading
直击2022ECDC萤石云开发者大会:携手千百行业加速智能升级
面试中有哪些经典的数据库问题?
随机推荐
JWT 认证
Unity C# 函数笔记
dolphinscheduler3.x本地启动
Redis(二)—Redis通用命令
Installing redis and windows extension method under win system
unity3d学习笔记
RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)`问题解决
当前发布的SKU(销售规格)信息中包含疑似与宝贝无关的字
场馆怎么做体育培训?
Crudini profile editing tool
A program lets you understand what static inner classes, local inner classes, and anonymous inner classes are
JVM in-depth
字符串常量与字符串对象分配内存时的区别
JWT certification
如何解决数据库插入数据显示SQLSTATE[HY000]: General error: 1364 Field ‘xxxxx‘ doesn‘t have a default value错误
VIM mapping large K
【解决】Final app status- UNDEFINED, exitCode- 16
c语言(结构体)定义一个User结构体,含以下字段:
企業如何進行數據治理?分享數據治理4個方面的經驗總結
2022 Android interview essential knowledge points, a comprehensive summary