# I need to create a 3D surface plot for a multiple linear regression

23 views (last 30 days)
Anna on 24 Feb 2023
Answered: William Rose on 24 Feb 2023
I have a data set that I've created, I have to understand how the volume works, and it depends on temperatures and pressures. The temperatures range is [-59; 260] °C; the pressures range is [17; 36] atm, I calculated the volume based on PV= nRT (the ideal gas law). So, I created the data set (I don't know if it is good) but to predict the model, I used the linear regression and it seems working. After this, I need to create the 3D surface plot, but I don't have any clue in this moment, also because I'm not sure if the prediction is really good.
I attach all the data.
Thank you in advance for the support.
sill =
25×3 table
temp pres vol
____ ____ ____
-59 17 1034
-57 20 887
-55 23 778
-47 27 687
-30 30 665
-20 31 670
-1 40 558
11 51 457
14 53 445
21 60 402
25 61 401
32 70 358
45 80 326
50 83 319
53 90 297
67 92 303
76 97 295
81 100 291
88 102 291
92 104 288
120 107 301
135 110 304
200 127 306
215 129 311
260 136 322
x1 = temp;
x2 = pres;
Y= vol;
X = [ones(size(x1)) x1 x2 x1.*x2];
b = regress(Y, X);
%plot
scatter3(x1,x2,Y,'filled')
hold on
x1fit = min(x1):100:max(x1);
x2fit = min(x2):10:max(x2);
[X1FIT,X2FIT] = meshgrid(x1fit,x2fit);
YFIT = b(1) + b(2)*X1FIT + b(3)*X2FIT + b(4)*X1FIT.*X2FIT;
mesh(X1FIT,X2FIT,YFIT)
xlabel('temp')
ylabel('pres')
zlabel('vol')
view(50,10)
hold off
%p value
X_ = [temp, pres];
lm = fitlm(X_,vol);

William Rose on 24 Feb 2023
Please attach sill as a text file containing 3 columns of data and no headers.
Please format your code as code (by highlighting it, then clicking the "code" button at the top of the message composition window), and run it in the window (by clicking the green arraow), so others can see what the output looks like. Is it doing something you don't like? Is it giving an error? Your answers will help you get useful help.
You say you fitted the data with a linear regression. That is interesting. Is the ideal gas law, with volume on the left hand side, a linear equation in P and T? Is n, the number of moles of gas, constant, as you change P and T?
What are the temperature units in your data? I notice negative temperatures values. What are the temperature units you must use for the ideal gas law?

### Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by