필터 지우기
필터 지우기

How to find a polynomial that best fit with scatter plot?

조회 수: 24 (최근 30일)
Andi
Andi 2023년 5월 12일
댓글: Andi 2023년 5월 14일
Hi everyone,
I am trying to find a best-fit polynomial equation that works well for my data set (two parameters x, and y).
First, I attempt to fit a polynomial line using Excel (figure attached). The equation shows the best fit with the original scatter plot (the red line is the best fit polynomial line).
However, when I try to estimate values with the best-fit equation, it looks very different from actual data points.
A similar error is observed when I attempt to use the Matlab function polyfilt.
clear all
clc
data=readmatrix('lv_vl.csv');
x=data(:,1);
y=data(:,2);
scatter(x,y,'b')
p = polyfit(x,y,2)
May someone suggets me how i can fix this.
(data is also attached).

채택된 답변

Walter Roberson
Walter Roberson 2023년 5월 12일
편집: Walter Roberson 2023년 5월 12일
data=readmatrix('lv_vl.csv');
x=data(:,1);
y=data(:,2);
scatter(x,y,5,'.r')
p = polyfit(x,y,2);
eqn = poly2sym(p)
eqn = 
xest = linspace(min(x), max(x), 75);
yest = polyval(p, xest);
hold on
plot(xest, yest, '-b');
title(char(vpa(eqn,5)))
  댓글 수: 9
Walter Roberson
Walter Roberson 2023년 5월 14일
The sum of squared error is still pretty high for degree 4, and there are still fairly visible artifacts.
Andi
Andi 2023년 5월 14일
True, but if I overestimate, then I am unable to incorporate other parameters that have a time-varying influence on the time series. Therefore, I decided to go with a 4-order polynomial.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by