fit a 3d curve

256 views (last 30 days)
Elza
Elza on 14 Apr 2011
Answered: Sonali on 27 Aug 2023
Dear all,
I am a beginner in Matlab and I need your help. Here is my problem: I have a cloud of data obtained by measurement. Thanks to those datas I have made a matrix(49x49) which allowed me to plot a paraboloid. I would like to fit this 3d curve based on data, but I don't know how to start. Could you please help me to find a way to solve this problem?
Sincerely,
Elza

Accepted Answer

Andrew Newell
Andrew Newell on 14 Apr 2011
Edited: John Kelly on 12 Jun 2014
If you have the Curve Fitting Toolbox, you could try interactive surface fitting.
EDIT: If you don't have it, you could try polyfitn, which you can download from the File Exchange.

More Answers (4)

Elza
Elza on 14 Apr 2011
Many thanks for your answer. Actually I don't have this tool. Do you know an other way to do it?
Thanks a million.
Elza

Jarrod Rivituso
Jarrod Rivituso on 14 Apr 2011
Could you cast it as a linear regression problem and then solve the equations using backslash? Some details:
Say we are trying to fit to an equation of the form
z = c1*f1(x,y) + c2*f2(x,y) + ...
where f1 and f2 are the basis functions of the linear equation, and c1,c2,etc. are the coefficients. You could write this as a matrix equation...
z = [f1(x,y) , f2(x,y) , ...] * [c1 ; c2 ; ...]
Here's an example in MATLAB with some data I made up...
%Define grid of x,y values
x = -1:0.01:1;
y = -1:0.01:1;
[X,Y] = meshgrid(x,y);
%Make up some data
data = X.^2 + 3*Y.^2 + 0.01*rand(size(X));
%Set the basis functions
f1 = ones(size(X));
f2 = Y.^2;
f3 = X.^2;
%Write as matrix equation
A = [f1(:),f2(:),f3(:)];
y = data(:);
%Solve for coefficients
coeffs = A\y

Elza
Elza on 20 Apr 2011
Thanks for your help Jarrod, I'll try that and let you know if it works for me.
Many thanks

Sonali
Sonali on 27 Aug 2023
Rt = 30.5;
area_ratio = 31.4754;
theta = 50;
theta_exit = 16.5;
theta_n = theta*pi/180;
k = 0.8;
Ln = k*(sqrt(area_ratio)-1)*Rt/tand(theta_exit);
% FIRST CURVE (FC)
% Angles for First Curve
Angle_FC = -(pi+(45*pi/180));
FC_step = (-pi/2-Angle_FC)/100;
theta_FC = (-3*pi/4):FC_step:(-pi/2);
% Coordinates for First Curve
x_FC = cos(theta_FC)*1.5*Rt;
y_FC = sin(theta_FC)*1.5*Rt+(1.5*Rt+Rt);
x_FC1 = x_FC';
y_FC1 = y_FC';
% SECOND CURVE (SC)
% Angle for Second Curve
Angle_SC = -pi/2;
SC_step = ((theta_n-pi/2)-Angle_SC)/100;
theta_SC = -pi/2:SC_step:(theta_n-pi/2);
% Coordinates for Second Curve
x_SC = cos(theta_SC)*0.382*Rt;
y_SC = sin(theta_SC)*0.382*Rt+(0.382*Rt+Rt);
x_SC1 = x_SC';
y_SC1 = y_SC';
% THIRD CURVE (TC)
% Coordinates for Third Curve
x_TC = cos(theta_n-pi/2)*0.382*Rt;
y_TC = sin(theta_n-pi/2)*0.382*Rt+(0.382*Rt+Rt);
% Exit Coordinates
y_exit = sqrt(area_ratio)*Rt;
matrix_y = [y_TC^2 y_TC 1; y_exit^2 y_exit 1; 2*y_TC 1 0];
matrix_x = [x_TC; Ln ;1/tan(theta_n)];
x_exit = matrix_y^-1*matrix_x;
a = x_exit(1,1);
b = x_exit(2,1);
c = x_exit(3,1);
y = y_TC:0.8:y_exit;
x = a*y.^2+b*y+c;
% Complete Coordinate
Rao_x = [x_FC x_SC x];
Rao_y = [y_FC y_SC y];
% Lower Geometry
Rao_y1 = -1*Rao_y;
%Coordinates
R_X = Rao_x';
R_Y = Rao_y';
Rao = [R_X R_Y];
% Figures
figure(1)
plot (Rao_x,Rao_y,'r','LineWidth',3)
hold on
plot (Rao_x,Rao_y1,'r','LineWidth',3)
hold of
I need this code To be generate in 3D model
can you please provide

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!