curve fitting: how to get the fitting curve?

1 visualización (últimos 30 días)
Yuji Zhang
Yuji Zhang el 6 de Dic. de 2013
Comentada: Yuji Zhang el 9 de Dic. de 2013
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!

Respuestas (1)

John D'Errico
John D'Errico el 6 de Dic. de 2013
Editada: John D'Errico el 6 de Dic. de 2013
Use pchip to create a shape preserving spline. ppval can evaluate it.
  2 comentarios
Yuji Zhang
Yuji Zhang el 9 de Dic. de 2013
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 el 9 de Dic. de 2013
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~

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by