Clear Filters
Clear Filters

genetic algorithm for curve fitting

20 views (last 30 days)
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!

Accepted Answer

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

Sign in to comment.

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!