How can I fit curve quadratically such that fit goes like in the picture?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anup
le 5 Nov 2022
Réponse apportée : Image Analyst
le 5 Nov 2022
I want to fit the curve based on equation
f(x) = b1+b2*x+b3*(x^2)
I got the curve as shown in the fiqure below:
I mean, this is the perfect fit, but I want fit that goes like following figure:
I got this from eqn f(x) = 20+0.1*x+b3*(x^2), by pre-defining b1 and b2 parameters.
Is there a way of curve plotting so that I can get all b1,b2,b3 automatically, such that curve goes in beween from all values?
0 commentaires
Réponse acceptée
Image Analyst
le 5 Nov 2022
Try this:
T_b = [.143, .163, .168];
P_b = [87, 107, 123];
plot(T_b, P_b, 'b.', 'MarkerSize', 25);
coefficients = polyfit(T_b, P_b, 2)
x = linspace(min(T_b), max(T_b), 1000);
yFit = polyval(coefficients, x);
hold on;
plot(x, yFit, 'r-', 'LineWidth', 2)
grid on;
xlabel('T_b', 'Interpreter', 'none');
ylabel('P_b', 'Interpreter', 'none');
0 commentaires
Plus de réponses (1)
John D'Errico
le 5 Nov 2022
Modifié(e) : John D'Errico
le 5 Nov 2022
It appears you have chosen to fit a quadratic polynomial to your data. And you say you want a quadratic polynomial, but you DREW a STRAIGHT line.
So which is it? You fit a quadratic. But then when you got a quadratic, you don't want it.
help polyfit
Given 3 general data points, there exists a unique quadratic polynomial that passes through the points. That it may not have the shape you wanted is the fault of your data. Only 3 points is not enough to define a curve terribly well. It is sufficient for a quadratic fit, but you are appranelty not happy with it. The faulty is therefore not in the fitting tool, but in your data, or in what you asked of the fitting tool.
So you could have done
p1 = polyfit(x,y,1);
Or, use the curve fitting toollbox, using the 'poly1' fitting method.
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!