Regression plot help for a range of data

Hello, I am currently tasked with creating a regression plot in matlab using for loops, but I have never done it before and don't know how. I have tried looking it up a number of different ways, but none of these ways seem to be similar to what I have to do.
The equation that I have is k = ((L*u*Q)/(dp*A)), where k is permeability, Q is flux, and dp is the change in pressure. All of the other variables are constant.
How would I go about making a regression plot for k, or permeability, for a range of different flux values and/or pressure values. If I can do them both at the same time that is cool, but if it needs to be done one at a time that would work too. Currently I am trying to do 0.0001-0.001 for flux in steps of 0.0001, and pressure 1 to 1000 newtons in steps of 15 or so. The steps are not that important, but getting started is the most important part. If anyone has any advice/links that they think would help it would be greatly appreciated.

1 Comment

Another use for meshgrid and surf() it would seem. IA just answered one a little while ago while I just pointed the OP to the documentation :) ...
Just substitute your function and range of independent variables, any away you go...

Sign in to comment.

 Accepted Answer

No need to employ meshgrid() for calculations instead, use color ":" operator that performs vectorized calcs.
L=...;
u=...;
A=...;
Q=0:.0001:.001; % Flux
dp=1:15:1000; % Change in pressure
k = ((L*u*Q)./(dp(:)*A));
surf(k)

5 Comments

Yeah, I'm too old. So I forget about the recent introduction of the automagic vector expansion -- 30 year ago when I began w/ Matlab, meshgrid was the only way outside explcit loops... :)
Thank you both for this, is there any way that I could make this into a regression plot like the pictures shown?
Well, that's linear regression diagnostics with a one-variable correlation, not nonlinear and more than one...
So, what toolboxes do you have; Curve Fitting and/or Statistics, maybe? They have some higher-level tools for nonlinear regresssion; it can be done in/with the base MATLAB, but have to do it all as those don't include much in the way of the output statistics automagically.
But, if you're just making data to plot and don't have experimental data slimilar to the above, it doesn't make any real sense to fit exact values if all the parameters are known -- the fit will be perfect and the errors identically zero.
The above is only valid in the case of estimating the coefficients of the presumed linear regression; your problem as posed is one where you have a specific correlation already and are just evaluating it over a range of variables.
If you want those to be "one-at-a-time" plots of each independent variable, then that's certainly possible; just set one to a fixed value and evaluate over a range of the other; then step the first and repeat. You'll get a family of curves parameterized over the other variable for two plots. This, of course, explodes exponentially as the number of independent variables goes up.
Okay, thank you, and that would be done the same way? using the surf function? the only tool box I have installed currently is the image processing one, but I am able to install any that I need through my school
All you need/want for a linear plot like the above is plot()
Just set hold on after the first line is drawn to add to it.
Or, create an array of the YData as columns for each of the second variable and pass it; plot treats each column of a 2D array as a separate line automagically.
See the documentation for plot for example usage.

Sign in to comment.

More Answers (0)

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!