フィルターのクリア

What is the most efficient way to "reverse" interpolate a 3D array?

13 ビュー (過去 30 日間)
deathtime
deathtime 2023 年 2 月 10 日
回答済み: Jan 2023 年 2 月 10 日
I have a 3-D array of data: it contains Fz values for different values of alpha angle, beta angle and Mach number.
I would like to know the best way to "reverse interpolate" the value of alpha for given/target values of beta, Mach and Fz.
The best method I can think of is a 2-step interpolation process:
1) For each value of alpha, and the given target values of beta and Mach, interpolate the "beta-Mach space" to extract Fz.
2) For the extracted Fz values from step 1, interpolate this space for the target Fz to find alpha.
Here is how it is implemented (data.mat is attached):
% load interpolation data
load data
% Set up interpolation target values
Fz_target = 19.4801;
beta_target = 0;
Mach_target = 0.1;
% Step 1: interpolate "beta-Mach space" for each alpha in alpha_array
[beta_points, Mach_points] = ndgrid(beta_array, Mach_array);
Fz_space = zeros(1,alphan);
for i = 1:alphan
Fz_space(i) = interpn(beta_points, Mach_points, reshape(Fz_basic(i,:,:), [betan, Machn]), beta_target, Mach_target);
end
% Step 2: interpolate Fz_space from step 1 for Fz_target to get alpha
alpha_extract = interpn(Fz_space, alpha_array, Fz_target);
Is there a more efficient, faster, less verbose way to do this?
If I pursue the above method, is there a way to vectorize the for loop?

採用された回答

Jan
Jan 2023 年 2 月 10 日
Creating the grid matrices is not useful. The interpolation is about 10 times faster using the original vectors.
% Omit:
% [beta_points, Mach_points] = ndgrid(beta_array, Mach_array);
% Use the vectors instead:
% Fz_space(i) = interpn(beta_points, Mach_points, reshape(Fz_basic(i,:,:), [betan, Machn]), beta_target, Mach_target);
Fz_space(i) = interpn(beta_array, Mach_array, reshape(Fz_basic(i,:,:), [betan, Machn]), beta_target, Mach_target);

その他の回答 (1 件)

Star Strider
Star Strider 2023 年 2 月 10 日
The loop would likely not be necessary interpolationg with the scatteredInterpolant function. Pass all the ‘_target’ values as column vectors (with the rows matching the desired matching values) for any of the three values to get the fourth. The code is a bit more involved initially, however after that, the interpolations are straightforward.
This defines scatteredInterpolant functions for all the values as functions of one of the other values —
LD = load(websave('data','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1291810/data.mat'))
LD = struct with fields:
Fz_basic: [9×3×2 double] Mach_array: [0.1000 0.8000] Machn: 2 alpha_array: [-5 -2.5000 0 2.5000 5 7.5000 10 12.5000 15] alphan: 9 beta_array: [-5 0 5] betan: 3
alpha = LD.alpha_array;
beta = LD.beta_array;
Mach = LD.Mach_array;
Fz = LD.Fz_basic;
CheckSame = Fz(:,:,2)-Fz(:,:,1);
alphav = reshape(alpha(:)*ones(1,numel(beta)*numel(Mach)), [],1);
betav = reshape(beta(:)*ones(1,numel(alpha)*numel(Mach)),[],1);
Machv = reshape(Mach(:)*ones(1,numel(alpha)*numel(beta)),[],1);
Fzv = reshape(Fz, [], 1);
alphafcn = scatteredInterpolant(betav,Machv,Fzv,alphav);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
betafcn = scatteredInterpolant(alphav,Machv,Fzv,betav);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Machfcn = scatteredInterpolant(alphav,betav,Fzv,Machv);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Fzfcn = scatteredInterpolant(alphav,betav,Machv,Fzv);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Fz_target = 19.4801;
beta_target = 0;
Mach_target = 0.1;
alpha_interp = alphafcn(beta_target, Mach_target, Fz_target)
alpha_interp = 11.9095
figure
surfc(beta, alpha, Fz(:,:,1))
hold on
surfc(beta, alpha, Fz(:,:,2))
scatter3(beta_target, alpha_interp, Fz_target, 250, 'c', 'p', 'filled')
hold off
colormap(turbo)
xlabel('\beta')
ylabel('\alpha')
zlabel('F_z')
.

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by