MATLAB: How to optimise this equation

dataequationoptimizationvariable

Hey,
I have the following equation and I need to optimize this to find the best value for n:
Furthermore, I have the following data:
Tau = 5.2
E(t) = [0 0.0199867 0.0999334 0.1598934 0.1998668 0.1598934 0.1199201 0.0799467 0.05996 0.0439707 0.02998 0.011992 0]';
t = [0 1 2 3 4 5 6 7 8 9 10 12 14]';
Hopefully can someone help me to find the best way for optimizing this function, I have looked for some methods but didn't really knew how to apply them.
Thanks in advance,
Kind regards,
Danny

Best Answer

Sinc you are using the factorial function, you are limited to integer values for ā€˜nā€™.
Try this:
objfcn = @(n,t,tau) (n.^n .* t.^(n-1)) ./ (factorial(n-1) .* tau.^n) .* exp(-n.*t/tau);
for k = 1:20
fcn(k) = norm(E - objfcn(k,t,Tau));
end
[Out,n] = min(fcn)
and the value of ā€˜nā€™ that produces the lowest residual norm ia 4.
If you want to use the gamma function instead:
objfcn = @(n,t) (n.^n .* t.^(n-1)) ./ (gamma(n) .* Tau.^n) .* exp(-n.*t/Tau);
[B,rsdnrm] = fminsearch(@(b) norm(E - objfcn(b,t)), 10)
evaluating to:
B =
4.2811
Related Question