I have this code (below at the end of the question) which visualizes the flowrate (Results.Flow) as a function of the pressure difference (Results.Tryk) and I made a linear regression line on this one.
After that, I validated the models precission by calculating the coefficient of determination with equation "Rsq1", which gave me a precision of about 99 percent.
The second part makes a graph of the flowrate(Results.Flow) as a function of the pressure difference squared. Again i made i linear regression to illustrate the mean value along the way which gave me a prediction precision of 83 percent (Rsq2). But i also need a polynomial regression to see if that makes a better fit for the graph. (Because the best fitted line concludes if the flow is laminar or turbulent in my hydraulic system)
So how do make that polynomial regression, and afterwards calculate the model accuracy like I did for the other two lines?
I've already tried some things with polyfit command, but sadly I couldn't make it work.
(I have included my workspace as an attachment.)
THE LINE MUST TO GO THROUGH ORIGIN (0,0)
I also attached some pictures of the desired result i seek.
Picture 1: Is the first plot, which is perfectly as i want it
Picture 2: Is the linear regression i made on the second plot, which is also as i desire.
Picture 3: Illustrates the desired plot i need for my project
(Of course with my own values from the expiriments)
format long
ResDivFlow = Results.Tryk\Results.Flow
yCalc1 = ResDivFlow*Results.Tryk;
scatter(Results.Tryk,Results.Flow,'.')
hold on
grid on
plot(Results.Tryk,yCalc1)
xlabel('\DeltaP [Pa]')
ylabel('Q [m^3/s]')
title('Flowrate som funktion af trykforskellen')
legend('Datapunkter','Tendenslinje for gennemsnitligt flow','Location','northwest')
Rsq1 = 1 - sum((Results.Flow - yCalc1).^2)/sum((Results.Flow- mean(Results.Flow)).^2)
hold off
PressureDiffTurb = sqrt(Results.Tryk)
ResDivFlow = PressureDiffSquared\Results.Flow
yCalc2 = ResDivFlow*PressureDiffSquared;
scatter(PressureDiffTurb,Results.Flow,'.')
hold on
grid on
plot(PressureDiffTurb,yCalc2)
xlabel('sqrt(\DeltaP) [sqrt(Pa)]')
ylabel('Q [m^3/s]')
title('Flowrate som funktion af kvadraten af trykforskellen')
legend('Datapunkter','Lineær tendenslinje for gennemsnitligt flow','Location','northwest')
Rsq2 = 1 - sum((Results.Flow - yCalc2).^2)/sum((Results.Flow- mean(Results.Flow)).^2)
hold off