Trying to fit surface into plot that is 3D
Afficher commentaires plus anciens
clear
close all
clc
data = load('survey.dat');
rho = data(1:9665, 1);
T = data(1:9665, 2);
p = data(1:9665, 6);
figure(1)
plot3(rho,T,p, '.', 'MarkerSize', 1, 'Color', 'r'), box 'on';
xlabel('\rho', 'FontSize', 10, 'fontweight', 'bold');
ylabel('T', 'FontSize', 10, 'fontweight', 'bold');
zlabel('p', 'FontSize', 10, 'fontweight', 'bold');
title('Equation', 'FontSize', 12);
axis([0 1.5 1 10 -1 250])
ft = fittype(strcat('rho*T + rho^2*(a01*T+a02*T^(1/2)+a03+a04/T+a05/T^2) + rho^3*(x06*T+x07+x08/T+x09/T^2)+ rho^4*(x10*T+x11+x12/T) + rho^5*(x13) + rho^6*(x14/T+x15/T^2) + rho^7*(x16/T)+ rho^8*(x17/T+x18/T^2) + rho^9*(x19/T^2)+(rho^3*(x20/T^2+x21/T^3)+rho^5*(x22/T^2+x23/T^4)+rho^7*(x24/T^2+x25/T^3)+rho^9*(x26/T^2+x27/T^4)+rho^11*(x28/T^2+x29/T^3)+rho^13*(x30/T^2+x31/T^3+x32/T^4))*exp(-3*rho^2)'),'independent',{'rho','T'},'dependent','z');
f = fit(X, Y, ft);
I am trying to understand how to fit the surface to the 3D plot i already have. I want to create a surface plot by using the custom equation from variable ft and create surface from it that will fit to the data. I can't find any help anywhere, I know I was close at some point because the surface was being drawn (which is weird because i was using only plot function and it still created 3d surface) and now I'm completely lost like a child in a fog. Any help will be greatly appreciated.
Réponses (1)
Tro JOP
le 7 Juil 2020
4 commentaires
John D'Errico
le 7 Juil 2020
We don't have your data, so there is no way to help you, or to offer advice as to if this a reasonable model.
Plot3 does not work as a call to surf, nor does plot. But plot does work using a surface fit with the curve fitting toolbox, because that toolbox overloads plot. When you plot the model created using fit, it is smart enough to know that you wanted a surface plot.
Tro JOP
le 7 Juil 2020
John D'Errico
le 7 Juil 2020
As long as it works. Some of the tools I've written overload plot. This can be useful when working with objects in MATLAB. For example,
px = [0 1 1 0 0];py = [0 0 2 1 0];
ps = polyshape(px,py);
plot(ps)

So perhaps surpringly, plot works when applied to a polyshape object in MATLAB. We could have predicted that, by taking a glance at the methods defined for a polyshape.
>> methods(ps)
Methods for class polyshape:
addboundary holes nearestvertex polybuffer rotate translate
area intersect numboundaries polyshape scale triangulation
boundary isequal numsides regions simplify turningdist
boundingbox ishole overlaps rmboundary sortboundaries union
centroid isinterior perimeter rmholes sortregions xor
convhull issimplified plot rmslivers subtract
As you can see, plot is one of them.
Just for kicks, try the same thing on a fit object, as produced by the curve fitting toolbox. You may be surprised at some of the functions that can be used.
mdl = fit(rand(10,1),rand(10,1),'poly2')
mdl =
Linear model Poly2:
mdl(x) = p1*x^2 + p2*x + p3
Coefficients (with 95% confidence bounds):
p1 = 1.213 (-3.747, 6.173)
p2 = -0.5017 (-4.58, 3.577)
p3 = 0.4511 (-0.09849, 1.001)
So some randomly garbage polynomial model now exists. What does methods tell me?
methods(mdl)
Methods for class cfit:
argnames coeffnames dependnames fitoptions integrate numcoeffs probnames type
category coeffvalues differentiate formula islinear plot probvalues
cfit confint feval indepnames numargs predint setoptions
For example:
>> differentiate(mdl,3)
ans =
6.7762
Tro JOP
le 7 Juil 2020
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!