Borrar filtros
Borrar filtros

genetic algorithm for curve fitting

20 visualizaciones (últimos 30 días)
Emran Alotaibi
Emran Alotaibi el 8 de Nov. de 2020
Comentada: Divya Thokala el 10 de Mayo de 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!

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 8 de Nov. de 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 comentarios
Ameer Hamza
Ameer Hamza el 8 de Nov. de 2020
I am glad to be of help! :)
Divya Thokala
Divya Thokala el 10 de Mayo de 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'})

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by