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!