Month: July 2024
4G / 5G not working when using Managed Home Screen
I have been using the Managed Home Screen and its been working perfectly until I’ve gone to test using mobile data (4G / 5G) and it doesn’t work when using it. This is for Android tablets.
Has anyone got around this?
I have been using the Managed Home Screen and its been working perfectly until I’ve gone to test using mobile data (4G / 5G) and it doesn’t work when using it. This is for Android tablets.Has anyone got around this? Read More
Single struct as alternative to name-value pairs in user-defined function
Hello, is it possible when defining a function with name-value argument pairs to allow a user to pass the struct(s) that define these name-value pairs directly to the function?
For example, I can define
function [s1, s2] = TestStructArgs(s1, s2)
arguments
s1 (1,1) struct
s2 (1,1) struct
end
end
then call TestStructArgs(struct(‘a’, 1, ‘b’, 2), struct(‘x’, 3, ‘y’, 4))
Or, I can define
function [s1, s2] = TestStructArgs2(s1, s2)
arguments
s1.a (1,1) double
s1.b (1,1) double
s2.x (1,1) double
s2.y (1,1) double
end
end
and call TestStructArgs2(‘a’, 1, ‘b’, 2, ‘x’, 3, ‘y’, 4)
But what if I would also like to call the second example by passing whole structs, TestStructArgs2(struct(‘a’, 1, ‘b’, 2), struct(‘x’, 3, ‘y’, 4)) ? There doesn’t appear to be any ambiguity in allowing both approaches, if they’re not mixed-and-matched.
Further, some MATLAB built-in functions permit this e.g. the following runs just fine
>> opts = struct(‘Color’, ‘r’, ‘LineWidth’, 2);
>> x = linspace(0,1,200); y = cos(x);
>> plot(x, y, opts)
There is an answer on the messageboard from 2022 here which suggests adding the attribute StructExpand after arguments but this causes an error if I add it to the above example
Many thanks for any helpHello, is it possible when defining a function with name-value argument pairs to allow a user to pass the struct(s) that define these name-value pairs directly to the function?
For example, I can define
function [s1, s2] = TestStructArgs(s1, s2)
arguments
s1 (1,1) struct
s2 (1,1) struct
end
end
then call TestStructArgs(struct(‘a’, 1, ‘b’, 2), struct(‘x’, 3, ‘y’, 4))
Or, I can define
function [s1, s2] = TestStructArgs2(s1, s2)
arguments
s1.a (1,1) double
s1.b (1,1) double
s2.x (1,1) double
s2.y (1,1) double
end
end
and call TestStructArgs2(‘a’, 1, ‘b’, 2, ‘x’, 3, ‘y’, 4)
But what if I would also like to call the second example by passing whole structs, TestStructArgs2(struct(‘a’, 1, ‘b’, 2), struct(‘x’, 3, ‘y’, 4)) ? There doesn’t appear to be any ambiguity in allowing both approaches, if they’re not mixed-and-matched.
Further, some MATLAB built-in functions permit this e.g. the following runs just fine
>> opts = struct(‘Color’, ‘r’, ‘LineWidth’, 2);
>> x = linspace(0,1,200); y = cos(x);
>> plot(x, y, opts)
There is an answer on the messageboard from 2022 here which suggests adding the attribute StructExpand after arguments but this causes an error if I add it to the above example
Many thanks for any help Hello, is it possible when defining a function with name-value argument pairs to allow a user to pass the struct(s) that define these name-value pairs directly to the function?
For example, I can define
function [s1, s2] = TestStructArgs(s1, s2)
arguments
s1 (1,1) struct
s2 (1,1) struct
end
end
then call TestStructArgs(struct(‘a’, 1, ‘b’, 2), struct(‘x’, 3, ‘y’, 4))
Or, I can define
function [s1, s2] = TestStructArgs2(s1, s2)
arguments
s1.a (1,1) double
s1.b (1,1) double
s2.x (1,1) double
s2.y (1,1) double
end
end
and call TestStructArgs2(‘a’, 1, ‘b’, 2, ‘x’, 3, ‘y’, 4)
But what if I would also like to call the second example by passing whole structs, TestStructArgs2(struct(‘a’, 1, ‘b’, 2), struct(‘x’, 3, ‘y’, 4)) ? There doesn’t appear to be any ambiguity in allowing both approaches, if they’re not mixed-and-matched.
Further, some MATLAB built-in functions permit this e.g. the following runs just fine
>> opts = struct(‘Color’, ‘r’, ‘LineWidth’, 2);
>> x = linspace(0,1,200); y = cos(x);
>> plot(x, y, opts)
There is an answer on the messageboard from 2022 here which suggests adding the attribute StructExpand after arguments but this causes an error if I add it to the above example
Many thanks for any help arguments, struct, validation, name-value MATLAB Answers — New Questions
Difference in computational time
Hi all, I am working on a curve fitting project and I have a couple of curves to fit. For 2 of the curves, the fitting function involves an integration and I was told that I will need to make each of the data loop through the function (using the for loop). The below is my first code, which takes less than a second to complete.
tic
% Preparation
clear; clc
load Steady_State_Data.mat
%% Preamble
% Fundamental constants
h = 4.0135667696*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
% Clean up of data to select range of values
Absorbance = log10(T_substrate./T_sample);
e = E >= 0 & E <= 2.0; % returns boolean value of the indices that satisfies the logical condition defined above
A = find(e); % gives indices that are non-zero
N = length(A); % no. of elements that are non-zero
n = length(E) + 1;
% Data for fitting
E_p = E(n-N:n-1);
Abs = Absorbance(n-N:n-1) – min(Absorbance);
% Fitting function: Elliott’s Model for Steady State with non-parabolic factor
function F = EM_SS_wR(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*(p(5))^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
p(2)*((2*pi*p(4)^3/2)/E_p)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
end
F = F(:);
end
% Carrier Contribution
function F = EM_SS_wR_CC(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*(p(5))^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1));
end
F = F(:);
end
% Excitoninc Contribution
EM_SS_wR_EC = @(p, E_p) p(2)*((2*pi*p(4)^3/2)/E_p)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
%% Curve fitting options
% Initial parameter guess and bounds
lb = [-Inf, -Inf, 0, 0, -Inf, -Inf]; ub = [Inf, Inf, 55, 0.030, Inf, Inf];
p0 = [0.13, 0.11, 1.4, 0.025, 0.12, 0.035]; % refer to the next line for their order
% p0 = [A1, A2, Eg, Eb, R, g]
% lsqcurvefit and choose between different algorithm that lsqcurvefit employs (3C1, comment those lines that are not choosen and uncomment the line that is choosen, if not, matlab will take the last line of "optim_lsq" by default)
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, 1000, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘trust-region-reflective’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘interior-point’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, 1000, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% Solver for lsqcurvefit
[p, residualnorm, residual, exitflag, output, lambda, jacobian] = lsqcurvefit(@EM_SS_wR, p0, E_p, Abs, lb, ub);
%% Error bars calculation
ci = nlparci(p, residual, ‘Jacobian’, jacobian);
PCI = table(ci(:,1), p(:), ci(:,2),’VariableNames’,{‘CI 0.025′,’p’,’CI 0.975′});
Parameter_CI = table2array(PCI);
upper_bar = (Parameter_CI(:,3) – Parameter_CI(:,2))./2;
lower_bar = (Parameter_CI(:,2) – Parameter_CI(:,1))./2;
%% Parameter values (refer to command window)
p1 = p(1,1);
p2 = p(1,2);
p3 = p(1,3);
p4 = p(1,4);
p5 = p(1,5);
p6 = p(1,6);
e1 = lower_bar(1,1);
e2 = lower_bar(2,1);
e3 = lower_bar(3,1);
e4 = lower_bar(4,1);
e5 = lower_bar(5,1);
e6 = lower_bar(6,1);
X1 = [‘ A1 = ‘, num2str(p1), char(177), num2str(e1)];
X2 = [‘ A2 = ‘, num2str(p2), char(177), num2str(e2)];
X3 = [‘ Eg = ‘, num2str(p3), char(177), num2str(e3)];
X4 = [‘ Eb = ‘, num2str(p4), char(177), num2str(e4)];
X5 = [‘ R = ‘, num2str(p5), char(177), num2str(e5)];
X6 = [‘ g = ‘, num2str(p6), char(177), num2str(e6)];
disp(X1);
disp(X2);
disp(X3);
disp(X4);
disp(X5);
disp(X6);
% Table of parameter values
parameter_name = {‘A1’; ‘A2’; ‘Eg’; ‘Eb’; ‘R’; ‘g’};
parameter_values = [p1; p2; p3; p4; p5; p6];
error = [e1; e2; e3; e4; e5; e6];
T = table(parameter_values, error, ‘RowNames’,parameter_name);
disp(T)
%% Plot command
plot(E_p, Abs, ‘o’, ‘Color’,’b’) % scatter plot
hold on
plot(E_p, EM_SS_wR(p, E_p), ‘LineWidth’, 1.0, ‘Color’,’red’) % curve fitting
plot(E_p, EM_SS_wR_CC(p, E_p), ‘LineWidth’, 1.0,’Color’,’black’) % carrier contribution
plot(E_p, EM_SS_wR_EC(p, E_p), ‘LineWidth’, 1.0, ‘Color’,’green’) % excitonic contribution
% Table of parameter values
TString = evalc(‘disp(T)’);
TString = strrep(TString,'<strong>’,’bf’);
TString = strrep(TString,'</strong>’,’rm’);
TString = strrep(TString,’_’,’_’);
FixedWidth = get(0,’FixedWidthFontName’);
annotation(gcf,’Textbox’,’String’,TString,’Interpreter’,’tex’,…
‘FontName’,FixedWidth,’Units’,’Normalized’,’Position’,[0.15, 0.8, 0.1, 0.1]);
xlabel(‘Probe energy (eV)’)
ylabel(‘Absorbance.O.D’)
legend(‘Experimental Data’, ‘Fitted Curve’, ‘Carrier Contribution’,’Excitonic Contribution’, ‘Location’,’southeast’)
hold off
%% Miscellaneous
% For a rectangular pic:
% drag horizontally until it just covers the letter ‘c’ in the word ‘col’
% For a square pic:
% drag horizontall until it just covers the letter ‘o’ in the word ‘Contribution’ in the next line)
% legend(‘Experimental Data’, ‘Fitted Curve’, ‘Carrier Contribution’,’Excitonic Contribution’)
toc
However, when using my second code (shown below) it takes around 5 minutes to complete running. May I please ask for the difference in the computational time?
tic
%% Preparation
clc; clear
data = importdata("FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
load Steady_State_Parameter_Values.mat
%% Preamble
% Fundamental constants
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
delay_t = data(1, :);
% Parameter values from Steady state fiting
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
t1 = 0.5342;
t2 = 1.0257;
t3 = 1.9673;
t4 = 3.9554;
carrier_T = [1198.8, 816.7, 446.8, 328.7];
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
% Data for fitting
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
delta_Abs1 = data(Range_W,col1);
delta_Abs2 = data(Range_W,col2);
delta_Abs3 = data(Range_W,col3);
delta_Abs4 = data(Range_W,col4);
% Fitting function: Elliott’s Model for Transient Absorption
function F = EM_TA_wR1(x, e_p)
load Steady_State_Parameter_Values.mat
kB = 8.617333268*10^-5; % units: eV/ K
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 1;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)./(E_p).*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)./E_p.*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR2(x, e_p)
data = importdata("Experimental dataTransient AbsorptionFCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 2;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR3(x, e_p)
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 3;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR4(x, e_p)
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 4;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
% Curve fitting
lb = [Eg, Eb, g, 0.3, 0.5, 0.2]; ub = [55, 0.05, 0.05, 20, 2, 1];
x0 = [1.65, 0.03, 0.03, 1.3, 1, 0.3];
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’, ‘MaxFunctionEvaluations’,10^5, ‘MaxIterations’, 10^5, ‘FunctionTolerance’,10^-20, ‘StepTolerance’, 10^-20);
delta_Abs(:,1)= data_new2(:,1);
x1 = lsqcurvefit(@EM_TA_wR1, x0, E_p, delta_Abs1, lb, ub, optim_lsq);
x2 = lsqcurvefit(@EM_TA_wR2, x1, E_p, delta_Abs2, lb, ub, optim_lsq);
x3 = lsqcurvefit(@EM_TA_wR3, x2, E_p, delta_Abs3, lb, ub, optim_lsq);
x4 = lsqcurvefit(@EM_TA_wR4, x3, E_p, delta_Abs4, lb, ub, optim_lsq);
plot(E_p, delta_Abs1, ‘o’,’color’,’blue’)
hold on
plot(E_p, delta_Abs2, ‘o’, ‘color’, ‘yellow’)
plot(E_p, delta_Abs3, ‘o’, ‘color’, ‘green’)
plot(E_p, delta_Abs4, ‘o’, ‘color’, ‘magenta’)
plot(E_p, EM_TA_wR1(x1, E_p), ‘color’, ‘blue’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR2(x2, E_p), ‘color’, ‘yellow’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR3(x3, E_p), ‘color’, ‘green’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR4(x4, E_p), ‘color’, ‘magenta’, ‘LineWidth’, 4.0)
xlabel(‘Probe Photon Energy (eV)’)
ylabel(‘Delta A (O.D.)’)
legend(‘0.5 ps’, ‘1.0 ps’, ‘2.0 ps’, ‘4.0 ps’, ‘Location’, ‘southeast’)
hold off
disp(x1)
disp(x2)
disp(x3)
disp(x4)
tocHi all, I am working on a curve fitting project and I have a couple of curves to fit. For 2 of the curves, the fitting function involves an integration and I was told that I will need to make each of the data loop through the function (using the for loop). The below is my first code, which takes less than a second to complete.
tic
% Preparation
clear; clc
load Steady_State_Data.mat
%% Preamble
% Fundamental constants
h = 4.0135667696*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
% Clean up of data to select range of values
Absorbance = log10(T_substrate./T_sample);
e = E >= 0 & E <= 2.0; % returns boolean value of the indices that satisfies the logical condition defined above
A = find(e); % gives indices that are non-zero
N = length(A); % no. of elements that are non-zero
n = length(E) + 1;
% Data for fitting
E_p = E(n-N:n-1);
Abs = Absorbance(n-N:n-1) – min(Absorbance);
% Fitting function: Elliott’s Model for Steady State with non-parabolic factor
function F = EM_SS_wR(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*(p(5))^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
p(2)*((2*pi*p(4)^3/2)/E_p)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
end
F = F(:);
end
% Carrier Contribution
function F = EM_SS_wR_CC(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*(p(5))^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1));
end
F = F(:);
end
% Excitoninc Contribution
EM_SS_wR_EC = @(p, E_p) p(2)*((2*pi*p(4)^3/2)/E_p)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
%% Curve fitting options
% Initial parameter guess and bounds
lb = [-Inf, -Inf, 0, 0, -Inf, -Inf]; ub = [Inf, Inf, 55, 0.030, Inf, Inf];
p0 = [0.13, 0.11, 1.4, 0.025, 0.12, 0.035]; % refer to the next line for their order
% p0 = [A1, A2, Eg, Eb, R, g]
% lsqcurvefit and choose between different algorithm that lsqcurvefit employs (3C1, comment those lines that are not choosen and uncomment the line that is choosen, if not, matlab will take the last line of "optim_lsq" by default)
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, 1000, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘trust-region-reflective’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘interior-point’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, 1000, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% Solver for lsqcurvefit
[p, residualnorm, residual, exitflag, output, lambda, jacobian] = lsqcurvefit(@EM_SS_wR, p0, E_p, Abs, lb, ub);
%% Error bars calculation
ci = nlparci(p, residual, ‘Jacobian’, jacobian);
PCI = table(ci(:,1), p(:), ci(:,2),’VariableNames’,{‘CI 0.025′,’p’,’CI 0.975′});
Parameter_CI = table2array(PCI);
upper_bar = (Parameter_CI(:,3) – Parameter_CI(:,2))./2;
lower_bar = (Parameter_CI(:,2) – Parameter_CI(:,1))./2;
%% Parameter values (refer to command window)
p1 = p(1,1);
p2 = p(1,2);
p3 = p(1,3);
p4 = p(1,4);
p5 = p(1,5);
p6 = p(1,6);
e1 = lower_bar(1,1);
e2 = lower_bar(2,1);
e3 = lower_bar(3,1);
e4 = lower_bar(4,1);
e5 = lower_bar(5,1);
e6 = lower_bar(6,1);
X1 = [‘ A1 = ‘, num2str(p1), char(177), num2str(e1)];
X2 = [‘ A2 = ‘, num2str(p2), char(177), num2str(e2)];
X3 = [‘ Eg = ‘, num2str(p3), char(177), num2str(e3)];
X4 = [‘ Eb = ‘, num2str(p4), char(177), num2str(e4)];
X5 = [‘ R = ‘, num2str(p5), char(177), num2str(e5)];
X6 = [‘ g = ‘, num2str(p6), char(177), num2str(e6)];
disp(X1);
disp(X2);
disp(X3);
disp(X4);
disp(X5);
disp(X6);
% Table of parameter values
parameter_name = {‘A1’; ‘A2’; ‘Eg’; ‘Eb’; ‘R’; ‘g’};
parameter_values = [p1; p2; p3; p4; p5; p6];
error = [e1; e2; e3; e4; e5; e6];
T = table(parameter_values, error, ‘RowNames’,parameter_name);
disp(T)
%% Plot command
plot(E_p, Abs, ‘o’, ‘Color’,’b’) % scatter plot
hold on
plot(E_p, EM_SS_wR(p, E_p), ‘LineWidth’, 1.0, ‘Color’,’red’) % curve fitting
plot(E_p, EM_SS_wR_CC(p, E_p), ‘LineWidth’, 1.0,’Color’,’black’) % carrier contribution
plot(E_p, EM_SS_wR_EC(p, E_p), ‘LineWidth’, 1.0, ‘Color’,’green’) % excitonic contribution
% Table of parameter values
TString = evalc(‘disp(T)’);
TString = strrep(TString,'<strong>’,’bf’);
TString = strrep(TString,'</strong>’,’rm’);
TString = strrep(TString,’_’,’_’);
FixedWidth = get(0,’FixedWidthFontName’);
annotation(gcf,’Textbox’,’String’,TString,’Interpreter’,’tex’,…
‘FontName’,FixedWidth,’Units’,’Normalized’,’Position’,[0.15, 0.8, 0.1, 0.1]);
xlabel(‘Probe energy (eV)’)
ylabel(‘Absorbance.O.D’)
legend(‘Experimental Data’, ‘Fitted Curve’, ‘Carrier Contribution’,’Excitonic Contribution’, ‘Location’,’southeast’)
hold off
%% Miscellaneous
% For a rectangular pic:
% drag horizontally until it just covers the letter ‘c’ in the word ‘col’
% For a square pic:
% drag horizontall until it just covers the letter ‘o’ in the word ‘Contribution’ in the next line)
% legend(‘Experimental Data’, ‘Fitted Curve’, ‘Carrier Contribution’,’Excitonic Contribution’)
toc
However, when using my second code (shown below) it takes around 5 minutes to complete running. May I please ask for the difference in the computational time?
tic
%% Preparation
clc; clear
data = importdata("FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
load Steady_State_Parameter_Values.mat
%% Preamble
% Fundamental constants
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
delay_t = data(1, :);
% Parameter values from Steady state fiting
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
t1 = 0.5342;
t2 = 1.0257;
t3 = 1.9673;
t4 = 3.9554;
carrier_T = [1198.8, 816.7, 446.8, 328.7];
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
% Data for fitting
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
delta_Abs1 = data(Range_W,col1);
delta_Abs2 = data(Range_W,col2);
delta_Abs3 = data(Range_W,col3);
delta_Abs4 = data(Range_W,col4);
% Fitting function: Elliott’s Model for Transient Absorption
function F = EM_TA_wR1(x, e_p)
load Steady_State_Parameter_Values.mat
kB = 8.617333268*10^-5; % units: eV/ K
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 1;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)./(E_p).*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)./E_p.*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR2(x, e_p)
data = importdata("Experimental dataTransient AbsorptionFCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 2;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR3(x, e_p)
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 3;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR4(x, e_p)
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 4;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
% Curve fitting
lb = [Eg, Eb, g, 0.3, 0.5, 0.2]; ub = [55, 0.05, 0.05, 20, 2, 1];
x0 = [1.65, 0.03, 0.03, 1.3, 1, 0.3];
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’, ‘MaxFunctionEvaluations’,10^5, ‘MaxIterations’, 10^5, ‘FunctionTolerance’,10^-20, ‘StepTolerance’, 10^-20);
delta_Abs(:,1)= data_new2(:,1);
x1 = lsqcurvefit(@EM_TA_wR1, x0, E_p, delta_Abs1, lb, ub, optim_lsq);
x2 = lsqcurvefit(@EM_TA_wR2, x1, E_p, delta_Abs2, lb, ub, optim_lsq);
x3 = lsqcurvefit(@EM_TA_wR3, x2, E_p, delta_Abs3, lb, ub, optim_lsq);
x4 = lsqcurvefit(@EM_TA_wR4, x3, E_p, delta_Abs4, lb, ub, optim_lsq);
plot(E_p, delta_Abs1, ‘o’,’color’,’blue’)
hold on
plot(E_p, delta_Abs2, ‘o’, ‘color’, ‘yellow’)
plot(E_p, delta_Abs3, ‘o’, ‘color’, ‘green’)
plot(E_p, delta_Abs4, ‘o’, ‘color’, ‘magenta’)
plot(E_p, EM_TA_wR1(x1, E_p), ‘color’, ‘blue’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR2(x2, E_p), ‘color’, ‘yellow’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR3(x3, E_p), ‘color’, ‘green’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR4(x4, E_p), ‘color’, ‘magenta’, ‘LineWidth’, 4.0)
xlabel(‘Probe Photon Energy (eV)’)
ylabel(‘Delta A (O.D.)’)
legend(‘0.5 ps’, ‘1.0 ps’, ‘2.0 ps’, ‘4.0 ps’, ‘Location’, ‘southeast’)
hold off
disp(x1)
disp(x2)
disp(x3)
disp(x4)
toc Hi all, I am working on a curve fitting project and I have a couple of curves to fit. For 2 of the curves, the fitting function involves an integration and I was told that I will need to make each of the data loop through the function (using the for loop). The below is my first code, which takes less than a second to complete.
tic
% Preparation
clear; clc
load Steady_State_Data.mat
%% Preamble
% Fundamental constants
h = 4.0135667696*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
% Clean up of data to select range of values
Absorbance = log10(T_substrate./T_sample);
e = E >= 0 & E <= 2.0; % returns boolean value of the indices that satisfies the logical condition defined above
A = find(e); % gives indices that are non-zero
N = length(A); % no. of elements that are non-zero
n = length(E) + 1;
% Data for fitting
E_p = E(n-N:n-1);
Abs = Absorbance(n-N:n-1) – min(Absorbance);
% Fitting function: Elliott’s Model for Steady State with non-parabolic factor
function F = EM_SS_wR(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*(p(5))^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1)) + …
p(2)*((2*pi*p(4)^3/2)/E_p)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
end
F = F(:);
end
% Carrier Contribution
function F = EM_SS_wR_CC(p, e_p)
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = p(1)*(2*pi*sqrt(p(4))/E_p)*(1/p(6))*…
(integral(@(E)sech(((E_p – E)./p(6)))*(1 + 10*p(5)*(E – p(3)) + …
126*(p(5))^2*(E – p(3))^2)/(1 – exp(-2*pi*sqrt(p(4)/(E – p(3))))), p(3), Inf, ‘ArrayValued’, 1));
end
F = F(:);
end
% Excitoninc Contribution
EM_SS_wR_EC = @(p, E_p) p(2)*((2*pi*p(4)^3/2)/E_p)*1/p(6)*(…
(1/1^3)*sech((E_p – p(3) + p(4)/1^2)./p(6)) + …
(1/2^3)*sech((E_p – p(3) + p(4)/2^2)./p(6)) + …
(1/3^3)*sech((E_p – p(3) + p(4)/3^2)./p(6)) + …
(1/4^3)*sech((E_p – p(3) + p(4)/4^2)./p(6)) + …
(1/5^3)*sech((E_p – p(3) + p(4)/5^2)./p(6)) + …
(1/6^3)*sech((E_p – p(3) + p(4)/6^2)./p(6)) + …
(1/7^3)*sech((E_p – p(3) + p(4)/7^2)./p(6)));
%% Curve fitting options
% Initial parameter guess and bounds
lb = [-Inf, -Inf, 0, 0, -Inf, -Inf]; ub = [Inf, Inf, 55, 0.030, Inf, Inf];
p0 = [0.13, 0.11, 1.4, 0.025, 0.12, 0.035]; % refer to the next line for their order
% p0 = [A1, A2, Eg, Eb, R, g]
% lsqcurvefit and choose between different algorithm that lsqcurvefit employs (3C1, comment those lines that are not choosen and uncomment the line that is choosen, if not, matlab will take the last line of "optim_lsq" by default)
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, 1000, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘trust-region-reflective’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘interior-point’, ‘MaxFunctionEvaluations’,1000, ‘MaxIterations’, 1000, ‘FunctionTolerance’,10^-9, ‘StepTolerance’, 10^-9);
% Solver for lsqcurvefit
[p, residualnorm, residual, exitflag, output, lambda, jacobian] = lsqcurvefit(@EM_SS_wR, p0, E_p, Abs, lb, ub);
%% Error bars calculation
ci = nlparci(p, residual, ‘Jacobian’, jacobian);
PCI = table(ci(:,1), p(:), ci(:,2),’VariableNames’,{‘CI 0.025′,’p’,’CI 0.975′});
Parameter_CI = table2array(PCI);
upper_bar = (Parameter_CI(:,3) – Parameter_CI(:,2))./2;
lower_bar = (Parameter_CI(:,2) – Parameter_CI(:,1))./2;
%% Parameter values (refer to command window)
p1 = p(1,1);
p2 = p(1,2);
p3 = p(1,3);
p4 = p(1,4);
p5 = p(1,5);
p6 = p(1,6);
e1 = lower_bar(1,1);
e2 = lower_bar(2,1);
e3 = lower_bar(3,1);
e4 = lower_bar(4,1);
e5 = lower_bar(5,1);
e6 = lower_bar(6,1);
X1 = [‘ A1 = ‘, num2str(p1), char(177), num2str(e1)];
X2 = [‘ A2 = ‘, num2str(p2), char(177), num2str(e2)];
X3 = [‘ Eg = ‘, num2str(p3), char(177), num2str(e3)];
X4 = [‘ Eb = ‘, num2str(p4), char(177), num2str(e4)];
X5 = [‘ R = ‘, num2str(p5), char(177), num2str(e5)];
X6 = [‘ g = ‘, num2str(p6), char(177), num2str(e6)];
disp(X1);
disp(X2);
disp(X3);
disp(X4);
disp(X5);
disp(X6);
% Table of parameter values
parameter_name = {‘A1’; ‘A2’; ‘Eg’; ‘Eb’; ‘R’; ‘g’};
parameter_values = [p1; p2; p3; p4; p5; p6];
error = [e1; e2; e3; e4; e5; e6];
T = table(parameter_values, error, ‘RowNames’,parameter_name);
disp(T)
%% Plot command
plot(E_p, Abs, ‘o’, ‘Color’,’b’) % scatter plot
hold on
plot(E_p, EM_SS_wR(p, E_p), ‘LineWidth’, 1.0, ‘Color’,’red’) % curve fitting
plot(E_p, EM_SS_wR_CC(p, E_p), ‘LineWidth’, 1.0,’Color’,’black’) % carrier contribution
plot(E_p, EM_SS_wR_EC(p, E_p), ‘LineWidth’, 1.0, ‘Color’,’green’) % excitonic contribution
% Table of parameter values
TString = evalc(‘disp(T)’);
TString = strrep(TString,'<strong>’,’bf’);
TString = strrep(TString,'</strong>’,’rm’);
TString = strrep(TString,’_’,’_’);
FixedWidth = get(0,’FixedWidthFontName’);
annotation(gcf,’Textbox’,’String’,TString,’Interpreter’,’tex’,…
‘FontName’,FixedWidth,’Units’,’Normalized’,’Position’,[0.15, 0.8, 0.1, 0.1]);
xlabel(‘Probe energy (eV)’)
ylabel(‘Absorbance.O.D’)
legend(‘Experimental Data’, ‘Fitted Curve’, ‘Carrier Contribution’,’Excitonic Contribution’, ‘Location’,’southeast’)
hold off
%% Miscellaneous
% For a rectangular pic:
% drag horizontally until it just covers the letter ‘c’ in the word ‘col’
% For a square pic:
% drag horizontall until it just covers the letter ‘o’ in the word ‘Contribution’ in the next line)
% legend(‘Experimental Data’, ‘Fitted Curve’, ‘Carrier Contribution’,’Excitonic Contribution’)
toc
However, when using my second code (shown below) it takes around 5 minutes to complete running. May I please ask for the difference in the computational time?
tic
%% Preparation
clc; clear
data = importdata("FCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
load Steady_State_Parameter_Values.mat
%% Preamble
% Fundamental constants
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
% Data
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
delay_t = data(1, :);
% Parameter values from Steady state fiting
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
t1 = 0.5342;
t2 = 1.0257;
t3 = 1.9673;
t4 = 3.9554;
carrier_T = [1198.8, 816.7, 446.8, 328.7];
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
% Data for fitting
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
delta_Abs1 = data(Range_W,col1);
delta_Abs2 = data(Range_W,col2);
delta_Abs3 = data(Range_W,col3);
delta_Abs4 = data(Range_W,col4);
% Fitting function: Elliott’s Model for Transient Absorption
function F = EM_TA_wR1(x, e_p)
load Steady_State_Parameter_Values.mat
kB = 8.617333268*10^-5; % units: eV/ K
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 1;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)./(E_p).*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)./E_p.*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR2(x, e_p)
data = importdata("Experimental dataTransient AbsorptionFCPIB-293K-2.5mW-400nm-Jan072021 -ibg -bg -chirp.csv"); % insert file path within parenthesis
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 2;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR3(x, e_p)
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 3;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
function F = EM_TA_wR4(x, e_p)
load Steady_State_Parameter_Values.mat
h = 4.1356677*10^-15; % units: eV/ Hz
c = 3*10^8; % SI units
kB = 8.617333268*10^-5; % units: eV/ K
Wavelength = data(:, 1);% units: nm
E = (h*c)./(Wavelength*10^-9);
A1 = p(1,1);
A2 = p(1,2);
Eg = p(1,3);
Eb = p(1,4);
R = p(1,5);
g = p(1,6);
col1 = 56;
col2 = 63;
col3 = 74;
col4 = 87;
Range_E = E >= 1.5 & E <= 2.0;
Range_W = Wavelength >= (h*c)/(2.0*10^-9) & Wavelength <= (h*c)/(1.5*10^-9);
E_p = E(Range_E); % selected probe energies
data_new2 = data(Range_W, [col1,col2,col3,col4]);
carrier_T = [1198.8, 816.7, 446.8, 328.7];
n = 4;
for i = 1:numel(e_p)
E_p = e_p(i);
F(i) = x(5)*A1*((2*pi*sqrt(x(2)))/E_p)*1/g*(integral(@(E)sech(((E_p – E)./g))*(1 + 10*R*(E – x(1)) + …
126*(R)^2*(E – x(1))^2)/(1 – exp(-2*pi*sqrt(x(2)/(E – x(1))))), x(1), Inf, ‘ArrayValued’, 1))*(1 – 1/(1 + exp((E_p – x(4))/(kB*carrier_T(1, n)))))^2 – …
A1*(2*pi*sqrt(Eb)/E_p)*(1/g)*…
(integral(@(e)sech(((E_p – e)./g))*(1 + 10*R*(e – Eg) + …
126*(R)^2*(e – Eg)^2)/(1 – exp(-2*pi*sqrt(Eb/(e – Eg)))), Eg, Inf, ‘ArrayValued’, 1)) + …
x(6)*A2*(4*pi*(x(2))^3/2)*1/x(3)*(…
(1/1^3)*sech((E_p – x(1) + x(2)/1^2)./x(3)) + …
(1/2^3)*sech((E_p – x(1) + x(2)/2^2)./x(3)) + …
(1/3^3)*sech((E_p – x(1) + x(2)/3^2)./x(3)) + …
(1/4^3)*sech((E_p – x(1) + x(2)/4^2)./x(3)) + …
(1/5^3)*sech((E_p – x(1) + x(2)/5^2)./x(3)) + …
(1/6^3)*sech((E_p – x(1) + x(2)/6^2)./x(3)) + …
(1/7^3)*sech((E_p – x(1) + x(2)/7^2)./x(3))) – …
A2*(4*pi*Eb^3/2)*1/g*(…
(1/1^3)*sech((E_p – Eg + Eb/1^2)./g) + …
(1/2^3)*sech((E_p – Eg + Eb/2^2)./g) + …
(1/3^3)*sech((E_p – Eg + Eb/3^2)./g) + …
(1/4^3)*sech((E_p – Eg + Eb/4^2)./g) + …
(1/5^3)*sech((E_p – Eg + Eb/5^2)./g) + …
(1/6^3)*sech((E_p – Eg + Eb/6^2)./g) + …
(1/7^3)*sech((E_p – Eg + Eb/7^2)./g));
end
F = F(:);
end
% Curve fitting
lb = [Eg, Eb, g, 0.3, 0.5, 0.2]; ub = [55, 0.05, 0.05, 20, 2, 1];
x0 = [1.65, 0.03, 0.03, 1.3, 1, 0.3];
optim_lsq = optimoptions(‘lsqcurvefit’, ‘Algorithm’, ‘levenberg-marquardt’, ‘MaxFunctionEvaluations’,10^5, ‘MaxIterations’, 10^5, ‘FunctionTolerance’,10^-20, ‘StepTolerance’, 10^-20);
delta_Abs(:,1)= data_new2(:,1);
x1 = lsqcurvefit(@EM_TA_wR1, x0, E_p, delta_Abs1, lb, ub, optim_lsq);
x2 = lsqcurvefit(@EM_TA_wR2, x1, E_p, delta_Abs2, lb, ub, optim_lsq);
x3 = lsqcurvefit(@EM_TA_wR3, x2, E_p, delta_Abs3, lb, ub, optim_lsq);
x4 = lsqcurvefit(@EM_TA_wR4, x3, E_p, delta_Abs4, lb, ub, optim_lsq);
plot(E_p, delta_Abs1, ‘o’,’color’,’blue’)
hold on
plot(E_p, delta_Abs2, ‘o’, ‘color’, ‘yellow’)
plot(E_p, delta_Abs3, ‘o’, ‘color’, ‘green’)
plot(E_p, delta_Abs4, ‘o’, ‘color’, ‘magenta’)
plot(E_p, EM_TA_wR1(x1, E_p), ‘color’, ‘blue’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR2(x2, E_p), ‘color’, ‘yellow’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR3(x3, E_p), ‘color’, ‘green’, ‘LineWidth’, 4.0)
plot(E_p, EM_TA_wR4(x4, E_p), ‘color’, ‘magenta’, ‘LineWidth’, 4.0)
xlabel(‘Probe Photon Energy (eV)’)
ylabel(‘Delta A (O.D.)’)
legend(‘0.5 ps’, ‘1.0 ps’, ‘2.0 ps’, ‘4.0 ps’, ‘Location’, ‘southeast’)
hold off
disp(x1)
disp(x2)
disp(x3)
disp(x4)
toc curve fitting, computational time MATLAB Answers — New Questions
How can i run my .m file of Report Generator?
Hi, I wanted to know how to use the .m file from my report that I customized and saved with the "Generate MATLAB File" option, because I need to use that .m file in a MATLAB function. But when I run the .m file, it doesn’t generate any report. It only shows this:
What can i do?
Thanks
How i generate the .m:Hi, I wanted to know how to use the .m file from my report that I customized and saved with the "Generate MATLAB File" option, because I need to use that .m file in a MATLAB function. But when I run the .m file, it doesn’t generate any report. It only shows this:
What can i do?
Thanks
How i generate the .m: Hi, I wanted to know how to use the .m file from my report that I customized and saved with the "Generate MATLAB File" option, because I need to use that .m file in a MATLAB function. But when I run the .m file, it doesn’t generate any report. It only shows this:
What can i do?
Thanks
How i generate the .m: "report-generator" "matlab" MATLAB Answers — New Questions
How can I disable data logging for all the signals in my model?
I have enabled data logging for a lot of signals in my model, how can do this via command line functions?I have enabled data logging for a lot of signals in my model, how can do this via command line functions? I have enabled data logging for a lot of signals in my model, how can do this via command line functions? MATLAB Answers — New Questions
New Teams Apps management
Hi,
how can I prohibit that users can use 3rd party apps via policy? Do I need to click every single app an configure that a user cannot use it?
What is the improvement of this Microsoft?!?
Hi, how can I prohibit that users can use 3rd party apps via policy? Do I need to click every single app an configure that a user cannot use it? What is the improvement of this Microsoft?!? Read More
Mot de passe
Bonjour j ai changé mon mot de passe outlook.fr mais je ne peux plus ouvrir mon pc Lenovo et j ai oublié ancien mot de passe que faire ? Merci
Bonjour j ai changé mon mot de passe outlook.fr mais je ne peux plus ouvrir mon pc Lenovo et j ai oublié ancien mot de passe que faire ? Merci Read More
Microsoft Teams Video feed still corrupted
Despite many previous reports like this one Teams has still not fixed the problem.
My partner, a student, also uses Teams for online lectures etc. She gets the exact same issue of green cast over her displayed feed on her attendee sessions using her Asus Chromebook with built in cam. I have looked at all settings on the Chromebook & Teams and everything seems fine. This is 2024 now so the problem has not been fixed by Teams.
Will MS Teams fix this problem, or notify Asus Chromebook users of the incompatibility issue, or offer any workarounds/solutions?
Despite many previous reports like this one Teams has still not fixed the problem. My partner, a student, also uses Teams for online lectures etc. She gets the exact same issue of green cast over her displayed feed on her attendee sessions using her Asus Chromebook with built in cam. I have looked at all settings on the Chromebook & Teams and everything seems fine. This is 2024 now so the problem has not been fixed by Teams.Will MS Teams fix this problem, or notify Asus Chromebook users of the incompatibility issue, or offer any workarounds/solutions? Read More
Dragging files from OneDrive explorer now copies them?
I think you’re better off having the files copied instead of moved. If something goes wrong when moving a file or folder it could get corrupted and be lost forever. The original file or folder can be deleted after you know the file copied without any problems.
I think you’re better off having the files copied instead of moved. If something goes wrong when moving a file or folder it could get corrupted and be lost forever. The original file or folder can be deleted after you know the file copied without any problems. Read More
Mouse double click gets latest used files, etc.
I have Windows 11 23H2 OS Build 22631.3737.
When I double click on an empty area of the desktop I get a list of the latest used files etc and folders.
How to I STOP that?
I have Windows 11 23H2 OS Build 22631.3737.When I double click on an empty area of the desktop I get a list of the latest used files etc and folders.How to I STOP that? Read More
When moving a folder near top of screen, I see movement which looks like a drop down menu? Can this
I don’t know how to explain what I’m seeing exactly.
When moving a folder and the folder goes near the top of the screen I see what looks like a drop down menu appear, and when I move the folder away from the top of the screen, it disappears.
Is there a way of stopping this from happening?
I don’t know how to explain what I’m seeing exactly.When moving a folder and the folder goes near the top of the screen I see what looks like a drop down menu appear, and when I move the folder away from the top of the screen, it disappears.Is there a way of stopping this from happening? Read More
Possible to install Windows 11 on unsupported CPU?
I have two laptops at home. One is built on Intel i5 6500 and the other is AMD Ryzen 7 1900X.
When I was trying to install Windows 11 from a bootable USB, it says “This PC can’t run Windows 11”. Then I was told to use the official PC Heather Check app to see what kind of system requirements are missing.
It turns on the CPU is too old and not supported by Windows 11. However, they are running perfectly with Windows 10. Is there any way to install Windows 11 on unsupported CPU so I can test out Windows 11?
I have two laptops at home. One is built on Intel i5 6500 and the other is AMD Ryzen 7 1900X. When I was trying to install Windows 11 from a bootable USB, it says “This PC can’t run Windows 11”. Then I was told to use the official PC Heather Check app to see what kind of system requirements are missing. It turns on the CPU is too old and not supported by Windows 11. However, they are running perfectly with Windows 10. Is there any way to install Windows 11 on unsupported CPU so I can test out Windows 11? Read More
How can I batch convert HEIC to JPG without losing quality?
Hello, I recently encountered a problem and hope to get your help. I have a bunch of HEIC format photos that need to be converted to JPEG format, and the operating system is Windows 11. I hope to maintain the original image quality as much as possible during the conversion process, and because there are a lot of photos, I hope to find a way to batch convert HEIC to JPG without losing quality. I have tried some online tools and software before, but I always feel that the quality of the converted pictures has declined, or the operation is not convenient enough.
Does anyone know any good method to solve my problem? Thank you very much for your help!
Hello, I recently encountered a problem and hope to get your help. I have a bunch of HEIC format photos that need to be converted to JPEG format, and the operating system is Windows 11. I hope to maintain the original image quality as much as possible during the conversion process, and because there are a lot of photos, I hope to find a way to batch convert HEIC to JPG without losing quality. I have tried some online tools and software before, but I always feel that the quality of the converted pictures has declined, or the operation is not convenient enough. Does anyone know any good method to solve my problem? Thank you very much for your help! Read More
What’s the difference between Azure savings plans for compute and Azure reservations?
A guide to help you choose the best option for your cloud computing needs
Introduction
Cloud computing is a powerful and flexible way to run your applications and services, but it can also be confusing and costly if you don’t know how to optimize your spending. Azure offers different options to help you save money on your costs in Azure, depending on your usage patterns and needs. In this article, we will compare and contrast two of these options: Azure savings plans for compute and reservations. We will also show you how to combine them to maximize your savings and flexibility. By the end of this article, you will have a better understanding of how to leverage these options to reduce your cloud computing bills and achieve your business goals.
What is an Azure savings plan for compute?
Azure savings plan for compute allows you to save up to 65% off usage of eligible compute resources, in exchange for making a fixed, hourly spend commitment for 1- or 3- years[1]. Savings plans benefits are available to a wide array of compute services, including Azure Virtual Machines, Azure App Service and Azure Functions premium plan. If you have consistent spend across different compute services, purchasing a savings plan may help reduce your overall costs.
Savings plan discounts apply to compute infrastructure charges (e.g., CPU, RAM, and storage) and vary based on the combination of compute service and region. The length of commitment term, not hourly commitment, governs the size of the discounts. Savings plans provide a discount, but do not affect the runtime state of your resources. Savings plan discounts do not apply to software licensing costs (e.g., Windows, Windows Server, or SQL Server). Azure Hybrid Benefit can be to reduce these licensing costs[2].
Under the savings plan model, Azure applies savings plan discounts to your eligible savings plan-eligible usage – usage from resources with the largest savings plan discount percentage is discounted first). The resulting charges are then deducted from your hourly commitment. Once the hourly commitment is exhausted, any remaining usage is billed at your pay-as-you-go rates.
Because this is an hourly commitment, even when there isn’t enough eligible usage in an hour to fully consume the commitment, you are still billed for the hour’s entire commitment.
Figure 1 Azure savings plans: Your global, flexible, and automatic path to savings
Azure savings plans – automatically flexible
Savings plans automatically apply the commitment to usage that would most benefit from it – regardless of service or region[3]. Since usage from resources with the highest savings plan discount always go first, you don’t have to worry about actively managing your commitment – savings plans automatically adapts to your usage patterns.
Savings plans are not tied to a specific Azure region or compute service – savings plans can provide cost savings on more than a half dozen compute services, including Azure Virtual Machines and Azure App Service. View a list of all included compute services, or view savings plan pricing in Azure pricing calculator, on the Azure Pricing page or by downloading your Azure price list.
Savings plans can be configured to make their discounts available to your entire EA billing account (aka enrollment) or MCA billing profile, or a specific management group, subscription, or resource group[4]. You can change the scope of your savings plan at any time.
While you can change the benefit scope of a savings plan, you are unable to modify the hourly commitment or change the term. In addition, as savings plans are inherently adaptable to changes to which compute services you utilize, you cannot cancel or exchange savings plans.
Figure 2 One plan, all locations: The global power of savings plans
What is an Azure reservation?
Azure reservations allow you to save up to 72% off usage of specific Azure resources, in exchange for making a 1-, 3-, or 5-year usage commitment[5]. Reservations are ideal for workloads that run continuously throughout the day, operate in one Azure region, and are not expected to materially change their infrastructure requirements in the next 1-, 3-, or 5-year. Azure reservations are available for a wide array of Azure services, including Azure Virtual Machines, Azure SQL database, and Azure Cosmos DB. If you have consistent and continuous usage of a particular Azure product, in a specific region, purchasing a reservation for that product can help reduce your overall costs.
Reservation savings apply to infrastructure charges (e.g., CPU, RAM and storage) and vary based on the Azure product and region. Like with savings plans, the commitment term of the reservation governs the discount. A reservation provides a discount but does not affect the runtime state of your resources. Reservation savings do not apply to software licensing costs (e.g., Windows, Windows Server, or SQL Server). However, Azure Hybrid Benefit can be to reduce these licensing costs.
By purchasing a reservation, you prepay, and commit to using a specific Azure product in a particular region. Each hour, your pay-as-you-go usage is evaluated, but instead of paying the pay-as-you-go rate, the prepaid reservation benefit is automatically applied to matching resources. Once all matching reservations are consumed, any remaining usage is billed under the savings plan model (if available) or at your pay-as-you-go rates. Because reservations are an hourly commitment, even when there isn’t enough eligible usage in an hour to fully consume the reservation, you still incur charges for the reservation each hour.
Reservation products are interchangeable with each other if they’re the same type of reservation. For example, you can exchange multiple compute reservations including Azure Dedicated Host, Azure VMware Solution, and Azure Virtual Machines with each other all at once[6]. You can also exchange multiple SQL database reservation types including SQL Managed Instances and Elastic Pool with each other. However, you can’t exchange dissimilar reservations. For example, you can’t exchange an Azure Cosmos DB reservation for SQL Database.
You may also exchange a reservation to purchase another reservation of a similar type in a different region. For example, you may exchange a reservation in West US 2 for one that’s in West Europe.
Azure Reservations – deep discounts for all your predictable workloads
Azure reservations are the best cost savings option for your stable and continuously running workloads. A workload is considered stable if its infrastructure requirements are not expected to change during the term of a reservation. Workloads that run for most of the day are likely good candidates for reservations. Azure reservations are available for multiple Azure products, including compute, database and analytics.
Reservations for VMs are also known as virtual machine reserved instances (VM RIs). Along with the deep discounts, these reservations provide the option of greater flexibility via Instance size flexibility[7]. This feature allows the reservation discount to be applied to other VMs in the same VM size group. For example, if you buy a Standard_DS3_v2 VM reservation, you may opt to allow the reservation to apply to other VM sizes in the DSv2 series (e.g., Standard_DS1_v2, Standard_DS2_v2, Standard_DS3_v2 or Standard_DS4_v2). Review this article to learn more about instance size flexibility.
In the future, while instance size flexibility for VMs will remain, exchanges of instance series or regions for Azure Virtual Machine, Azure Dedicated Host and Azure App Service reservations will no longer be supported. Please see this article for more information.
View a list of all supported services, or view reservation pricing in Azure pricing calculator, on the Azure pricing page or by downloading your Azure price list.
Like savings plans, reservations can be configured to make their discounts available to your entire EA billing account or MCA billing profile, or a specific management group, subscription, or resource group. You can change the scope of your reservation at any time.
How to compare savings plans and reservations?
Now that we have explained what savings plans and reservations are, let’s compare and contrast them to see where they differ and how they can help you optimize your cloud computing spending.
Depending on your usage patterns and needs, savings plans and reservations are two options that can help drive cost savings on your infrastructure costs[8]. They can both be combined with Azure Hybrid Benefit to save on licensing costs for Windows Server and SQL Server. However, they also have key differences that you should consider before you choose one or the other.
Reservations
Savings plan
Target
Workloads running continuously in the same region, with no planned changes
Dynamic/evolving workloads running in different regions
Savings compared to pay-as-you-go
Save up to 72%
Save up to 65%
Commitment
Usage of a specific product in a particular region (e.g., D2v4 VM in Japan East)
Hourly amount (e.g., $5/hr.)
Benefit order
Applied first
Applied
Term
1, 3, or 5 years
1 or 3 years
Payment options
Upfront or monthly
Upfront or monthly
Modifications
Exchange reservations1
Trade-in VM, Dedicate Host or App Service reservations for savings plan
Cancel reservations2
No cancellations
1Subject to upcoming changes to reservation exchange policy
2Subject to $50,000 USD in a revolving 12-month period
Examples
In this section, we will present two examples of how to compare Azure reservations with Savings Plan for Compute, based on different scenarios and assumptions. These examples are intended to illustrate the potential savings and trade-offs of each option, as well as the factors that affect the decision. Both examples assume that workloads operate 24 hours a day. The pricing used in the following examples are retrieved from the Azure Pricing calculator as of May 2024.
Example 1: Reservations
In this example, we have workloads spread across two regions – East US and West US. The workloads are powered by 2 Virtual Machine instances and 2 Azure SQL Databases in each region, and there are no planned changes to these resources. Purchasing reservations for a 3-year term will achieve the highest savings.
Reservations Estimate
Service type
Region
Description
PAYG monthly cost
Discount
3 years
Monthly cost
Monthly savings
Virtual machines
East US
4 D2 v3 (2 vCPUs, 8 GB RAM) (3 year reserved), Windows (License included), OS Only; 0 managed disks – S4; Inter Region transfer type, 5 GB outbound data transfer from East US to West US
$548.96
31%
$376.18
$172.78
Virtual machines
West US
4 D2 v3 (2 vCPUs, 8 GB RAM) (3 year reserved), Windows (License included), OS Only; 0 managed disks – S4; Inter Region transfer type, 5 GB outbound data transfer from West US to East US
$610.28
34%
$416.86
$193.42
Azure SQL database
East US
Single Database, vCore, General Purpose, Provisioned, Standard-series (Gen 5), Locally Redundant, 2 – 2 vCore instance(s), 3 year reserved, 32 GB Storage, RA-GRS Backup Storage Redundancy, 0 GB Point-In-Time Restore, 0 x 5 GB Long Term Retention
$745.94
35%
$501.46
$244.48
Azure SQL database
West US
Single Database, vCore, General Purpose, Provisioned, Standard-series (Gen 5), Locally Redundant, 2 – 2 vCore instance(s), 3 year reserved, 32 GB Storage, RA-GRS Backup Storage Redundancy, 0 GB Point-In-Time Restore, 0 x 5 GB Long Term Retention
$792.30
35%
$523.38
$268.93
Total
$2,697.49
$1,817.88
$879.61
Disclaimer
All prices shown are in United States Dollars (USD). This is a summary estimate, not a quote. For up-to-date pricing information please visit https://azure.microsoft.com/pricing/calculator.
This estimate was created at 5/21/2024 8:52:39 AM UTC.
We need a total of 4 reservations because reservations are bound to a single region, and we have compute and database services within two different regions. By having 4 reservations, we can achieve a monthly savings of $879.61, which results in savings of $31,665.96 over our 3-year term.
Example 2: Savings Plans for Compute
In this scenario, our customer, Fabrikam, has their operations set up across three key regions: West US, West Europe, and East Asia. Each region has a set of resources dedicated to running their critical workloads, ensuring continuous operations.
The workloads are designed to run for 8 hours in each region, following the local business hours, which allows Fabrikam to take advantage of the lower cost associated with off-peak hours in each region. This approach not only optimizes resource utilization but also aligns with the “follow the sun” model, providing seamless service to their global customer base.
By adopting the Savings Plans for Compute, Fabrikam commits to a consistent amount of compute usage (measured in $/hour) for a 1 or 3-year period. In return, they receive a significant discount compared to pay-as-you-go rates. The following example illustrates how Fabrikam can leverage Savings Plans for Compute covering their App Services running in West US, West Europe, and East Asia.
Savings Plan Estimate
Service type
Region
Description
PAYG 8 hours/day
Discount 3 years
Monthly cost 8 hours/day
Monthly savings
Hourly commitment
App Service
West US
Premium V3 Tier; 1 P3V3 (8 Core(s), 32 GB RAM, 250 GB Storage); 3 year savings plan; Windows OS; 0 SNI SSL Connections; 0 IP SSL Connections; 0 Custom Domains; 0 Standard SLL Certificates; 0 Wildcard SSL Certificates
$42.88
24%
$32.80
$10.08
$1.025
App Service
West Europe
Premium V3 Tier; 1 P3V3 (8 Core(s), 32 GB RAM, 250 GB Storage); 3 year savings plan; Windows OS; 0 SNI SSL Connections; 0 IP SSL Connections; 0 Custom Domains; 0 Standard SLL Certificates; 0 Wildcard SSL Certificates
$43.26
24%
$33.02
$10.24
$1.032
App Service
East Asia
Premium V3 Tier; 1 P3V3 (8 Core(s), 32 GB RAM, 250 GB Storage); 3 year savings plan; Windows OS; 0 SNI SSL Connections; 0 IP SSL Connections; 0 Custom Domains; 0 Standard SLL Certificates; 0 Wildcard SSL Certificates
$48.26
26%
$35.74
$12.51
$1.117
Total
$3,066.00
$2,317.01
$32.83
$1.025
Disclaimer
All prices shown are in United States Dollar (USD). This is a summary estimate, not a quote. For up-to-date pricing information please visit https://azure.microsoft.com/pricing/calculator.
This estimate was created at 6/19/2024 12:22:34 PM UTC.
Our example shows that pay-as-you-go prices and regional discounts differ slightly. The West US region generally offers the lowest app service rates, while East Asia has a higher discount of 26%, compared to 24% elsewhere. Our workload operates for 8 hours per region, rotating the savings benefit as we transition from one region to another. It’s best to opt for a single, minimum-hourly-commitment savings plan to avoid underuse. This results in selecting a $1.205 hourly rate for our Compute Savings Plan. Manual calculations are unnecessary; Azure Advisor will recommend a suitable baseline to cover your needs, and during purchase, you’ll see an hourly commitment suggestion based on past data.
This example illustrates the financial benefits and operational efficiency that can be achieved through strategic planning and the utilization of Savings Plans for Compute. It demonstrates how a “follow the sun” model can be effectively implemented to maximize savings while maintaining continuous global operations.
How to utilize both savings plans and reservations
Leverage Azure Advisor recommendations in the following order
Right size/shutdown VMs
Exchange any underutilized previously purchased reservations
Trade-in VM, Dedicated Host & App Service reservation for a savings plan
Purchase reservations based on recommendations
Purchase savings plan based on recommendations
How to consider the Microsoft Azure Consumption Commitment (MACC) discount?
Many Enterprise Customers might have an existing Microsoft Azure Consumption Commitment (MACC) discount[9]. This is a discount that is based on your commitment to spend a certain amount on Azure services for a specified time, usually one or three years. The MACC discount applies to the pay-as-you-go rates of your eligible Azure services, and it can vary depending on your commitment level and contract terms. However, the MACC discount does not stack with the savings plan or reservation discounts. This means that if you purchase a savings plan or a reservation, you will not get the MACC discount on top of the savings plan or reservation discount. Instead, you will get the higher of the two discounts.
Summary
In this article, we have compared and contrasted Azure savings plans for compute and reservations, two options that can help you save money on your costs in Azure. Here are the main points to remember:
Savings plans provide a flexible and global way to save on the infrastructure costs of compute services. They automatically apply to any eligible compute service, instance type, or region, and can be changed as your needs evolve. You can share your savings plan across your entire billing scope and change the scope at any time. While it is possible to increase your commitment at any time, it cannot be decreased or canceled before the end of the term. Savings plans offer up to 65 percent in savings and can be combined with Azure Hybrid Benefit for additional savings on licensing costs.
Reservations provide a predictable and stable way to save on the infrastructure costs of your service. You can reserve a specific service, instance type, and region by paying the upfront cost. Reservations can be canceled or exchanged at any time, subject to a limit of $50,000 USD per 12-month rolling window. You can also modify your reservation by changing the instance size within the same family or the region within the same geographic area. However, exchanging a reservation for a non-compute service is only possible under certain conditions. With reservations, you can save up to 72 percent and combine them with Azure Hybrid Benefit for additional savings on licensing costs.
Reservations cover more services than just compute, but they are less flexible than savings plans, since they are tied to a specific service, instance type, and region. Reservations are ideal for workloads that are stable and predictable, and have no planned changes.
A reserved instance is a type of reservation that targets virtual machines. You can reserve a specific VM size and region, and get a discount on your VM costs. Reserved instances are ideal for workloads that run continuously or for long periods of time, such as web servers, databases, or batch processing.
Savings plans and reservations can be combined to maximize savings and flexibility. Reservations can be used for stable and predictable workloads, while savings plans are ideal for dynamic and evolving workloads. Azure automatically applies the reservation discount first, followed by the savings plan discount for any remaining usage until the savings plan commitment is fully utilized. Any usage not covered by either option is charged at the pay-as-you-go rate. Different types of reservations and savings plans can be mixed and matched depending on the services, instance types, and regions used.
You should also consider the Microsoft Azure Consumption Commitment (MACC) discount, if you have one, when you compare the savings plan or reservation options. The MACC discount applies to the pay-as-you-go rates of your eligible Azure services, and it can vary depending on your commitment level and contract terms. However, the MACC discount does not stack with the savings plan or reservation discounts. You will get the higher of the two discounts, if you purchase a savings plan or a reservation.
We hope that this article has helped you to understand how to choose between Azure savings plans for compute and reservations, and how to combine them to optimize your cloud computing spending. If you have any questions, feedback, or experiences to share, please feel free to leave a comment below. We would love to hear from you.
References
[1] What is Azure savings plans for compute? – Microsoft Cost Management | Microsoft Learn
[2] Azure Hybrid Benefit for Windows Server | Microsoft Learn
[3] How an Azure saving plan discount is applied – Microsoft Cost Management | Microsoft Learn
[4] Savings plan scopes – Microsoft Cost Management | Microsoft Learn
[5] What are Azure Reservations? – Microsoft Cost Management | Microsoft Learn
[6] Self-service exchanges and refunds for Azure Reservations – Microsoft Cost Management | Microsoft Learn
[7] Virtual machine size flexibility -Azure Reserved VM Instances – Azure Virtual Machines | Microsoft Learn
[8] Decide between a savings plan and a reservation – Microsoft Cost Management | Microsoft Learn
[9] Track your Microsoft Azure Consumption Commitment (MACC) – Microsoft Cost Management | Microsoft Learn
Microsoft Tech Community – Latest Blogs –Read More
In matlab, although my matrix is full rank, the solution is still incorrect.Ax=b,A(10000*10000),x、b(10000*1)
This is equation solving
this is D matrics
this is J matrics
I want to test
but the result is not good
My ultimate goal is to use the constructed inverse matrix to restore the image, because the deviation in the solution causes the restoration effect not to be very good:
The above picture is restored by me directly using the inverse matrix. The picture below is restored by using the constructed inverse matrix. The inverse matrix is J and the constructed inverse matrix is Dx1.
Thank you guysThis is equation solving
this is D matrics
this is J matrics
I want to test
but the result is not good
My ultimate goal is to use the constructed inverse matrix to restore the image, because the deviation in the solution causes the restoration effect not to be very good:
The above picture is restored by me directly using the inverse matrix. The picture below is restored by using the constructed inverse matrix. The inverse matrix is J and the constructed inverse matrix is Dx1.
Thank you guys This is equation solving
this is D matrics
this is J matrics
I want to test
but the result is not good
My ultimate goal is to use the constructed inverse matrix to restore the image, because the deviation in the solution causes the restoration effect not to be very good:
The above picture is restored by me directly using the inverse matrix. The picture below is restored by using the constructed inverse matrix. The inverse matrix is J and the constructed inverse matrix is Dx1.
Thank you guys matrics, calculation MATLAB Answers — New Questions
Incorrect dimensions for matrix multiplication.
Could anyone help, please with explanation?
V=1+((exp(-0.5*t))*((-0.9)*(cos(1.323*t))-(0.34)*(sin(1.323*t))));
Error using *
Incorrect dimensions for matrix multiplication. Check that the number
of columns in the first matrix matches the number of rows in the
second matrix. To perform elementwise multiplication, use ‘.*’.
Thank you in advance.Could anyone help, please with explanation?
V=1+((exp(-0.5*t))*((-0.9)*(cos(1.323*t))-(0.34)*(sin(1.323*t))));
Error using *
Incorrect dimensions for matrix multiplication. Check that the number
of columns in the first matrix matches the number of rows in the
second matrix. To perform elementwise multiplication, use ‘.*’.
Thank you in advance. Could anyone help, please with explanation?
V=1+((exp(-0.5*t))*((-0.9)*(cos(1.323*t))-(0.34)*(sin(1.323*t))));
Error using *
Incorrect dimensions for matrix multiplication. Check that the number
of columns in the first matrix matches the number of rows in the
second matrix. To perform elementwise multiplication, use ‘.*’.
Thank you in advance. matlab MATLAB Answers — New Questions
how to build one to many and many to many LSTM in matlab?
I don’t know that is possible to build these kind of networks in matlab? If it is possible, can I use these kind of network in simulink?I don’t know that is possible to build these kind of networks in matlab? If it is possible, can I use these kind of network in simulink? I don’t know that is possible to build these kind of networks in matlab? If it is possible, can I use these kind of network in simulink? lstm, one_to_many, many_to_many, recurrent_neural_networks, neural network MATLAB Answers — New Questions
How Do I Create a Purchase Order in Q.B Desktop?
Hi, I need help creating a purchase order in Quick-Books Desktop for my business. I’m relatively new to the software and would appreciate a detailed, step-by-step guide on how to create a purchase order. Specifically, I need to know which menus to navigate, what information is required, and any tips for ensuring the purchase order is accurate and complete. Any additional advice on managing purchase orders in Q.B Desktop would also be greatly appreciated.
Hi, I need help creating a purchase order in Quick-Books Desktop for my business. I’m relatively new to the software and would appreciate a detailed, step-by-step guide on how to create a purchase order. Specifically, I need to know which menus to navigate, what information is required, and any tips for ensuring the purchase order is accurate and complete. Any additional advice on managing purchase orders in Q.B Desktop would also be greatly appreciated. Read More
Problem with Exchange Server 2016 – MSExchange Availability
Hello
We have 2 Exchange Server (DAG with MBS). We always get the Eventid 4002:
Process 836: ProxyWebRequest CrossSite from S-1-5-21-3814888480-1449635806-2613578883-16147 to https://server02.melecs.local:444/ews/exchange.asmx failed. Caller SIDs: NetworkCredentials. The exception returned is Microsoft.Exchange.InfoWorker.Common.Availability.ProxyWebRequestProcessingException: Proxy web request failed. —> System.Net.WebException: The request was aborted: The request was canceled.
at System.Web.Services.Protocols.WebClientAsyncResult.WaitForResponse()
at System.Web.Services.Protocols.WebClientProtocol.EndSend(IAsyncResult asyncResult, Object& internalAsyncState, Stream& responseStream)
at System.Web.Services.Protocols.SoapHttpClientProtocol.EndInvoke(IAsyncResult asyncResult)
at Microsoft.Exchange.InfoWorker.Common.Availability.Proxy.Service.EndGetUserAvailability(IAsyncResult asyncResult)
at Microsoft.Exchange.InfoWorker.Common.Availability.FreeBusyApplication.EndProxyWebRequest(ProxyWebRequest proxyWebRequest, QueryList queryList, IService service, IAsyncResult asyncResult)
at Microsoft.Exchange.InfoWorker.Common.Availability.ProxyWebRequest.EndInvoke(IAsyncResult asyncResult)
at Microsoft.Exchange.InfoWorker.Common.Availability.AsyncWebRequest.EndInvokeWithErrorHandling()
— End of inner exception stack trace —
. Name of the server where exception originated: Server01. LID: 43532. Make sure that the Active Directory site/forest that contain the user’s mailbox has at least one local Exchange 2010 server running the Availability service. Turn up logging for the Availability service and test basic network connectivity.
Do everyone know what I can do to solve this problem?
Thanks
Regards
Andreas
Hello We have 2 Exchange Server (DAG with MBS). We always get the Eventid 4002: Process 836: ProxyWebRequest CrossSite from S-1-5-21-3814888480-1449635806-2613578883-16147 to https://server02.melecs.local:444/ews/exchange.asmx failed. Caller SIDs: NetworkCredentials. The exception returned is Microsoft.Exchange.InfoWorker.Common.Availability.ProxyWebRequestProcessingException: Proxy web request failed. —> System.Net.WebException: The request was aborted: The request was canceled.at System.Web.Services.Protocols.WebClientAsyncResult.WaitForResponse()at System.Web.Services.Protocols.WebClientProtocol.EndSend(IAsyncResult asyncResult, Object& internalAsyncState, Stream& responseStream)at System.Web.Services.Protocols.SoapHttpClientProtocol.EndInvoke(IAsyncResult asyncResult)at Microsoft.Exchange.InfoWorker.Common.Availability.Proxy.Service.EndGetUserAvailability(IAsyncResult asyncResult)at Microsoft.Exchange.InfoWorker.Common.Availability.FreeBusyApplication.EndProxyWebRequest(ProxyWebRequest proxyWebRequest, QueryList queryList, IService service, IAsyncResult asyncResult)at Microsoft.Exchange.InfoWorker.Common.Availability.ProxyWebRequest.EndInvoke(IAsyncResult asyncResult)at Microsoft.Exchange.InfoWorker.Common.Availability.AsyncWebRequest.EndInvokeWithErrorHandling()— End of inner exception stack trace —. Name of the server where exception originated: Server01. LID: 43532. Make sure that the Active Directory site/forest that contain the user’s mailbox has at least one local Exchange 2010 server running the Availability service. Turn up logging for the Availability service and test basic network connectivity. Do everyone know what I can do to solve this problem? ThanksRegardsAndreas Read More