Matlab code by least square method

11 ビュー (過去 30 日間)
Ahmet Tasgetiren
Ahmet Tasgetiren 2020 年 4 月 11 日
コメント済み: Image Analyst 2021 年 1 月 1 日
Write matlab codes that fit curves n. a degree function using the least squares method.?

回答 (2 件)

David Hill
David Hill 2020 年 4 月 11 日
If you can use matlab functions, it is quite easy:
p=polyfit(x,y,n);
  2 件のコメント
Mat m
Mat m 2021 年 1 月 1 日
least square method matlab code
Image Analyst
Image Analyst 2021 年 1 月 1 日
Mat, yes, that's what it is.

サインインしてコメントする。


Image Analyst
Image Analyst 2020 年 4 月 11 日
You can do something like this with polyfit. Run the attached demo for a full demo to create the plots below. Adapt as needed.
% Do the regression with polyfit to fit a cubic polynomial
cubicCefficients = polyfit(x, y, 3)
% The x coefficient, slope, is coefficients(1).
% The constant, the intercept, is coefficients(2).
% Make fit. It does NOT need to have the same
% number of elements as your training set,
% or the same range, though it could if you want.
% Make 500 fitted samples going from -13 to +12.
xFit = linspace(-13, 12, 500);
% Get the estimated values with polyval()
yFit = polyval(cubicCefficients, xFit);
  2 件のコメント
Diaz Iskakov
Diaz Iskakov 2020 年 12 月 13 日
Hello,
Very interesting but how could i create thus kind of function in high dimension problems ? Like R7->R
(X1,X2,X3,X4,X5,X7)->X
Thank
Image Analyst
Image Analyst 2020 年 12 月 13 日
You can use matrix division, like coefficients = A\y. Start a new question and provide some data to someone can do a multiple linear regression for you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by