Solving differential equation - where is my mistake in my code?
2 views (last 30 days)
Show older comments
Zeynep Toprak
on 23 Dec 2020
Commented: Zeynep Toprak
on 23 Dec 2020
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/469517/image.png)
function HW_3_Exercise_11_ode_solver()
%Firstly define the given parameters
beta = 0.8; % Maximal expression rate
alpha =0.6; % Degredation rate
K = 0.25; % Activation coefficient
n = 4; % a constant
C0 = 0.1; % Initial concentration at time 0,
[tvals1,cvals1] = ode45(@protein_eqn,[0, 15],C0);
C1 = 0.2; % Another Initial concentration
[tvals2,cvals2] = ode45(@protein_eqn,[0, 15],C1);
figure3 = figure;
axes('Parent',figure3,'FontSize',12);
box('on');
hold('all');
plot(tvals1,cvals1);
hold on
plot(tvals2,cvals2);
title({'Solution to problem #5'},'FontSize',14);
xlabel({'{Time (sec)}'},'FontSize',14,'FontName','Times New Roman');
ylabel({'% Concentration (mols/m^3)'},'FontSize',14,'FontName','Times New Roman');
% Define the function
function dcdt = protein_eqn (C)
dcdt = beta*(C/K)^n/(1+(C/K)^n)- alpha*C;
end
end
But when I run, I obtain the error
Where is my mistake? I cannot handle it? Please le me know my mistake. Thanks
0 Comments
Accepted Answer
Walter Roberson
on 23 Dec 2020
ode45() always passes at least two parameters to the ode function: current time, and the boundary conditions.
You are not required to use either of them in your code, but you must accept them:
function dcdt = protein_eqn(~,C)
More Answers (0)
See Also
Categories
Find more on Assembly in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!