How to use exponential function to fit my data?

5 ビュー (過去 30 日間)
Taoooooooooooo
Taoooooooooooo 2021 年 11 月 3 日
コメント済み: Mathieu NOE 2021 年 11 月 19 日
Hi,
I tried to use lsqcurvefit function to fit my data and the results did not look right at all. The x and y are attached above where y is the center_voxel (80-by-1Matrix). Please help and here is my code:
x = linspace(0,128,80);
y = center_voxel';
xdata=x;
ydata=y;
lb = [-100, -100, -100];
ub = [100, 100, 100];
fun = @(xx,xdata)xx(1).*exp(xx(2).*xdata)+xx(3);
x0 = [0.5, 0.5, 0.5];
xx = lsqcurvefit(fun,x0,xdata,ydata,ub,lb)
yy = linspace(xdata(1),xdata(end));
figure
plot(xdata, ydata, 'pg')
hold on
plot(yy, fun(xx,yy),'r-')

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 11 月 5 日
hello
try this
clc
clearvars
load('x axis.mat')
load('y axis.mat')
x = linspace(0,128,80);
y = center_voxel';
f = @(a,b,c,x) a.*exp(x.*b)+c;
obj_fun = @(params) norm(f(params(1), params(2), params(3),x)-y);
sol = fminsearch(obj_fun, [-y(end),-1e-1,y(end)]);
a = sol(1)
b = sol(2)
c = sol(3)
figure;
plot(x, y, '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
plot(x, f(a, b,c, x), '-');grid on
xlabel('x');
ylabel('y');
a = -3.5863e+03
b = -0.0143
c = 3.4995e+03
  1 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 11 月 19 日
hello
problem solved ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by