fitting data into a quadratic curve

Hello,
I have some data that can be fitted into a quadratic curve of y=ax^2 + bx + c. My data passes through the origin, and has a horizontal slope near the origin too. So my question is how do i force b and c to be zero in the qudratic equation ? while doing that i want to estimate the error too, so how do i keep track of the error if i have more than one quadratic equation.
I tried using fittype and polyval, and i am familiar with them, but that doesn't do my task.
I attached my data for better understanding.
Thanks for any help.

 Risposta accettata

To force ‘b’ and ‘c’ to be zero:
B = volume_flow_rate1(:).^2 \ influence(:) % Estimate Regression Parameter
vfrv = linspace(min(volume_flow_rate1), max(volume_flow_rate1)); % Vector For Regression Evaluation
inflv = vfrv(:).^2 * B; % Evaluate Regression
figure();
plot(volume_flow_rate1,influence, '--r*' );
hold on
plot(vfrv, inflv, '-.k') % Plot Regression
hold off
xlabel ('Q (uL/s)');
ylabel ('P(Pa)');
legend ('Via');
text(25, 1200, sprintf('y = %.6f\\cdotx^2', B)) % Regression Equation
The regression parameter is:
B =
0.0266527362537937
To force only ‘c’ to be zero:
B = [volume_flow_rate1(:).^2, volume_flow_rate1(:)] \ influence(:); % Estimate Regression Parameters
vfrv = linspace(min(volume_flow_rate1), max(volume_flow_rate1)); % Vector For Regression Evaluation
inflv = [vfrv(:).^2, vfrv(:)] * B; % Evaluate Regression
figure();
plot(volume_flow_rate1,influence, '--r*' );
hold on
plot(vfrv, inflv, '-.k') % Plot Regression
hold off
xlabel ('Q (uL/s)');
ylabel ('P(Pa)');
legend ('Via');
text(25, 1200, sprintf('y = %.6f\\cdotx^2 %+.6f\\cdotx', B)) % Regression Equation
The regression parameter estimates are:
B =
0.0304986880886496
-0.722814145120915

10 Commenti

Thank you for the great answer, that does the job perfectly. After plotting the regression paramter, i want now to estimate the error, how can i do that ?
My pleasure.
It depends on what you mean by ‘error’. To calculate the residuals and their standard deviations:
rsd = influence(:) - (volume_flow_rate1(:).^2 * B); % Residuals
std_rsd = std(rsd) % Standard Deviation Of Residuals
Hello Star strider,
Thanks for the help out there. It helped a lot. I have a few more questions regarding the residuals, so if you may please.
In another plot, i fitted a quadratic curve to my data, where b and c does not equal to zero. I used fittype('poly2') for this. What i am trying to do now is to calculate the residuals of this fit. how can i do that ? what should i substract from the influence?
I can go through tools and then plot the residuals and calcualte the norm, but i decided to go with the standard deviation of the residuals as a comparison
Another small question regarding the estimation of the regression parameter. Is this a general method ? does it have a specific name? or am i asking a wrong question ?
Thanks again for the help.
As always, my pleasure!
I do not have the Curve Fitting Toolbox, so I cannot help you with any questions related directly to it.
Calculate the residuals by finding the values of the fitted curve at every value of the independent variable, then subtract that value from the data value at the same point.
The term ‘parameter estimation’ is the general term for determining the parameters of a model related to data. That is the only description I have ever encountered. There are several ways to estimate parameters, depending on the technique or algorithm used. Most of them minimise the squared distance between the data and the estimated model at each data value, although there are other methods of comparing them.
I attached the m file with this reply. i am stuck on the "%Residuals" section of the quadratic curve. The thing is i don't know how to transform a fittype into double inorder to subtract it from the original data. Any help on this part ?
For the perimeter estimation, you used the method where it minimize the squared distance between the data and the estimated model at each data value, right ?
Thank youuu.
As always, my pleasure.
I do not have the Curve Fitting Toolbox, so I cannot help you with anything regarding it.
Doing the same thing with polyfit and polyval:
B = polyfit(volume_flow_rate1(:), influence(:), 2); % Estimate PArameters
infl_fit = polyval(B, volume_flow_rate1(:)); % Evaluate At Independent Variable Values
resid = influence(:) - infl_fit(:); % Calculate Residuals
You can then do statistics on the residuals.
Hello Star strider,
As i can see you are an expert in fitting curves and codes that are related to this topic, so i thought i would ask you directlty here, and thank you inadvance.
I want to fit a power function y = a.x^b +c. Based on my data, b is always -1, but the fitting is giving values approximatly = -1. How do i force it to be -1 ?
Thank youuuu.
As always, my pleasure.
You will have problems with that, since:
volume_flow_rate1(1) = 0
However if you are using different data, I would calculate it as:
B = [1./x(:) ones(size(x(:)))] \ y(:) % Estimate Parameters
y_fit = [1./x(:) ones(size(x(:)))] * B % Fit To Data
This uses which is more efficient than .
Perfect, that worked as i wanted. And yes i am using different data.
Thank you again and again :D , I learned alot from you.
As always, my pleasure!
That is actually what Answers is for!

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by