Fit quality parameter in a double loop
Mostrar comentarios más antiguos
I have a physical process (amplification in gain medium) described by the equation for the parameter "amp_I0" in the code below. The free parameters in the process are the variables g0 and alpha, and the goal is to calculate the residual sum of squares (fitquality parameter in the code) between the reference and amplified profiles. Everything is working fine when I manually change g0 and alpha (the commented section in the code), but when I want to change the free parameters in loops and get the fitquality parameter for each g0 and alpha, I get an array mostly populated with zeros (which does not make sense in terms of the physcis). Can someone please fix my mistake in the double for loop? The strange thing is the plot looks correct.
clear
close all
t = [-100:0.1:100];
I = exp(-(t/10).^2) + 0.5*exp(-((t-20)/10).^2);
I = I/max(I);
I = I';
ref_I = exp(-(t/4.5).^2) + 0.06*exp(-((t-20)/6).^2);
ref_I = ref_I/max(ref_I);
ref_I = ref_I';
lambda = [190:0.01:197];
S = exp(-((lambda-193.5)/0.25).^2);
S = S/max(S);
S = S';
L = 54;
g0 = 1*0.16;
alpha = 10*0.008;
prod = S*I';
% amp_I0 = g0*prod.*(exp((g0*prod-alpha)*L)-1)./(g0*prod-alpha);
% amp_I = sum(amp_I0,1)/max(sum(amp_I0,1));
% amp_I = amp_I';
% amp_I = amp_I/max(amp_I);
% fitquality = trapz((amp_I - ref_I).^2)
for k = 1:11
alpha(k) = 0.008 + 0.008*(k-1);
for j = 1:21
g0(j) = 0.15 + 0.001*(j-1);
amp_I0 = g0(j)*prod.*(exp((g0(j)*prod-alpha(k))*L)-1)./(g0(j)*prod-alpha(k));
amp_I(:,j*k) = sum(amp_I0,1)/max(sum(amp_I0,1));
amp_I(:,j*k) = amp_I(:,j*k)';
amp_I(:,j*k) = amp_I(:,j*k)/max(amp_I(:,j*k));
fitquality(k,j*k) = trapz((amp_I(:,j*k) - ref_I).^2);
% plot(t,amp_I,'r');
% drawnow()
end
end
figure(1)
plot(t,I,'b')
hold on
plot(t,ref_I,'r')
plot(t,amp_I,'g')
figure(2)
plot(lambda,S,'b')
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming 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!

