It is necessary to sum the functional sequence F(t) by 'n', while at each step of summation it is necessary to take 'n' from another array n(t).
    2 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
It is necessary to sum the functional sequence F(t) by 'n', while at each step of summation it is necessary to take 'n' from another array n(t) I mean nD(t). 
%% initial conditions
global d k0 h_bar ksi m E;
Ef = 2.77*10^3; 
Kb = physconst('boltzmann'); % 1.38*10^(-23)
T = 0.12:0.24:6.4;
m = 9.1093837*10^(-31);
Tc = 1.2;
%t = T./Tc;
t = 0.1:0.1:2;
nD = floor(375./(2.*pi.*t.*1.2) - 0.5);
D = 10^(-8); % толщина пленки
ksi = 10^(-9);
%d = D/ksi;
d = 1000;
E = Ef/(pi*Kb*Tc);
h_bar = (1.0545726*10^(-34));
k0 = (ksi/h_bar)*sqrt(2.*m.*pi.*Kb.*Tc);
C_2 = 0;
for n = 0:49
    C_2 = C_2 + (1/(2.*n+1)).*k0.*real(sqrt(3601+1i.*(2.*n+1))-((1+1i)./sqrt(2)).*sqrt(2.*n+1)); % константа
end
%% calculation
F = f_calc(t);
plot(t,F, '-r');
%% F(t)
function F = f_calc(t) 
    global d k0 h_bar ksi m;
    F = 0;
    for i = 1:20
        n = nD(1,i);
        F  = F + 1/(2*n+1).*(k0.*real(((f_p1(n,t)-f_p2(n,t))./2))+(f_arg_2(n,t)-f_arg_1(n,t))./d); 
    end
    F = -F;
    %F = -(1/d).*F;
    %F = F - C_2;
end
function p1 = f_p1(n,t)
    p1 = ((1+1i)./sqrt(2)).*sqrt(t.*(2.*n+1));
end
function p2 = f_p2(n,t)
    global E;
    p2 = sqrt(3601+1i.*t.*(2.*n+1));
end 
function n_lg = f_lg(n,t)
    global d k0;
    arg_of_lg = (1+exp(-1i*d*k0.*f_p1(n,t)))/(1+exp(-1i*d*k0.*f_p2(n,t)));
    n_lg = log(abs(arg_of_lg));
end
function arg_1 = f_arg_1(n,t)
    global d k0;
    arg_1 = angle(1+exp(-1i*d*k0.*f_p1(n,t)));
end
function arg_2 = f_arg_2(n,t)
    global d k0;
    arg_2 = angle(1+exp(-1i*d*k0.*f_p2(n,t)));
end
0 Kommentare
Antworten (1)
  Voss
      
      
 am 8 Jan. 2023
        Redefine the function f_calc to take nD as its second argument. (You could also make nD a global variable.) See below:
%% initial conditions
global d k0 h_bar ksi m E;
Ef = 2.77*10^3; 
Kb = physconst('boltzmann'); % 1.38*10^(-23)
T = 0.12:0.24:6.4;
m = 9.1093837*10^(-31);
Tc = 1.2;
%t = T./Tc;
t = 0.1:0.1:2;
nD = floor(375./(2.*pi.*t.*1.2) - 0.5);
D = 10^(-8); % толщина пленки
ksi = 10^(-9);
%d = D/ksi;
d = 1000;
E = Ef/(pi*Kb*Tc);
h_bar = (1.0545726*10^(-34));
k0 = (ksi/h_bar)*sqrt(2.*m.*pi.*Kb.*Tc);
C_2 = 0;
for n = 0:49
    C_2 = C_2 + (1/(2.*n+1)).*k0.*real(sqrt(3601+1i.*(2.*n+1))-((1+1i)./sqrt(2)).*sqrt(2.*n+1)); % константа
end
%% calculation
F = f_calc(t,nD);
plot(t,F, '-r');
%% F(t)
function F = f_calc(t,nD) 
    global d k0 h_bar ksi m;
    F = 0;
    for i = 1:20
        n = nD(1,i);
        F  = F + 1/(2*n+1).*(k0.*real(((f_p1(n,t)-f_p2(n,t))./2))+(f_arg_2(n,t)-f_arg_1(n,t))./d); 
    end
    F = -F;
    %F = -(1/d).*F;
    %F = F - C_2;
end
function p1 = f_p1(n,t)
    p1 = ((1+1i)./sqrt(2)).*sqrt(t.*(2.*n+1));
end
function p2 = f_p2(n,t)
    global E;
    p2 = sqrt(3601+1i.*t.*(2.*n+1));
end 
function n_lg = f_lg(n,t)
    global d k0;
    arg_of_lg = (1+exp(-1i*d*k0.*f_p1(n,t)))/(1+exp(-1i*d*k0.*f_p2(n,t)));
    n_lg = log(abs(arg_of_lg));
end
function arg_1 = f_arg_1(n,t)
    global d k0;
    arg_1 = angle(1+exp(-1i*d*k0.*f_p1(n,t)));
end
function arg_2 = f_arg_2(n,t)
    global d k0;
    arg_2 = angle(1+exp(-1i*d*k0.*f_p2(n,t)));
end
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Direct Search finden Sie in Help Center und File Exchange
			
	Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
