Why the Kf_LMax value is increased beyond its limits. Is their is any logical error Kindly help me out .

1 visualización (últimos 30 días)
Why the Kf_LMax value is increased beyond its limits. Is their is any logical error Kindly help me out .
% Define parameters
Kf_Max = 100; % maximum forward rate
RLC = [0.1, 0.5, 10, 5, 10, 1]; % RLC values
TauKf_ON = -0.01; % TauKf_ON
TauKf_OFF = -0.01; % TauKf_OFF
PhaseTimes = [0, 500, 1000, 2000, 3000, 4000, 5000]; % phase times (each row defines a phase)
% Generate time vector
t = 0:0.01:5000;
% Call the function to compute receptor concentrations and Kf
[ Kf_LMax] = Kf_Cal(Kf_Max, RLC, TauKf_ON, TauKf_OFF, PhaseTimes, t);
% Plotting
figure;
% Plot Kf_LMax
plot(t, Kf_LMax, 'b', 'LineWidth', 1.5);
title('Kf_LMax over Time');
xlabel('Time');
ylabel('Kf_LMax');
grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ Kf_LMax] = Kf_Cal(Kf_Max, RLC, TauKf_ON, TauKf_OFF, PhaseTimes, t)
% Initialize output variables
Kf_LMax = zeros(size(t));
% Calculate Kf_L for each time step
for i = 1:length(t)
Kf_LMax(i) = calculate_kf(t(i), PhaseTimes, Kf_Max, RLC, TauKf_ON, TauKf_OFF);
end
% Nested function for calculating Kf_L based on time
function Kf_L = calculate_kf(t_current, PhaseTimes, Kf_Max, RLC, TauKf_ON, TauKf_OFF)
% Calculate maximum Kf_L based on RLC values using Element wise
% division
Kf_LMax_values = Kf_Max * (RLC ./ (1 + RLC));
% Default Kf_L to the maximum value of the first phase
Kf_L = Kf_LMax_values(1);
% Number of phases
num_phases = numel(RLC);
% Iterate through each phase to determine the current phase based on time
for j = 1:num_phases
T_start = PhaseTimes(j); % Start time of the current phase
if j < num_phases
T_end = PhaseTimes(j + 1); % End time of the current phase
else
T_end = inf; % Handle last phase separately
end
% Check if the current time t_current is within the current phase
if t_current >= T_start && t_current < T_end
if j == 1
% For the first phase, use the maximum value directly
Kf_L = Kf_LMax_values(j);
else
% Time at the end of the previous phase
% prev_end = PhaseTimes(j - 1);
if j < num_phases
% Check RLC conditions and compute Kf_L
if RLC(j - 1) < RLC(j) && RLC(j) > RLC(j + 1)
% Peak condition
Kf_endA = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endA - Kf_LMax_values(j - 1)) *exp(TauKf_OFF * ( t_current - T_start));
elseif RLC(j - 1) < RLC(j) && RLC(j) < RLC(j + 1)
% Increasing RLC condition
Kf_endB = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endB - Kf_LMax_values(j - 1)) *exp(TauKf_OFF * (t_current - T_start));
elseif RLC(j - 1) > RLC(j) && RLC(j) < RLC(j + 1)
% Decreasing RLC condition
Kf_endC = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endC - Kf_LMax_values(j - 1)) * exp(TauKf_OFF * (t_current - T_start ));
elseif RLC(j - 1) > RLC(j) && RLC(j) >= RLC(j + 1)
% Flat or decreasing RLC condition
Kf_endD = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endD - Kf_LMax_values(j - 1)) * exp(TauKf_OFF * (t_current - T_start ));
end
else
% % % Handling for the last phase
if RLC(j - 1) < RLC(j)
Kf_end1 = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start) Kf_L = Kf_LMax_values(j) + (Kf_end1 - Kf_LMax_values(j - 1)) * exp(TauKf_OFF * (t_current - T_start));
elseif RLC(j - 1) > RLC(j)
Kf_end2 = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_end2 - Kf_LMax_values(j - 1)) * exp(TauKf_OFF * (t_current - T_start));
end
end
end
return; % Exit the function after finding the correct phase
end
end
end
end
Expected responses:

