How to generate a nonlinear equation from MATLAB?

1 回表示 (過去 30 日間)
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA 2022 年 9 月 12 日
回答済み: Star Strider 2022 年 9 月 12 日
I have the data points of a nonlinear curve.
X=[0 1 1.1 1.15]
Y=[0 0.0042 0.0097 0.016]
But I don not have the curve. How can I generate the curve in MATLAB? Thank you.

採用された回答

Star Strider
Star Strider 2022 年 9 月 12 日
Try something like this —
X=[0 1 1.1 1.15];
Y=[0 0.0042 0.0097 0.016];
fcn = @(b,x) b(1) .* exp(b(2).*x);
format long
[B,fv] = fminsearch(@(b)norm(Y-fcn(b,X)), rand(2,1))
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 0.000423
B = 2×1
0.000000462018946 9.076307769820247
fv =
4.232123029691332e-04
xv = linspace(min(X), max(X));
fcnplot = fcn(B,xv);
figure
plot(X, Y, 'p', 'DisplayName','Data')
hold on
plot(xv, fcnplot, '-r', 'DisplayName','Fitted Function')
hold off
grid
xlabel('X')
ylabel('Y')
legend('Location','best')
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by