MATLAB: Linear Regression with Y as your Dependent Variable

chemical engineeringregression

Howdy! I've had the issue where I have to calculate a non-linear line with y as the dependent variable to make a regression for later steps in a problem. I used polyfit, polyval and it worked the first time(I'm not sure how as the graph was strange but it gave the right values), but now on the more highly non-linear example it breaks. How should I go about doing this?
I thought about inputting the y value as x and visa versa but this introduces problems later on. I've attached a portion of the code that finds the regressions. Please excuse the comments, it's how I take notes as I think.
xD=0.85; xF=0.5; xB=0.03; degree=9; R=1.5; % Stripping operating line: y = a*x + b, where
a=(R/(R+1));b=xD/(R+1);
yF=a*xF+b; %This appears to be the intersection of the line with the q line
xe=[0 .02 .05 .1 .2 .3 .4 .5 .6 .7 .8 .9 .94 .96 .98 1];
ye=[0 .192 .377 .527 .656 .713 .746 .771 .794 .822 .858 .912 .942 .959 .978 1];
%Data points as described in the question
pp1=polyfit(ye,xe,degree); %This is where the problem starts
y=0:0.01:1;
pp=polyfit(xe,ye,degree);
range=0:0.01:1; %This defines the range that we want the function to go over
y=polyval(pp,range);
plot(range,y,[0 1],[0 1],[xB xF],[xB yF],[xD xF],[xD yF],[xF xF],[xF yF],'–')
pE=polyfit([xD xF],[xD yF],1);
EDIT: I found that interp1 seems to work, but I'll leave this open for a bit if anyone has a more elegant solution.

Best Answer

Do you actually need to fit a curve to your data? Consider using the interp1 (link) function if you only need to get data from it.
Related Question