I have a function called "compute_ode" that computes the derivative dC/dt for the differential equation model ODE: dC/dt = 0.1*(C-20)*(23-C)*(C-26) +k. The function will be assessed by running the code:
[t,c]=ode45(@(t,c) compute_ode(t,c,k),t_range,init_cond);
for chosen values of k, t_range, and init_cond. Thus, the function should conform to the standards required by the MATLAB function ode45.
The function looks like this:
function dcdt = compute_ode(t,c,k)
dcdt = 0.1 * (c-20) * (23-c) * (c-26) + k;
And I am running it with:
[t,c]=ode45(@(t,c) compute_ode(t,c,k),t_range,init_cond);
xlabel('time','FontSize',18)
ylabel('c(t)','FontSize',18)
Then I wrote a function called "compute_states" that takes as input a value for k and then returns as output all real-valued steady states for the differential equation. The function will be assessed by running
for different values of k. Looking like this:
function vectCeq = compute_states(k)
coeffs = [-0.1, 6.9, -157.8, 1196 + k];
all_roots = roots(coeffs);
real_roots = all_roots(imag(all_roots) == 0);
Now I need to write a function called "compute_time_to_steady" that solves the differential equation and returns the earliest time (t) it takes to get within 1% error of the steady state value. In other words, if the computed value is y(t) at time t and the steady state is y* then the stopping criterion is abs(y(t)-y*)/y*<0.001 and the code returns the first time t that satisfies this criterion. Importantly, the function assumes a steady state exists and that the stopping criterion should be reached before t=100,000. If the stopping criterion is not satisfied by t=100,000 then the code should return -1, i.e. csol=-1. The function will be assessed by running the code:
csol = compute_time_to_steady(init_cond,k,steady_state);
for many different values of init_cond (a scalar), k (a scalar), and steady_state (a scalar).
Any suggestion on how to solve this? I have got some guisng saying that "find " might be useful.
Thanks in advance!