Using lsqcurvefit with a function that contains a for loop

4 次查看(过去 30 天)
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

回答(1 个)

Matt J
Matt J 2013-11-27
编辑:Matt J 2013-11-27
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));

标签

Community Treasure Hunt

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

Start Hunting!

Translated by