Clear Filters
Clear Filters

Normalization of poly22 fitsurface

33 views (last 30 days)
laura bagnale
laura bagnale on 23 Jun 2021
Answered: Nipun on 17 May 2024
Hello everyone,
I hope someone could help me. I would like to find a way to normalize poly22.
I have a set of X,Y,Z points in space, and I used fs poly22 to fit them with a surface.
This is my code:
X = [0.1; 0.05; 0.5; 0.5; 0.05; 0.4];
Y = [2.8; 5.5; 5.5; 1.4; 1.4; 2];
Z = [0.9; 0.3; 0; 0.2; 0.6; 1];
%plotting data and fitsurface
plot3(X,Y,Z,'or');
fs=fit([X,Y],Z, 'poly22','Normalize','on');
plot(fs, [X,Y],Z)
Linear model Poly22:
fs1(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2
where x is normalized by mean 0.2933 and std 0.2741
and where y is normalized by mean 2.683 and std 1.946
Coefficients:
p00 = 1.076
p10 = -0.01815
p01 = 0.08533
p20 = -0.5503
p11 = -0.07016
p02 = -0.2431
I would like my surface to be contained in a cube of edges 0-1 in the three directions, is there a way to do it?
Thank you very much for your help!
Kind Regards,
Laura

Answers (1)

Nipun
Nipun on 17 May 2024
Hi Laura,
I understand that you are trying to fit a surface to your X, Y, Z data points using a polynomial of degree 2 in both X and Y, and you want to ensure that this fitted surface is contained within a cube with edges ranging from 0 to 1 in all three directions. To achieve this, you should normalize your data points so that they fit within this cube before applying the fitting process. Here is how you can do it in MATLAB:
% Your original data
X = [0.1; 0.05; 0.5; 0.5; 0.05; 0.4];
Y = [2.8; 5.5; 5.5; 1.4; 1.4; 2];
Z = [0.9; 0.3; 0; 0.2; 0.6; 1];
% Normalize the X, Y, and Z data to the range [0, 1]
X_norm = (X - min(X)) / (max(X) - min(X));
Y_norm = (Y - min(Y)) / (max(Y) - min(Y));
Z_norm = (Z - min(Z)) / (max(Z) - min(Z));
% Fit the surface to the normalized data
fs_norm = fit([X_norm, Y_norm], Z_norm, 'poly22');
% Plotting the normalized data and the fitted surface
figure;
plot3(X_norm, Y_norm, Z_norm, 'or'); % Plot the normalized data points
hold on;
% Plot the fitted surface
fs_plot = plot(fs_norm, [X_norm, Y_norm], Z_norm);
zlim([0 1]); % Ensure the Z-axis is limited to [0, 1]
xlabel('Normalized X');
ylabel('Normalized Y');
zlabel('Normalized Z');
title('Normalized Fitted Surface');
This code normalizes your X, Y, and Z data to be within the range of 0 to 1, fits a polynomial surface to the normalized data, and then plots both the normalized data points and the fitted surface. The normalization ensures that your fitted surface will be contained within a cube with edges from 0 to 1 in the X, Y, and Z directions as desired.
Hope this helps.
Regards,
Nipun

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!