Hi i am working with ODE45 and i have a issue that it noi t give us a variables in the workspace and also guíve a bump in the downward phase kindlydo guide me what i have to
3 views (last 30 days)
Show older comments
Hi i am working with ODE45 and i have a issue that it noi t give us a variables in the workspace and also guíve a bump in the downward phase kindlydo guide me what i have to
function Phase_1LIGAND_INTERACTION()
% Parameters
timespan = 0:0.01:100; % Time vector
Receptor_concentration = 100; % Concentration of Receptor
% Initial conditions
C_LigandReceptor_0 = 0; % Initial concentration of complex of ligand and receptor
% Time-dependent forward reaction rate constants (anonymous functions)
Kf1t_start = 5; % Start time of receptor pulse
Kf1t_end = 20; % Duration of receptor pulse
Kf1Max_rate = 200;
Kf1Min_rate = 1;
Kf1growth = -0.1;
% Time-dependent backward reaction rate constants (anonymous functions)
Kb1t_start =5; % Start time of Complex pulse
Kb1t_end = 20; % Duration of Complex pulse
Kb1Max_rate = 20;
Kb1Min_rate = 10;
Kb1growth = -1;
kf_1 = @(t) calculate_kf(t, Kf1t_start, Kf1t_end, Kf1Max_rate, Kf1Min_rate, Kf1growth );
kb_1 = @(t) calculate_kb(t, Kb1t_start, Kb1t_end, Kb1Max_rate, Kb1Min_rate, Kb1growth);
% Solving the ODE system
[t, y] = ode45(@(t, y) ode_LR(t, y, kf_1, kb_1), timespan, [Receptor_concentration; C_LigandReceptor_0]);
% Extract the concentrations
receptor_concentration = y(:, 1);
ligand_Receptor_concentration = y(:, 2); % Now this represents the ligand-receptor complex concentration
% Calculate kf and kb values at each time point
kf_values = zeros(size(t));
kb_values = zeros(size(t));
kf_growth_values = zeros(size(t));
kb_growth_values = zeros(size(t));
for i = 1:length(t)
kf_values(i) = kf_1(t(i));
kb_values(i) = kb_1(t(i));
kf_growth_values(i) = Kf1growth;
kb_growth_values(i) = Kb1growth;
end
% Create a table for the data
data_table = table(t, kf_values, kb_values, kf_growth_values, kb_growth_values, timespan', ligand_Receptor_concentration, receptor_concentration, ...
'VariableNames', {'Time', 'kf', 'kb', 'kf_growth', 'kb_growth', 'TimeSpan', 'Ligand_Receptor_Concentration', 'Receptor_Concentration'});
% Write the data table to a CSV file
csv_filename = 'interaction_data.csv';
writetable(data_table, csv_filename);
% ...
% Plotting the results
figure;
plot(t, receptor_concentration, '-o', 'LineWidth', 2);
hold on;
plot(t, kf_1(t), '-', 'LineWidth', 2);
hold on;
plot(t, kb_1(t), 'o:', 'LineWidth', 3);
hold on;
plot(t, ligand_Receptor_concentration, '-k', 'LineWidth', 3);
hold on;
xlabel('Time');
ylabel('Concentration');
legend('Receptor', 'kf', 'kb' ,'Activated Receptor (Complex)');
end
function kf_1 = calculate_kf(t, Kf1t_start, Kf1t_end, Kf1Max_rate, Kf1Min_rate, Kf1growth )
kf_1 = zeros(size(t));
for i = 1:length(t)
if t(i) < Kf1t_start
kf_1(i) = Kf1Min_rate;
elseif t(i) >= Kf1t_start && t(i) < Kf1t_end
kf_1(i) = Kf1Max_rate - (Kf1Max_rate - Kf1Min_rate) * exp(Kf1growth * (t(i) - Kf1t_start));
else
kf_end = Kf1Max_rate - (Kf1Max_rate - Kf1Min_rate) * exp(Kf1growth * (Kf1t_end - Kf1t_start));
kf_1(i) = Kf1Min_rate + ( kf_end - Kf1Min_rate) * exp(Kf1growth * (t(i) - Kf1t_end));
end
end
end
function kb_1 = calculate_kb(t, Kb1t_start, Kb1t_end, Kb1Max_rate, Kb1Min_rate, Kb1growth)
kb_1 = zeros(size(t));
for i = 1:length(t)
if t(i) < Kb1t_start
kb_1(i) = Kb1Min_rate;
elseif t(i) >= Kb1t_start && t(i) < Kb1t_end
kb_1(i) = Kb1Max_rate - (Kb1Max_rate - Kb1Min_rate) * exp(Kb1growth * (t(i) - Kb1t_start));
else
kb_end = Kb1Max_rate - (Kb1Max_rate - Kb1Min_rate) * exp(Kb1growth * (Kb1t_end - Kb1t_start));
kb_1(i) = Kb1Min_rate + ( kb_end - Kb1Min_rate) * exp(Kb1growth * (t(i) - Kb1t_end));
end
end
end
function dydt = ode_LR(t, y, kf_1, kb_1)
% Unpack the concentrations
Receptor_concentration = y(1);
C_LigandReceptor = y(2);
% Define the ODE system
dReceptor_dt = -kf_1(t) * Receptor_concentration + kb_1(t) * C_LigandReceptor;
d_CLigandReceptor_dt = kf_1(t) * Receptor_concentration - kb_1(t) * C_LigandReceptor;
% Pack the derivatives into a column vector
dydt = [dReceptor_dt; d_CLigandReceptor_dt];
end
1 Comment
Dyuman Joshi
on 25 Sep 2023
Convert the function Phase_1LIGAND_INTERACTION to a script and then run the code.
Answers (1)
Abderrahim. B
on 25 Sep 2023
Edited: Abderrahim. B
on 25 Sep 2023
Hi!
Functions do not use the base workspace. Every function has its own function workspace. Read more here.
Use assignin function and set the first input argument to 'base' to send variables in a function to the base workspace.
Nothe that there might be other ways to do this.
hope this helps
Abderrahim
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!