How can I fit curve quadratically such that fit goes like in the picture?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2022-11-5
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 个评论
更多回答(1 个)
John D'Errico
2022-11-5
编辑:John D'Errico
2022-11-5
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!