Compute steady states as a funciton of k, ODE

4 Ansichten (letzte 30 Tage)
Erik Eriksson
Erik Eriksson am 16 Nov. 2023
Kommentiert: Sam Chak am 30 Mai 2024
I will write 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 ODE. The function will be assessed by running "Ceq = compute_states(k)" for many different values of k. I also want to be sure to filter out any complex-valued steady states. I know that "roots" and "imag" might be helpful.
Input: a scalar for k
Output: a vector of steady states, where the lenght of the vector is the number of all real-valued steady states.
ODE: dC/dt = 0.1*(C-20)*(23-C)*(C-26) +k
What I have so far:
Function:
function vectCeq = compute_states(k)
% note that vectCeq is a vector of all real-valued steady states
end
Code to call my function:
k=0; % try for different values of k
vectCeq = compute_states(k)

Antworten (1)

Anurag
Anurag am 24 Nov. 2023
Hi Erik,
I understand that you need to compute all real valued steady states of given ordinary differential equation. For that you need to set the right-hand side of the equation to zero and solve for “C”.
Here is an example code snippet that you can refer to:
function vectCeq = compute_states(k)
% Define the polynomial coefficients (using coeffs of the equation you
% have written)
coefficients = [0.1,6.9,145k,520];
% Find the roots of the polynomial equation
roots_eq = roots(coefficients);
% Filter out complex roots and keep only real roots
real_roots = roots_eq(imag(roots_eq) == 0);
% Remove duplicate roots (if any)
vectCeq = unique(real_roots);
% Display the results
disp(['For k = ', num2str(k), ', real-valued steady states:']);
disp(vectCeq);
end
k = 0; % or any other value
vectCeq = compute_states(k);
This function calculates the real-valued steady states for the given value of k and displays the results.
Documentation link for the function used:
Hope this helps!
Regards,
Anurag
  2 Kommentare
Tommy
Tommy am 6 Apr. 2024
May I ask how you got those coefficients (Line 4)? I'm not getting the same
Sam Chak
Sam Chak am 30 Mai 2024
If @Anurag's solution was what you have been seeking in the last few days, please consider clicking 'Accept' ✔ on the answer to close the issue.
Hi @Tommy,
Those coefficients are derived from the manually solved "expanded form" of the cubic polynomial.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by