Compute steady states as a funciton of k, ODE

조회 수: 4 (최근 30일)
Erik Eriksson
Erik Eriksson 2023년 11월 16일
댓글: Sam Chak 2024년 5월 30일
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)

답변 (1개)

Anurag
Anurag 2023년 11월 24일
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
Tommy
Tommy 2024년 4월 6일
May I ask how you got those coefficients (Line 4)? I'm not getting the same
Sam Chak
Sam Chak 2024년 5월 30일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by