genetic algorithm for curve fitting

20 次查看(过去 30 天)
I know this question have been extensively asked previously,
However, I want to fit an exponontial equation y = a*(1-b*exp(-c*x)) where a,b and c are constants to be optimized, y and x are experimental data obtained as follows
xx=[0.001,5,10,20,40,80];
yy=[0,5,8,11.2,18.3,25.3];
From previous threads I read in the fourm, I ended up forming the below function:
function x = material(y)
xx=[0.001,5,10,20,40,80];
yy=[0,5,8,11.2,18.3,25.3];
a=y(1); b=y(2); c=y(3);
for j=1:6
x=(a)*(1-b*exp(-c*xx(j)))-yy(j);
end
end
I used the function above with GA toolbox in MATLAB 2017b, the results are way wrong
49.98723904071618 49.939937193013776 0.011881054853272788 for a,b and c respictevely
what i have missed?
Thanks for your help!

采纳的回答

Ameer Hamza
Ameer Hamza 2020-11-8
Try this
xx=[0.001,5,10,20,40,80];
yy=[0,5,8,11.2,18.3,25.3];
fun = @(p) p(1)*(1-p(2)*exp(-p(3)*xx));
objFun = @(p) norm(fun(p)-yy);
sol = ga(objFun, 3);
figure()
axes();
plot(xx, yy, 'b+');
hold on
plot(xx, fun(sol), 'r-');
legend({'Data points', 'Fitted Curve'})
  3 个评论
Divya Thokala
Divya Thokala 2021-5-10
I have ran a code similar to this. Actually I am not aware of how to optimize it. My graph is coming like slopy as in the figure shown. please help me
xx=xlsread('wave.xlsx','A:A');
yy=xlsread('wave.xlsx','B:B');
fun = @(p) p(1)+p(2)*cos(2*3.14*xx/12)+p(3)*sin(2*3.14*xx/12)+p(4)*xx;
objFun = @(p) norm(fun(p)-yy);
sol = ga(objFun, 4);
figure()
axes();
plot(xx, yy, 'b+');
hold on
plot(xx, fun(sol), 'r-');
legend({'Data points', 'Fitted Curve'})

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by