How to plot the least square method?

Hello!
I have these measurements of an experiment where Kp and Kd are the coefficients of PD controller and model displays critical damping at these measurements.
I want to find the ideal curve with respect to least sqruare method.
How to do that?
I tried that but I don't know if is true.
plot(Kd,Kp,'go')
hold on
f = fit(Kd,Kp,'poly2');
plot(f,Kd,Kp,'b--')
xlim([0.2,1.3])
ylim([-2,22])
legend('Location','NorthWest');
hold off

3 件のコメント

Star Strider
Star Strider 2021 年 4 月 24 日
Kd_Kp = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/595780/Kd_Kp.xlsx')
Kd_Kp = 4×2 table
Kp Kd __ ___ 1 0.3 5 0.6 10 0.8 20 1.2
figure
scatter(Kd_Kp.Kd, Kd_Kp.Kp, 'filled')
xlabel('K_d')
ylabel('K_p')
grid
Since there are so few points, your options are limited!
RoBoTBoY
RoBoTBoY 2021 年 4 月 24 日
How do I connect these points with a curve?
So this diagram I drew is wrong?
Star Strider
Star Strider 2021 年 4 月 24 日
'How do I connect these points with a curve?
Whatever works, unless you have a mathematical model of the process that created them, and in that instance, use that mathematical model with a linear or nonlinear parameter estimation function. Then, using that function and the estimated parameters, calculate the fit and plot the line using those data.
One option is a spline fit —
Kd_Kp = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/595780/Kd_Kp.xlsx')
Kd_Kp = 4×2 table
Kp Kd __ ___ 1 0.3 5 0.6 10 0.8 20 1.2
Kd_v = linspace(min(Kd_Kp.Kd), max(Kd_Kp.Kd));
Kp_v = spline(Kd_Kp.Kd, Kd_Kp.Kp, Kd_v);
figure
scatter(Kd_Kp.Kd, Kd_Kp.Kp, 'filled')
hold on
plot(Kd_v, Kp_v, '-r')
hold off
xlabel('K_d')
ylabel('K_p')
grid
legend('Data','Spline Fit', 'Location','best')
It all depends on the result you want, and the process that created the data.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSmoothing についてさらに検索

タグ

質問済み:

2021 年 4 月 24 日

コメント済み:

2021 年 4 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by