Effacer les filtres
Effacer les filtres

genetic algorithm for curve fitting

20 vues (au cours des 30 derniers jours)
Emran Alotaibi
Emran Alotaibi le 8 Nov 2020
Commenté : Divya Thokala le 10 Mai 2021
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!

Réponse acceptée

Ameer Hamza
Ameer Hamza le 8 Nov 2020
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 commentaires
Ameer Hamza
Ameer Hamza le 8 Nov 2020
I am glad to be of help! :)
Divya Thokala
Divya Thokala le 10 Mai 2021
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'})

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by