Working out a summation for fitting a curve
Show older comments
Hi, I want to work out a summation that goes as.
I want to fit this to a curve plotted as I on the y axis and t on the x axis using the curve fit app. My function for that goes as:
function I = CurveFitD(t, deltaQ, d)
%CurveFitD We want to fit the I(t)=f(t) to a custom function.
% For a bounded layer we have an expression which can yield us the
% thickness of the polymer layer (in centimeters). We have to fit the transient to this
% equation to calculate the layer thickness.
D = 1e-05;
% deltaQ = 4.2e-11; % Couloumbs
I = zeros(size(t));
for i = 1:length(t)
for k = 1:5
I(i) = I(i) + (-(1)^(k)).*...
(exp((-(k^2).*(d^2))))./(D*t(i));
end
I(i) = sqrt(1./t(i)).*(1+2.*I(i));
end
I = sqrt(D/(pi))*(deltaQ/d).*I;
end
9 Comments
Torsten
on 19 Aug 2022
I guess you have measurement data for I at certain times and you want to fit D ?
D_num = sym(1e-05)
delta_q_num = sym(4.2e-11)
syms D d delta_q t
syms n integer
Pi = sym(pi);
inner = (-1).^n .* exp(-n.^2 .* d.^2 / (D .* t))
inner_sum = symsum(inner, n, 1, inf)
multiplier = sqrt(D ./ (Pi * t)) .* delta_q / d
I = multiplier * (1 + 2 * inner_sum)
Is = simplify(I)
I_num = subs(Is, {D, delta_q}, {D_num, delta_q_num} )
We would need to know the value of d, and the range of time, in order to plot it.
It is not obvious in the above display, but there is a negative sign in the
term.
Bruno Luong
on 19 Aug 2022
IMO your code is not correct
(exp((-(k^2).*(d^2))))./(D*t(i))
The denominator is outside exp argument, not as your math expression.
Yes,
I(i) = I(i) + (-1).^k.*exp(-k.^2.*d.^2./(D*t(i)))
instead of
I(i) = I(i) + (-(1)^(k)).*...
(exp((-(k^2).*(d^2))))./(D*t(i));
Bruno and I corrected your mistakes in the calculation of I(i).
Curious why you still make the same mistakes as in your first attempt to code the infinite series.
Worse:
Now you write
I(k) = I(k) + ...
instead of the correct
I(i) = I(i) + ...
Hashim
on 19 Aug 2022
Bruno Luong
on 19 Aug 2022
Edited: Bruno Luong
on 19 Aug 2022
It looks fine to me. You can also use MATLAB vectorization instead of for-loop:
D = 1e-05;
deltaQ = 4.7e-6;
nmax = 5;
n = (1:nmax)';
t = reshape(t,1,[]);
I = sqrt(D./(pi*t)).*deltaQ/d.*(1 + 2*sum((-1).^n.*exp(-(n*d).^2./(D*t)),1));
Hashim
on 20 Aug 2022
Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




