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!