Respuestas (3)

Sam Chak
Sam Chak el 10 de Sept. de 2024
I am unfamiliar with your equation, but it appears that you did not "mathematically" impose the desired upper limit (100) on the 'Kf_L' variable. I selected a specific time at (where the peak approximately occurs) to compute the instantaneous value of 'Kf_L'​, which depends on the incremental computations of 'Kf_endA' and 'Kf_L'. The returned value is 102.6787, which clearly exceeds the desired upper limit.
In my opinion, a time-varying parameter like 'Kf_L'​, if governed by an exponentially decaying dynamic law, should be best formulated as a differential equation, and then solved either analytically or numerically.
% Define parameters
Kf_Max = 100; % maximum forward rate
RLC = [0.1, 0.5, 10, 5, 10, 1]; % RLC values
TauKf_ON = -0.01; % TauKf_ON
TauKf_OFF = -0.01; % TauKf_OFF
PhaseTimes = [0, 500, 1000, 2000, 3000, 4000, 5000]; % phase times (each row defines a phase)
% Generate time vector
% t = 0:0.01:5000;
t = 1125;
% Call the function to compute receptor concentrations and Kf
[Kf_LMax] = Kf_Cal(Kf_Max, RLC, TauKf_ON, TauKf_OFF, PhaseTimes, t)
Kf_LMax_values = 1x6
9.0909 33.3333 90.9091 83.3333 90.9091 50.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Kf_endA = 74.4134
Kf_L = 102.6787
Kf_LMax = 102.6787
%% TEST
% Kf_endA = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON*(t_current - T_start))
Kf_endA = 90.9091 - (90.9091 - 33.3333 )*exp(-0.01 *(1125 - 1000))
Kf_endA = 74.4134
% Kf_L = Kf_LMax_values(j) + (Kf_endA - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start));
Kf_L = 90.9091 + (74.4134 - 33.3333 )*exp(-0.01 *(1125 - 1000))
Kf_L = 102.6787
% Plotting
% figure;
% % Plot Kf_LMax
% plot(t, Kf_LMax, 'bo--', 'LineWidth', 1.5);
% title('Kf_LMax over Time');
% xlabel('Time');
% ylabel('Kf_LMax');
% grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Kf_LMax] = Kf_Cal(Kf_Max, RLC, TauKf_ON, TauKf_OFF, PhaseTimes, t)
% Initialize output variables
Kf_LMax = zeros(size(t));
% Calculate Kf_L for each time step
for i = 1:length(t)
Kf_LMax(i) = calculate_kf(t(i), PhaseTimes, Kf_Max, RLC, TauKf_ON, TauKf_OFF);
end
% Nested function for calculating Kf_L based on time
function Kf_L = calculate_kf(t_current, PhaseTimes, Kf_Max, RLC, TauKf_ON, TauKf_OFF)
% Calculate maximum Kf_L based on RLC values using Element wise
% division
Kf_LMax_values = Kf_Max * (RLC ./ (1 + RLC))
% Default Kf_L to the maximum value of the first phase
Kf_L = Kf_LMax_values(1);
% Number of phases
num_phases = numel(RLC);
% Iterate through each phase to determine the current phase based on time
for j = 1:num_phases
T_start = PhaseTimes(j); % Start time of the current phase
if j < num_phases
T_end = PhaseTimes(j + 1); % End time of the current phase
else
T_end = inf; % Handle last phase separately
end
% Check if the current time t_current is within the current phase
if t_current >= T_start && t_current < T_end
if j == 1
% For the first phase, use the maximum value directly
Kf_L = Kf_LMax_values(j);
else
% Time at the end of the previous phase
% prev_end = PhaseTimes(j - 1);
if j < num_phases
% Check RLC conditions and compute Kf_L
if RLC(j - 1) < RLC(j) && RLC(j) > RLC(j + 1)
% Peak condition
Kf_endA = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON * (t_current - T_start))
Kf_L = Kf_LMax_values(j) + (Kf_endA - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start))
elseif RLC(j - 1) < RLC(j) && RLC(j) < RLC(j + 1)
% Increasing RLC condition
Kf_endB = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endB - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start));
elseif RLC(j - 1) > RLC(j) && RLC(j) < RLC(j + 1)
% Decreasing RLC condition
Kf_endC = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endC - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start ));
elseif RLC(j - 1) > RLC(j) && RLC(j) >= RLC(j + 1)
% Flat or decreasing RLC condition
Kf_endD = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endD - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start ));
end
else
% % % Handling for the last phase
if RLC(j - 1) < RLC(j)
Kf_end1 = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_end1 - Kf_LMax_values(j - 1)) * exp(TauKf_OFF * (t_current - T_start));
elseif RLC(j - 1) > RLC(j)
Kf_end2 = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_end2 - Kf_LMax_values(j - 1)) * exp(TauKf_OFF * (t_current - T_start));
end
end
end
return; % Exit the function after finding the correct phase
end
end
end
end
  1 comentario
