How to fit a smooth curve on discrete data.

40 ビュー (過去 30 日間)
Raj Arora
Raj Arora 2022 年 10 月 19 日
編集済み: Torsten 2022 年 10 月 20 日
Hello all, I want to produce an equation that can develop a continous smooth curve (does not matter whether it follow any distribution or any plot) which connect the data given below. Using that equation I can interpolate data in between but I want a smoooth curve not a discrete curve. Can anyone please help me with this.
x = [3, 2.5, 2, 1.5, 1, 0.5]
y = [1.8, 1.75, 1.71, 1.55, 0.8, 1.25]
plot(x,y)

採用された回答

Torsten
Torsten 2022 年 10 月 19 日
Maybe something like this:
x = [3, 2.5, 2, 1.5, 1, 0.5];
y = [1.8, 1.75, 1.71, 1.55, 0.8, 1.25];
plot(x,y)
xx = linspace(x(1),x(end),100);
yy = interp1(x,y,xx,'cubic');
hold on
plot(xx,yy)
hold off
  4 件のコメント
Raj Arora
Raj Arora 2022 年 10 月 20 日
Alex can you tell me the procedure how you come up with this equaiton and values of p1 p2 p3 p4?
Torsten
Torsten 2022 年 10 月 20 日
編集済み: Torsten 2022 年 10 月 20 日
Alex's idea is to approximate your data by a curve. This curve does not pass exactly through each of your data points, but gives a good approximation over the complete interval with a small number of coefficients.
x = [3, 2.5, 2, 1.5, 1, 0.5];
y = [1.8, 1.75, 1.71, 1.55, 0.8, 1.25];
fun = @(p,x) p(1)./(p(2)+(x-p(3)).^2)+p(4) ;
fun1 = @(p) fun(p,x)-y;
p0 = [-0.1;0.1;0.9;2] ;
sol = lsqnonlin(fun1,p0)
Local minimum possible. lsqnonlin stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
sol = 4×1
-0.1412 0.1199 0.8609 1.8143
hold on
plot(x,y,'o')
xx = x(1):-0.01:x(end);
plot(xx,fun(sol,xx))
hold off

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

その他の回答 (0 件)

カテゴリ

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