curve fitting: how to get the fitting curve?

2 次查看(过去 30 天)
Hi everyone~
I did some curve fitting using curve fitting toolbox. But I don't know how to get the fitting curve. Can somebody help?
Also, in the future I want to do this using code. I'm reading the manual for spline fitting. http://www.mathworks.com/help/curvefit/construction.html
There seems to be lots of kinds of it. I want it shape-conserve, and must pass all the points. Which one should I use?
Any help is appreciated. Thank you!

回答(1 个)

John D'Errico
John D'Errico 2013-12-6
编辑:John D'Errico 2013-12-6
Use pchip to create a shape preserving spline. ppval can evaluate it.
  2 个评论
Yuji Zhang
Yuji Zhang 2013-12-9
Hi Thanks John~
I did testing and found "spline" is more shape-preserving. See the example.
Do you know how I can control the curve to go up or down at the side where there's no data? Any discussion's appreciated. Thank u~
Example: circles: data (4 points)
blue curve: pchip
red curve: spline
code:
x0 = [-10 -5 0 5 ];
y0 = [-50 -10 0 -10];
x = -50:0.1:50;
y1 = pchip (x0, y0, x);
y2 = spline (x0, y0, x);
plot(x0, y0, 'o');
hold on;
plot(x, y1,'b');
plot(x, y2,'r');
Yuji Zhang
Yuji Zhang 2013-12-9
Hi John~
Actually too bad. For my case, "pchip" doesn't work for the left end, and "spline" doesn't work for the right end. I just want a bell shape facing down.
See the plot:
Code:
x0 = [-10 -5 0 5 100];
y0 = [-50 -10 0 -10 -200];
x = -300:0.1:300;
y1 = pchip (x0, y0, x);
y2 = spline (x0, y0, x);
plot(x0, y0, 'o');
hold on;
plot(x, y1,'b');
plot(x, y2,'r');
ylim([-700 200]);
Let me know is there any way to fix it. Thanks a lot~

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by