Ehtisham
Ehtisham el 10 de Sept. de 2024
@Sam Chak Thanks for your replying .I do not want to impose the Kf_L = 100 i just want i should gives us the calculation till the Kf maximum value define in the initial condition

Iniciar sesión para comentar.


Sam Chak
Sam Chak el 10 de Sept. de 2024
The previous answer attempts to provide a logical explanation for why the 'Kf_L'​ variable exceeds the desired upper limit (100). Are you, by any chance, looking to impose a hard limit on the 'Kf_L' variable as plotted below?
% Define parameters
Kf_Max = 100; % maximum forward rate
RLC = [0.1, 0.5, 10, 5, 10, 1]; % RLC values
TauKf_ON = -0.01; % TauKf_ON
TauKf_OFF = -0.01; % TauKf_OFF
PhaseTimes = [0, 500, 1000, 2000, 3000, 4000, 5000]; % phase times (each row defines a phase)
% Generate time vector
t = 0:0.01:5000;
% Call the function to compute receptor concentrations and Kf
[Kf_LMax] = Kf_Cal(Kf_Max, RLC, TauKf_ON, TauKf_OFF, PhaseTimes, t);
% Plotting
figure;
% Plot Kf_LMax
plot(t, Kf_LMax, '.--', 'LineWidth', 1.5); ylim([0 110])
title('Kf_LMax over Time');
xlabel('Time');
ylabel('Kf_LMax');
grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Kf_LMax] = Kf_Cal(Kf_Max, RLC, TauKf_ON, TauKf_OFF, PhaseTimes, t)
% Initialize output variables
Kf_LMax = zeros(size(t));
% Calculate Kf_L for each time step
for i = 1:length(t)
Kf_LMax(i) = calculate_kf(t(i), PhaseTimes, Kf_Max, RLC, TauKf_ON, TauKf_OFF);
end
% Nested function for calculating Kf_L based on time
function Kf_L = calculate_kf(t_current, PhaseTimes, Kf_Max, RLC, TauKf_ON, TauKf_OFF)
% Calculate maximum Kf_L based on RLC values using Element wise
% division
Kf_LMax_values = Kf_Max * (RLC ./ (1 + RLC));
% Default Kf_L to the maximum value of the first phase
Kf_L = Kf_LMax_values(1);
% Number of phases
num_phases = numel(RLC);
% Iterate through each phase to determine the current phase based on time
for j = 1:num_phases
T_start = PhaseTimes(j); % Start time of the current phase
if j < num_phases
T_end = PhaseTimes(j + 1); % End time of the current phase
else
T_end = inf; % Handle last phase separately
end
% Check if the current time t_current is within the current phase
if t_current >= T_start && t_current < T_end
if j == 1
% For the first phase, use the maximum value directly
Kf_L = Kf_LMax_values(j);
else
% Time at the end of the previous phase
% prev_end = PhaseTimes(j - 1);
if j < num_phases
% Check RLC conditions and compute Kf_L
if RLC(j - 1) < RLC(j) && RLC(j) > RLC(j + 1)
% Peak condition
Kf_endA = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endA - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start));
elseif RLC(j - 1) < RLC(j) && RLC(j) < RLC(j + 1)
% Increasing RLC condition
Kf_endB = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endB - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start));
elseif RLC(j - 1) > RLC(j) && RLC(j) < RLC(j + 1)
% Decreasing RLC condition
Kf_endC = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endC - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start ));
elseif RLC(j - 1) > RLC(j) && RLC(j) >= RLC(j + 1)
% Flat or decreasing RLC condition
Kf_endD = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1))*exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_endD - Kf_LMax_values(j - 1))*exp(TauKf_OFF*(t_current - T_start ));
end
else
% % % Handling for the last phase
if RLC(j - 1) < RLC(j)
Kf_end1 = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_end1 - Kf_LMax_values(j - 1)) * exp(TauKf_OFF * (t_current - T_start));
elseif RLC(j - 1) > RLC(j)
Kf_end2 = Kf_LMax_values(j) - (Kf_LMax_values(j) - Kf_LMax_values(j - 1)) * exp(TauKf_ON * (t_current - T_start));
Kf_L = Kf_LMax_values(j) + (Kf_end2 - Kf_LMax_values(j - 1)) * exp(TauKf_OFF * (t_current - T_start));
end
end
end
Kf_L = min(Kf_L, Kf_Max); % Sam: imposing a hard limit Kf_Max
return; % Exit the function after finding the correct phase
end
end
end
end
  7 comentarios
