Using lsqcurvefit with a function that contains a for loop

2 views (last 30 days)
I want to fit Fick's Law for diffusion in a sphere using lsqcurvefit to experimental data.
The equation is an infinite series of the form
y = 1- sum((A/n^2 * exp(-B*n^2*t - t0))
I would like to create a function which sums the first 100 n terms using a for loop and then use lsqcurvefit to adjust parameter B to fit the experimental mass versus time data.
I know how to use lsqcurvefit, I just want to know how to fit this equation without adding the first 100 etc terms manually in the function file.
Thanks for your help,
Jon

Answers (1)

Matt J
Matt J on 27 Nov 2013
Edited: Matt J on 27 Nov 2013
No idea why you think you need a for loop. The SUM command will work just fine,
n=1:100;
y = 1- sum((A./n.^2 .* exp(-B*n.^2*t - t0));

Tags

Community Treasure Hunt

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

Start Hunting!