0% found this document useful (0 votes)
32 views

MATLAB Examples - Interpolation

Interpolation coding

Uploaded by

santha kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

MATLAB Examples - Interpolation

Interpolation coding

Uploaded by

santha kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Interpolation

Interpolation is used to estimate data points between two known


points. The most common interpolation technique is Linear
Interpolation.
Known points
?

?
Interpolation
• Interpolation is used to estimate data points between two known points.
The most common interpolation technique is Linear Interpolation.
• In MATLAB we can use the interp1() function.
• The default is linear interpolation, but there are other types available, such
as:
– linear
– nearest
– spline
– cubic
– etc.
• Type “help interp1” in order to read more about the different options.
Given the following Data Points:
Interpolation
x y
0 15
(Logged
1 10 Data from
2 9 a given
Process)
3 6
4 2
5 0

x=0:5;
y=[15, 10, 9, 6, 2, 0]; ?

plot(x,y ,'o')
grid

Problem: Assume we want to find the interpolated value for, e.g., 𝑥 = 3.5
Interpolation
We can use one of the built-in Interpolation functions in MATLAB:
x=0:5; new_y =
y=[15, 10, 9, 6, 2, 0];
4
plot(x,y ,'-o')
grid on

new_x=3.5;
new_y = interp1(x,y,new_x)

MATLAB gives us the answer 4.


From the plot we see this is a good guess:
Interpolation
Given the following data: Temperature, T [ oC] Energy, u [KJ/kg]
100 2506.7
150 2582.8
200 2658.1
250 2733.7
300 2810.4
400 2967.9
500 3131.6

• Plot u versus T.
• Find the interpolated data and plot it in the same graph.
• Test out different interpolation types (spline, cubic).
• What is the interpolated value for u=2680.78 KJ/kg?
clear
clc

T = [100, 150, 200, 250, 300, 400, 500];


u=[2506.7, 2582.8, 2658.1, 2733.7, 2810.4, 2967.9, 3131.6];

figure(1)
plot(u,T, '-o')

% Find interpolated value for u=2680.78


new_u=2680.78;
interp1(u, T, new_u)

%Spline
new_u = linspace(2500,3200,length(u));
new_T = interp1(u, T, new_u, 'spline');
figure(2)
plot(u,T, new_u, new_T, '-o')
T = [100, 150, 200, 250, 300, 400, 500];
u=[2506.7, 2582.8, 2658.1, 2733.7, 2810.4, 2967.9, 3131.6];

figure(1)
plot(u,T, 'o')

or: plot(u,T, '-o')


% Find interpolated value for u=2680.78
new_u=2680.78;
interp1(u, T, new_u)
The interpolated value for u=2680.78 KJ/kg is:
ans =
215.0000

i.e, for 𝑢 = 2680.76 we get 𝑇 = 215

For ‘spline’/’cubic’ we get almost the same. This is


%Spline
because the points listed above are quite linear in their
new_u = linspace(2500,3200,length(u)); nature.
new_T = interp1(u, T, new_u, 'spline');
figure(2)
plot(u,T, new_u, new_T, '-o')

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy