Using fminsearch with a function containing summation (via for loop)
Mostrar comentarios más antiguos
Dear MATLAB community,
I would like to obtain the values of
, γ, δ, and L in the following equations:

To obtain these values, I am optimizing the error function
:

where
is the experimental result.
The strategy that I would like to implement is:
(1) Generate a function that calculates both the
and 
(2) Use that function to optimize the values of
, γ, δ, and L using fminsearch (since I want to use Nelder-Mead optimization).
The script that I have written for the function is:
function [f] = ErrorFunction(x)
% n_ave = x(1)
% gamma = x(2)
% delta = x(3)
% length = x(4)
c = 299792458; % Speed of light in m/s
n_air = 1.000293; % Index of refraction of air
k = 1e-12; % ps to s coversion
cor_fac = 0.04;
M = 4;
fp_signal = 0.0; %fp_signal is E_FP(t)
for k=1:M
fp_signal = fp_signal +...
((x(1)-1)/(x(1)+1))^(2*k).*...
x(2)^(2*k).*...
raw_signal_ref.*k... % raw_signal_ref is E_reference(t)
(raw_time_ref.*(1e-12)-(x(1)*2*x(4)*M/c)-((x(1)-n_air)*x(4)/c))/...
x(3)^(2*M+1);
end
signal_simulated = cor_factor*(4*x(1))/(x(1)+1)^2*x(2)*...
((raw_signal_ref.*k.*((raw_time_ref*(1e-12)-(x(1)-1)*(x(4)*(1e-3)/c))/x(3))) + fp_signal); % raw_time_ref = t
f = sum(sim_signal_sam - raw_signal_sam); %raw_signal_sam is E_sample_(t)
To find
, γ, δ, and L, I use fminsearch using the following separate script:
%% Optimization of paramters: n_ave , gamma, delta, length
x0 = [n_ave_in;gamma_in;delta_in;thickness_in];
x_optimized = fminsearch('ErrorFunction',x0);
The initial values for these parameters are
,
,
, and
.
When I run both scripts, however, I am getting this result:

Questions now are:
- Should I use a different approach on implementing the summation (via for loop) for the FP effect, i.e. using symsum?
- Can optimization using fminsearch be even done if a summation is inside the equation?
- What should be changed in the function script for fminsearch to work?
Thanks in advanced for your help.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!