Spline interpolation of input data

조회 수: 1 (최근 30일)
Emilio Pulli
Emilio Pulli 2021년 12월 6일
댓글: Mathieu NOE 2021년 12월 7일
I would like to obtain a spline interpolation of the following input data contained in the attached txt file. I try to explain how this data needs to be interpolated by describing the txt file:
  • The first row of the txt file indicates different number of Reynolds at which the measurements of some variables have been taken. Therefore, the txt file can be split into two subtables: the first goes from column 1 to 4 (Reynolds equal to 60000) and the second goes from column 5 to 8 (Reynolds equal to 100000).
  • Each column of the two subtables contains the measurements of a specific variable. In particular, in column 1 there are the measurements of the variable "beta" at Re=60000, column 2 measurements of "CL" at Re=60000, column 3 measurements of "CD" at Re=60000, column 4 measurements of "eff" at Re=60000. Analogously, column 5,6,7,8 contains respectively values of beta, CL, CD and eff at Re=100000.
  • Due to the fact that the first row of the txt file contains the Re numbers, the columns of the afore listed variables all started from row number 2.
Plotting the trends of CL,CD and eff with respect to the relative beta, it can be noticed how closed the trend of the variables are and, therefore, I would like to do a spline interpolation between the measurements obtained at 60000 and 100000 Re of CL,CD and eff variables. Unfortunately, as you can see from reading the txt file, the beta at 60000 and 100000 are not the same! Therefore, if, for instance, at row 3, the CL, CD and eff at Re=60000 have been measured for a beta equal to 3, maybe, at the same row, the CL, CD and eff at Re=100000 have been measured for a beta equal to 4. Therefore, the spline interpolation needs to be consistent.
Thak you in advance for your help!!!
  댓글 수: 2
KSSV
KSSV 2021년 12월 6일
What have you attempted?
Emilio Pulli
Emilio Pulli 2021년 12월 6일
편집: Emilio Pulli 2021년 12월 6일
I simply wrote the code to read the file:
format long
clc;
clear all;
close all;
load Bruining_reviewed.txt;
polars=Bruining_reviewed;
beta_vect_60=polars(2:end,1);
CL_vect_60=polars(2:end,2);
CD_vect_60=polars(2:end,3);
eff_vect_60=polars(2:end,4);
beta_vect_100=polars(2:end,5);
CL_vect_100=polars(2:end,6);
CD_vect_100=polars(2:end,7);
eff_vect_100=polars(2:end,8);
I do not know how to correctly do the sline interpolation...

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 12월 6일
hello
check this
not even sure the spline option is really needed here . A basic linear interpolation is good for the job
clc
clearvars
% I would like to obtain a spline interpolation of the following input data contained in the attached txt file.
% I try to explain how this data needs to be interpolated by describing the txt file:
% The first row of the txt file indicates different number of Reynolds at which the measurements of some variables have been taken.
% Therefore, the txt file can be split into two subtables: the first goes from column 1 to 4 (Reynolds equal to 60000)
% and the second goes from column 5 to 8 (Reynolds equal to 100000).
%
% Each column of the two subtables contains the measurements of a specific variable.
% In particular, in column 1 there are the measurements of the variable "beta" at Re=60000,
% column 2 measurements of "CL" at Re=60000,
% column 3 measurements of "CD" at Re=60000,
% column 4 measurements of "eff" at Re=60000.
% Analogously, column 5,6,7,8 contains respectively values of beta, CL, CD and eff at Re=100000.
%
% Due to the fact that the first row of the txt file contains the Re numbers,
% the columns of the afore listed variables all started from row number 2.
% Plotting the trends of CL,CD and eff with respect to the relative beta,
% it can be noticed how closed the trend of the variables are and, therefore,
% I would like to do a spline interpolation between the measurements obtained at 60000 and 100000 Re of CL,CD and eff variables.
% Unfortunately, as you can see from reading the txt file, the beta at 60000 and 100000 are not the same!
% Therefore, if, for instance, at row 3, the CL, CD and eff at Re=60000 have been measured for a beta equal to 3,
% maybe, at the same row, the CL, CD and eff at Re=100000 have been measured for a beta equal to 4.
% Therefore, the spline interpolation needs to be consistent.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data = readmatrix('Bruining_reviewed.txt');
%% data at Re=60000,
beta1 = data(2:end,1);
CL1 = data(2:end,2);
CD1 = data(2:end,3);
EFF1 = data(2:end,4);
%% data at Re=100000,
beta2 = data(2:end,1+4);
CL2 = data(2:end,2+4);
CD2 = data(2:end,3+4);
EFF2 = data(2:end,4+4);
figure(1)
plot(beta1,CL1,beta1,CD1,beta1,EFF1);
hold on
plot(beta2,CL2,beta2,CD2,beta2,EFF2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% resample all the data on common new beta axis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
new_beta = linspace(max(min(beta1),min(beta2)),min(max(beta1),max(beta2)),100);
new_CL1 = interp1(beta1,CL1,new_beta,'spline');
new_CD1 = interp1(beta1,CD1,new_beta,'spline');
new_EFF1 = interp1(beta1,EFF1,new_beta,'spline');
new_CL2 = interp1(beta2,CL2,new_beta,'spline');
new_CD2 = interp1(beta2,CD2,new_beta,'spline');
new_EFF2 = interp1(beta2,EFF2,new_beta,'spline');
figure(2)
plot(new_beta,new_CL1,new_beta,new_CD1,new_beta,new_EFF1);
hold on
plot(new_beta,new_CL2,new_beta,new_CD2,new_beta,new_EFF2);
  댓글 수: 11
Emilio Pulli
Emilio Pulli 2021년 12월 7일
Ok perfect, thank you! I will tale into consideration your method as alternatives to the one using csaps. Anyway your answer helped me to better tackle the problem!
Mathieu NOE
Mathieu NOE 2021년 12월 7일
My pleasure ! have a good day

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Splines에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by