필터 지우기
필터 지우기

How to extend smoothingspline predictions

조회 수: 3 (최근 30일)
Roederer Lyne
Roederer Lyne 2016년 2월 18일
댓글: Roederer Lyne 2016년 2월 26일
I need to extend my best fit curve so that I can get a current prediction when y position = 70 mm, is there a possible way to do this?
clc
clear all
load TOD_regular_lda.mat
x = 1;
for i = 1:1:5
current(x) = mean(lda(x).um);
z(x) = lda(x).z;
C = current;
x = x + 1;
end
C = C(:);
Z = z(:);
% a = fit(C,Z,'poly2');
b = fit(C,Z,'smoothingspline');
plot(C,Z)
axis([-0.05 0 -400 100 ])
hold on
% plot(a,'r--')
plot(b,'g--')
xlabel('Current (m/s)')
ylabel('y position (mm)')

채택된 답변

Anish Mitra
Anish Mitra 2016년 2월 22일
I cannot comment on the quality of the extension (extrapolation) of the fit, since it depends on the data. However, the 'feval' method can be used with the 'cfit' object that is returned by the 'fit' function.
Following is a sample code to extend the fitted values, and compare them to the original synthetic data.
% Code to test extrapolation for different fit types
% (smoothingspline and quadratic polynomial curve)
clear; close all; clc;
% Generate data for the entire range (to compare the extrapolated result
% later on
x_all = (0:0.01:5)';
y_all = 0.2*x_all.^3 - x_all.^2;
% Obtain fitting data
x_data = x_all(x_all>1 & x_all<4);
y_data = y_all(x_all>1 & x_all<4);
% Fit a smoothing spline
fit_ss = fit(x_data,y_data,'smoothingspline');
% Fit a quadratic polynomial curve
fit_poly = fit(x_data,y_data,'poly2');
% Evaluate the fitted function for the original range using the feval
% function
y_ss = feval(fit_ss,x_all);
y_poly = feval(fit_poly,x_all);
% Plot all data
figure; hold on;
plot(x_all, y_all, 'b');
plot(x_data, y_data, 'g.');
plot(x_all, y_ss,'r');
plot(x_all, y_poly, 'k');
Note that 'SmoothingSpline' is generally not recommended if the objective is to then extrapolate the fit to outside the initial data limits. The following example contains more details on Smoothing Splines.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Working with Signals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by