Interpolate different sets of data using the same interval

34 views (last 30 days)
sairos
sairos on 16 Oct 2015
Answered: Martin Schätz on 16 Oct 2015
Hello everyone,
I'm working on an university project in CFD, basically i have a fluid flowing in a pipe, i need to verify that the solution of the simulation in Fluent is mesh independent, so i have 3 type of grid, the raw one, medium and the finest one. I plot the velocity values along the axis and i must compare the results in 3 cases (if the root mean square is < then 2%, it's ok). My problem is, since the finest mesh have more cells then the medium one etc, I have more values for the finest mesh on the same interval.
Like:
raw mesh x = 0 --> y = 1 x = 0,5 --> y = 1,2
medium mesh x = 0 --> y = 1 x = 0,1 --> y = 1 x = 0,2 --> y = 1,01 x = 0,3 --> y = 1,05 x = 0,4 --> y = 1,1 x = 0,5 --> y = 1,2
I need to have a fixed number of points for X, (50 points for example) and have the Y values associated to be able to compare the 3 different cases.
I think it can be done with interp1 function but i'm not really sure how to do that, i hope someone can help me, thank you in advance.
Regards, Vlad.

Answers (1)

Martin Schätz
Martin Schätz on 16 Oct 2015
Hi, as you said you can use interp1 function. You will have the raw mesh like this:
x = 0:1:10; %step by 1
v = sin(x);
with smaller step.
figure
plot(x,v,'o');
title('Original Data');
To interpolate data, you have to create new variable with smaller steps (now is the step 0.1 as u want for your medium mesh).
xq = 0:0.1:10; % new step by 0.1
vq1 = interp1(x,v,xq,'spline');
Then after interpolation, you will get data with smaller step.
figure
plot(xq,vq1,'o');
title('(Default) Linear Interpolation');
You can easily use this code, but look at the help for interp1 and choose right interpolation method for your data.

Community Treasure Hunt

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

Start Hunting!