Interpolation between multi curves

clc clear close all x=linspace(0,180,180)*pi/180
y200 = -0.0023.*x.^6 + 0.0296.*x.^5 - 0.1574.*x.^4 + 0.3502.*x.^3 - 0.1597.*x.^2 + 0.0567.*x - 0.0009;% 200 km y500 = -0.0019.*x.^6 + 0.0219.*x.^5 - 0.1172.*x.^4 + 0.2772.*x.^3 - 0.1297.*x.^2 + 0.0306.*x + 0.0001;% 500 km y1000 = -0.0029.*x.^6 + 0.0342.*x.^5 - 0.1786.*x.^4 + 0.4265.*x.^3 - 0.3061.*x.^2 + 0.0695.*x - 0.0033; % 1000 km
figure(1) plot(x,y1000,x,y500,x,y200)
I want to use the interpolation method to find the curves at any required altitude in the plot below, I already have the the polynomial of each curve as seen in the script

4 Comments

Let me clarify your question. If my understanding is correct, you have data set for each curve (each altitude). But data length is different for each curve. So you would like to adjust data size for each curve by interpolation.
In such a case, I think "spline" function will be helpful.
https://www.mathworks.com/help/matlab/ref/spline.html
Dear Akira, thanks for your response, what I want is to find a new curves for any altitude I want such as 300 or 4500 km for instant
"what I want is to find a new curves for any altitude I want such as 300 or 4500 km"
My answer will give you exactly that.
Stephen23
Stephen23 on 16 Feb 2017
Edited: Stephen23 on 16 Feb 2017
@Oday Shahadh: you just edited your question into something totally different. This does not help because your original task (interpolating scattered data) was much simpler than this one.
Your idea of creating polynomials and then trying to interpolate them is more difficult than simply using an interpolant on your original data. Basically to interpolate the polynomials you would have to generate some data points... then you might as well use the original data points. So what you are trying to do is more complicated.
If you want more help I would suggest that you:
  1. revert back to your original question, with the original figure.
  2. upload sample data (this is the third time that you have been asked to provide sample data).

Sign in to comment.

 Accepted Answer

Stephen23
Stephen23 on 16 Feb 2017
Edited: Stephen23 on 16 Feb 2017
Use one of the interpolation tools for scattered data:
If you edit your question and upload some sample data by clicking the paperclip button then I can show you how to do it. It is hard to demonstrate code using imaginary data.
EDIT the original question asked how to interpolate values that were obtained by digitising the curves in this figure:
EDIT based on the original question, this code will interpolate the data points directly:
% Read CSV files:
S = dir('*.csv');
C = cell(size(S));
A = nan(size(S));
for k = 1:numel(S)
C{k} = csvread(S(k).name,1,0);
A(k) = sscanf(S(k).name,'%d');
end
% Merge data into matrices:
N = cellfun('size',C,1);
A = arrayfun(@(a,n)repmat(a,n,1),A,N,'Uni',0);
M = [vertcat(A{:}),vertcat(C{:})]; % [alt,phi,F_e]
% Interpolate:
F = TriScatteredInterp(M(:,1:2),M(:,3),'natural');
and tested:
>> rho = 0:0.1:pi; % angles rho
>> alt = 800*ones(size(rho)); % altitude
>> out = F(alt,rho)
out =
Columns 1 through 7
NaN 0.024935 0.04987 0.074805 0.09974 0.12468 0.14961
Columns 8 through 14
0.17455 0.19948 0.22442 0.24935 0.27429 0.29923 0.32416
Columns 15 through 21
0.3491 0.37404 0.39897 0.42391 0.44885 0.47378 0.49872
Columns 22 through 28
0.52366 0.54859 0.57353 0.59847 0.62341 0.64835 0.67328
Columns 29 through 32
0.69822 0.72316 0.7481 0.77304
Because the Excel file is very inconvenient to work with I transferred the data to simple CSV files, available here:

8 Comments

Dear Sir,
  1. I will take the range of altitude from 200-1000
  2. I used cyrve fiiting and find polynomial for eacr curve:for 200 km
y = -0.0023x6 + 0.0296x5 - 0.1574x4 + 0.3502x3 - 0.1597x2 + 0.0567x - 0.0009
for 500 km :
y = -0.0019x6 + 0.0219x5 - 0.1172x4 + 0.2772x3 - 0.1297x2 + 0.0306x + 0.0001
and for 1000 km:
y = -0.0029x6 + 0.0342x5 - 0.1786x4 + 0.4265x3 - 0.3061x2 + 0.0695x - 0.0033
so how can to interpolate these three polynomials to find a new curve for any given altitude between 200-1000 km?
y = -0.0023x6 + 0.0296x5 - 0.1574x4 + 0.3502x3 - 0.1597x2 + 0.0567x - 0.0009
Fitting lots of polynomials before interpolating will make interpolating difficult.
If the goal is just to calculate new values, then actually there is no point in creating explicit polynomial curves at all, I would simply use the interpolation tool directly to get the values that I want.
However if you particularly need a polynomial function then I would still interpolate first at the altitude I wanted the polynomial for, and fit a polynomial to that.
Please answer this question: do you need a polynomial curve as your output, or do you want to calculate values for any altitude?
I will also request for a second time: if you want further help please upload your data file (e.g. sampled points) in a new comment.
Dear sir, there is no need to produce a new polynomials, just when enter a new altitude value the script have to produce a new curve,so there is no need to produce a new polynomials
Stephen23
Stephen23 on 16 Feb 2017
Edited: Stephen23 on 16 Feb 2017
"there is no need to produce a new polynomials"
I never suggested that you should generate new polynomials to perform this interpolation. That would be a pointlessly complicated way to solve this task. Not only that it would introduce a significant amount of error into your results because both polynomials and interpolation add error.
I suggested multiple times that you should simply interpolate the original data points without those polynomials. Why did I suggest this? Because it would be easier.
For a fourth time: please upload the original sample data by clicking the paperclip button.
Sorry for confused happened, I appreciate your patient with me, I attached the data into excel sheet
Dear Stephen, I appreciate every second you spent helping me, you did a lot and you did the best, thanks, it works, really thanks
Can I ask for a clarification Stephen?
@Oday Shahadh: of course. What would you like to ask about?

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Asked:

on 16 Feb 2017

Commented:

on 18 Feb 2017

Community Treasure Hunt

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

Start Hunting!