Ehtisham
Ehtisham el 11 de Sept. de 2024
Editada: Sam Chak el 11 de Sept. de 2024
here the skecth of active and non active receptor and reaction rates @Sam Chak
Sam Chak
Sam Chak el 11 de Sept. de 2024
I’m not familiar with the concentration system. However, since this is a super simple coupled first-order system, you can probably run the simulation phase by phase—integrate, stop, and then integrate again until the next phase.
Kf_L = 1.5e-3;
Kb = Kf_L*9;
tspan = [0, 500];
y0 = [100; 0];
[t, y] = ode45(@(t, y) ode_LR(t, y, Kf_L, Kb), tspan, y0);
tl = tiledlayout(2, 1, 'TileSpacing', 'Compact');
nexttile
plot(t, y(:,1)), grid on
title('Non-Active Receptor concentration')
nexttile
plot(t, y(:,2)), grid on
title('Active Receptor concentration')
xlabel(tl, 'Time')
function dydt = ode_LR(t, y, Kf_L, Kb)
% Non_Active_Receptor_concentration = y(1);
% Active_Receptor_concentration = y(2);
dy1 = - Kf_L*y(1) + Kb*y(2);
dy2 = Kf_L*y(1) - Kb*y(2);
dydt = [dy1;
dy2];
end

Iniciar sesión para comentar.


Sam Chak
Sam Chak el 11 de Sept. de 2024
If the gains and stay constant or vary very slowly during each phase, then you can consider applying the following analytical solutions by making the appropriate substitutions for the gains and initial conditions at each phase.
syms x(t) y(t) K1 K2 C1 C2
% x is the concentration of Non-Active Receptor
% y is the concentration of Active Receptor
% K1 is Kf_L
% K2 is Kb
% C1 is initial condition of x
% C2 is initial condition of y
eqns = [diff(x,t) == - K1*x + K2*y,
diff(y,t) == K1*x - K2*y];
cond = [x(0)==C1,
y(0)==C2];
[xSol(t), ySol(t)] = dsolve(eqns, cond)
xSol(t) = 
ySol(t) = 

Categorías

Más información sobre Plot Customization en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by