이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Mismatched Stability check.
조회 수: 8 (최근 30일)
이전 댓글 표시
I have system of two equations. I solved the model - variable k and t for each value of parameter m, between 0 and 1, and checked for stability of solution. I got all solution as stable
% Define the equations as anonymous functions
eq1 = @(vars, m) (sqrt(vars(1))/sqrt(1-vars(1))) + ((vars(2)*(2*(m^3) + vars(2)^3 - 3*vars(2)*((m+1)^2))^2)/(6*vars(2) - 3*((m-vars(2))^2)) + ((m-vars(2))^2)*(m+2*vars(2))*(m/(3*vars(2)) + 2/3)) / ((m^3 - (vars(2)^2)*(3*m+3) + 2*(vars(2)^3))*(m/(3*vars(2)) - (2*m+vars(2))/(3*(2*vars(2)-((m-vars(2))^2))) + 2/3) - vars(2)*((m-vars(2))^2)*(2*m+vars(2))*((2*m/3) + vars(2)/3));
eq2 = @(vars, m) vars(2) - ((sqrt(vars(1))/sqrt(1-vars(1)))*(((m/vars(2))+2)/3) - (1/3)*(2 + (m/vars(2)) + ((2*m+vars(2))/(((m-vars(2))^2)-2*vars(2))))) / ((sqrt(vars(1))/sqrt(1-vars(1)))*(2*(m^3) - 3*((1+m)^2)*vars(2) + vars(2)^3)/(3*(((m-vars(2))^2)-2*vars(2))) - ((2*m+vars(2))/3));
% Range of m values
m_values = linspace(0, 1, 100); % 100 values of m between 0 and 1
% Preallocate arrays to store solutions
k_solutions = zeros(size(m_values));
t_solutions = zeros(size(m_values));
stabilities = cell(size(m_values));
% Loop over m values and solve the system of equations for each m
for i = 1:length(m_values)
m = m_values(i);
% System of equations for current m
system_of_equations = @(vars) [eq1(vars, m); eq2(vars, m)];
% Initial guess for [k, t]
initial_guess = [0.75, 1.5];
% Solve the system of equations using fsolve
options = optimoptions('fsolve', 'Display', 'off');
solution = fsolve(system_of_equations, initial_guess, options);
% Store solutions if they meet the criteria
k_solution = solution(1);
t_solution = solution(2);
if k_solution > 0.5 && k_solution < 1 && t_solution > 0
k_solutions(i) = k_solution;
t_solutions(i) = t_solution;
% Compute the Jacobian matrix
J = [diff(eq1([k_solution, t_solution], m), 1, 1), diff(eq1([k_solution, t_solution], m), 1, 2);
diff(eq2([k_solution, t_solution], m), 1, 1), diff(eq2([k_solution, t_solution], m), 1, 2)]
% Calculate eigenvalues of the Jacobian matrix
eigenvalues = eig(J);
% Analyze stability
if all(real(eigenvalues) < 0)
stabilities{i} = 'Stable';
elseif all(real(eigenvalues) == 0)
% Use center manifold method for stability analysis
% Modify this part with your center manifold method implementation
stabilities{i} = 'Center manifold method';
elseif any(real(eigenvalues) > 0)
stabilities{i} = 'Unstable';
end
else
k_solutions(i) = NaN;
t_solutions(i) = NaN;
stabilities{i} = 'NaN';
end
end
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
J =
[]
% Display solutions and stabilities
disp('Solutions for each m:');
Solutions for each m:
for i = 1:length(m_values)
fprintf('m = %.2f, k = %.4f, t = %.4f, Stability = %s\n', m_values(i), k_solutions(i), t_solutions(i), stabilities{i});
end
m = 0.00, k = 0.8968, t = 1.3405, Stability = Stable
m = 0.01, k = 0.8900, t = 1.3562, Stability = Stable
m = 0.02, k = 0.8831, t = 1.3715, Stability = Stable
m = 0.03, k = 0.8762, t = 1.3864, Stability = Stable
m = 0.04, k = 0.8693, t = 1.4010, Stability = Stable
m = 0.05, k = 0.8624, t = 1.4154, Stability = Stable
m = 0.06, k = 0.8556, t = 1.4294, Stability = Stable
m = 0.07, k = 0.8488, t = 1.4432, Stability = Stable
m = 0.08, k = 0.8420, t = 1.4569, Stability = Stable
m = 0.09, k = 0.8354, t = 1.4703, Stability = Stable
m = 0.10, k = 0.8288, t = 1.4836, Stability = Stable
m = 0.11, k = 0.8223, t = 1.4967, Stability = Stable
m = 0.12, k = 0.8159, t = 1.5096, Stability = Stable
m = 0.13, k = 0.8097, t = 1.5225, Stability = Stable
m = 0.14, k = 0.8035, t = 1.5352, Stability = Stable
m = 0.15, k = 0.7975, t = 1.5479, Stability = Stable
m = 0.16, k = 0.7916, t = 1.5604, Stability = Stable
m = 0.17, k = 0.7858, t = 1.5729, Stability = Stable
m = 0.18, k = 0.7802, t = 1.5853, Stability = Stable
m = 0.19, k = 0.7747, t = 1.5976, Stability = Stable
m = 0.20, k = 0.7693, t = 1.6099, Stability = Stable
m = 0.21, k = 0.7641, t = 1.6221, Stability = Stable
m = 0.22, k = 0.7590, t = 1.6343, Stability = Stable
m = 0.23, k = 0.7540, t = 1.6464, Stability = Stable
m = 0.24, k = 0.7492, t = 1.6585, Stability = Stable
m = 0.25, k = 0.7445, t = 1.6706, Stability = Stable
m = 0.26, k = 0.7399, t = 1.6826, Stability = Stable
m = 0.27, k = 0.7355, t = 1.6946, Stability = Stable
m = 0.28, k = 0.7312, t = 1.7067, Stability = Stable
m = 0.29, k = 0.7270, t = 1.7187, Stability = Stable
m = 0.30, k = 0.7229, t = 1.7306, Stability = Stable
m = 0.31, k = 0.7190, t = 1.7426, Stability = Stable
m = 0.32, k = 0.7151, t = 1.7546, Stability = Stable
m = 0.33, k = 0.7114, t = 1.7666, Stability = Stable
m = 0.34, k = 0.7078, t = 1.7786, Stability = Stable
m = 0.35, k = 0.7043, t = 1.7905, Stability = Stable
m = 0.36, k = 0.7009, t = 1.8025, Stability = Stable
m = 0.37, k = 0.6977, t = 1.8145, Stability = Stable
m = 0.38, k = 0.6945, t = 1.8265, Stability = Stable
m = 0.39, k = 0.6914, t = 1.8385, Stability = Stable
m = 0.40, k = 0.6884, t = 1.8505, Stability = Stable
m = 0.41, k = 0.6855, t = 1.8625, Stability = Stable
m = 0.42, k = 0.6827, t = 1.8745, Stability = Stable
m = 0.43, k = 0.6799, t = 1.8866, Stability = Stable
m = 0.44, k = 0.6773, t = 1.8986, Stability = Stable
m = 0.45, k = 0.6747, t = 1.9107, Stability = Stable
m = 0.46, k = 0.6722, t = 1.9228, Stability = Stable
m = 0.47, k = 0.6698, t = 1.9349, Stability = Stable
m = 0.48, k = 0.6675, t = 1.9470, Stability = Stable
m = 0.49, k = 0.6652, t = 1.9591, Stability = Stable
m = 0.51, k = 0.6630, t = 1.9712, Stability = Stable
m = 0.52, k = 0.6608, t = 1.9834, Stability = Stable
m = 0.53, k = 0.6587, t = 1.9955, Stability = Stable
m = 0.54, k = 0.6567, t = 2.0077, Stability = Stable
m = 0.55, k = 0.9565, t = 0.8397, Stability = Stable
m = 0.56, k = 0.9575, t = 0.8376, Stability = Stable
m = 0.57, k = 0.9586, t = 0.8355, Stability = Stable
m = 0.58, k = 0.9596, t = 0.8334, Stability = Stable
m = 0.59, k = 0.9606, t = 0.8313, Stability = Stable
m = 0.60, k = 0.9616, t = 0.8292, Stability = Stable
m = 0.61, k = 0.9626, t = 0.8272, Stability = Stable
m = 0.62, k = 0.9636, t = 0.8251, Stability = Stable
m = 0.63, k = 0.9646, t = 0.8230, Stability = Stable
m = 0.64, k = 0.9655, t = 0.8210, Stability = Stable
m = 0.65, k = 0.9665, t = 0.8189, Stability = Stable
m = 0.66, k = 0.9674, t = 0.8168, Stability = Stable
m = 0.67, k = 0.9683, t = 0.8148, Stability = Stable
m = 0.68, k = 0.9692, t = 0.8127, Stability = Stable
m = 0.69, k = 0.9701, t = 0.8107, Stability = Stable
m = 0.70, k = 0.9709, t = 0.8086, Stability = Stable
m = 0.71, k = 0.9718, t = 0.8066, Stability = Stable
m = 0.72, k = 0.9726, t = 0.8045, Stability = Stable
m = 0.73, k = 0.9734, t = 0.8025, Stability = Stable
m = 0.74, k = 0.9742, t = 0.8004, Stability = Stable
m = 0.75, k = 0.9749, t = 0.7984, Stability = Stable
m = 0.76, k = 0.9757, t = 0.7963, Stability = Stable
m = 0.77, k = 0.9764, t = 0.7943, Stability = Stable
m = 0.78, k = 0.9771, t = 0.7922, Stability = Stable
m = 0.79, k = 0.9778, t = 0.7901, Stability = Stable
m = 0.80, k = 0.9785, t = 0.7881, Stability = Stable
m = 0.81, k = 0.9791, t = 0.7860, Stability = Stable
m = 0.82, k = 0.9797, t = 0.7839, Stability = Stable
m = 0.83, k = 0.9804, t = 0.7819, Stability = Stable
m = 0.84, k = 0.9810, t = 0.7798, Stability = Stable
m = 0.85, k = 0.9815, t = 0.7777, Stability = Stable
m = 0.86, k = 0.9821, t = 0.7756, Stability = Stable
m = 0.87, k = 0.9826, t = 0.7735, Stability = Stable
m = 0.88, k = 0.9832, t = 0.7713, Stability = Stable
m = 0.89, k = 0.9837, t = 0.7692, Stability = Stable
m = 0.90, k = 0.9842, t = 0.7671, Stability = Stable
m = 0.91, k = 0.9846, t = 0.7649, Stability = Stable
m = 0.92, k = 0.9851, t = 0.7627, Stability = Stable
m = 0.93, k = 0.9856, t = 0.7606, Stability = Stable
m = 0.94, k = 0.9860, t = 0.7584, Stability = Stable
m = 0.95, k = 0.9864, t = 0.7562, Stability = Stable
m = 0.96, k = 0.9868, t = 0.7539, Stability = Stable
m = 0.97, k = 0.9872, t = 0.7517, Stability = Stable
m = 0.98, k = 0.9875, t = 0.7494, Stability = Stable
m = 0.99, k = 0.9879, t = 0.7471, Stability = Stable
m = 1.00, k = 0.9882, t = 0.7448, Stability = Stable
Now, the problem arose when I took k as an exogenous variable. When I input the value of k say 0.6945 (In above code, I got one of the solution as for m=0.38 I had k=0.6945 and t =1.82 and it was stable), I got value of t as 1.82 against m=0.38, as should be. But now this solution is unstable. Why? Can anyone help me why I am getting it stable in above code. While it is unstable in below. Please help
% Define the range of m values
m_values = linspace(0, 1, 100); % Adjust the number of points for higher accuracy
% Define the value of k
k = 0.6945;
% Initialize cell arrays to store fixed points and their stability
fixed_points = cell(length(m_values), 1);
stability_info = cell(length(m_values), 1);
% Define the function f(t, m)
f = @(t, m) real(((((k).^(1/2)).*(((m./t)+2)/3) - ((1-k).^(1/2)).*(1/3)*(2 + (m./t) + ((2*m + t)./(((m - t)^2) - 2*t)))))./((((k).^(1/2)).*(2*m^3 - 3*((1+m)^2)*t + t^3)/(3*(((m - t)^2) - 2*t)) - ((1-k).^(1/2)).*((2*m + t)/3))) - t);
% Define initial guesses for fsolve
initial_guesses = [0.1, 0.5, 1.7];
% Loop over the range of m values
for i = 1:length(m_values)
m_val = m_values(i);
% Initialize temporary storage for current m
current_fixed_points = [];
current_stability_info = [];
% Find fixed points using fsolve with multiple initial guesses
for guess = initial_guesses
options = optimset('Display', 'off', 'TolFun', 1e-10, 'TolX', 1e-10);
try
[t_val, fval, exitflag] = fsolve(@(t) f(t, m_val), guess, options);
% Check if the solution is valid and positive
if exitflag > 0 && t_val > 0 && isreal(t_val) && ~isnan(t_val) && ~isinf(t_val)
% Check if the solution is already found (to avoid duplicates)
if isempty(current_fixed_points) || all(abs(current_fixed_points - t_val) > 1e-6)
% Calculate the partial derivative (Jacobian) at the fixed point to check stability
df_dt = (f(t_val + 1e-6, m_val) - f(t_val, m_val)) / 1e-6;
% The eigenvalue in this 1D case is just df_dt
eigenvalue = df_dt;
% Check stability based on the real part of the eigenvalue
is_stable = real(eigenvalue) < 0;
% Store the fixed point and its stability
current_fixed_points = [current_fixed_points, t_val];
current_stability_info = [current_stability_info, is_stable];
end
end
catch
% Skip this initial guess if it causes an error
continue;
end
end
% Store results for current m
fixed_points{i} = current_fixed_points;
stability_info{i} = current_stability_info;
end
% Display results
for i = 1:length(m_values)
m_val = m_values(i);
t_vals = fixed_points{i};
stability_vals = stability_info{i};
for j = 1:length(t_vals)
fprintf('For m = %.2f, t = %.6f: stable = %d\n', m_val, t_vals(j), stability_vals(j));
end
end
For m = 0.00, t = 1.000000: stable = 1
For m = 0.00, t = 0.999999: stable = 1
For m = 0.00, t = 1.004399: stable = 0
For m = 0.01, t = 0.972720: stable = 1
For m = 0.02, t = 0.964445: stable = 1
For m = 0.03, t = 0.958973: stable = 1
For m = 0.04, t = 0.954766: stable = 1
For m = 0.05, t = 0.951274: stable = 1
For m = 0.05, t = 1.162613: stable = 0
For m = 0.06, t = 0.948240: stable = 1
For m = 0.07, t = 0.945521: stable = 1
For m = 0.07, t = 1.209997: stable = 0
For m = 0.08, t = 0.943032: stable = 1
For m = 0.08, t = 1.232926: stable = 0
For m = 0.09, t = 0.940716: stable = 1
For m = 0.09, t = 1.255454: stable = 0
For m = 0.10, t = 0.938538: stable = 1
For m = 0.10, t = 1.277632: stable = 0
For m = 0.11, t = 0.936469: stable = 1
For m = 0.11, t = 1.299500: stable = 0
For m = 0.12, t = 0.934492: stable = 1
For m = 0.12, t = 1.321089: stable = 0
For m = 0.13, t = 0.932590: stable = 1
For m = 0.13, t = 1.342424: stable = 0
For m = 0.14, t = 0.930754: stable = 1
For m = 0.14, t = 1.363528: stable = 0
For m = 0.15, t = 0.928975: stable = 1
For m = 0.15, t = 1.384416: stable = 0
For m = 0.16, t = 0.927246: stable = 1
For m = 0.16, t = 1.405106: stable = 0
For m = 0.17, t = 0.925560: stable = 1
For m = 0.17, t = 1.425609: stable = 0
For m = 0.18, t = 0.923915: stable = 1
For m = 0.18, t = 1.445937: stable = 0
For m = 0.19, t = 0.922306: stable = 1
For m = 0.19, t = 1.466101: stable = 0
For m = 0.20, t = 0.920729: stable = 1
For m = 0.20, t = 1.486111: stable = 0
For m = 0.21, t = 0.919183: stable = 1
For m = 0.21, t = 1.505973: stable = 0
For m = 0.22, t = 0.917665: stable = 1
For m = 0.22, t = 1.525695: stable = 0
For m = 0.23, t = 0.916173: stable = 1
For m = 0.23, t = 1.545286: stable = 0
For m = 0.24, t = 0.914706: stable = 1
For m = 0.24, t = 1.564749: stable = 0
For m = 0.25, t = 0.913262: stable = 1
For m = 0.25, t = 1.584092: stable = 0
For m = 0.26, t = 0.911839: stable = 1
For m = 0.26, t = 1.603320: stable = 0
For m = 0.27, t = 0.910437: stable = 1
For m = 0.27, t = 1.622437: stable = 0
For m = 0.28, t = 0.909055: stable = 1
For m = 0.28, t = 1.641448: stable = 0
For m = 0.29, t = 0.907691: stable = 1
For m = 0.29, t = 1.660357: stable = 0
For m = 0.30, t = 0.906345: stable = 1
For m = 0.30, t = 1.679169: stable = 0
For m = 0.31, t = 0.905017: stable = 1
For m = 0.31, t = 1.697886: stable = 0
For m = 0.32, t = 0.903705: stable = 1
For m = 0.32, t = 1.716512: stable = 0
For m = 0.33, t = 0.902409: stable = 1
For m = 0.33, t = 1.735050: stable = 0
For m = 0.34, t = 0.901128: stable = 1
For m = 0.34, t = 1.753504: stable = 0
For m = 0.35, t = 0.899862: stable = 1
For m = 0.35, t = 1.771876: stable = 0
For m = 0.36, t = 0.898611: stable = 1
For m = 0.36, t = 1.790169: stable = 0
For m = 0.37, t = 0.897373: stable = 1
For m = 0.37, t = 1.808385: stable = 0
For m = 0.38, t = 0.896149: stable = 1
For m = 0.38, t = 1.826527: stable = 0
For m = 0.39, t = 0.894938: stable = 1
For m = 0.39, t = 1.844597: stable = 0
For m = 0.40, t = 0.893739: stable = 1
For m = 0.40, t = 1.862598: stable = 0
For m = 0.41, t = 0.892553: stable = 1
For m = 0.41, t = 1.880530: stable = 0
For m = 0.42, t = 0.891380: stable = 1
For m = 0.42, t = 1.898397: stable = 0
For m = 0.43, t = 0.890218: stable = 1
For m = 0.43, t = 1.916201: stable = 0
For m = 0.44, t = 0.889067: stable = 1
For m = 0.44, t = 1.933942: stable = 0
For m = 0.45, t = 0.887928: stable = 1
For m = 0.45, t = 1.951622: stable = 0
For m = 0.46, t = 0.886799: stable = 1
For m = 0.46, t = 1.969244: stable = 0
For m = 0.47, t = 0.885682: stable = 1
For m = 0.47, t = 1.986808: stable = 0
For m = 0.48, t = 0.884575: stable = 1
For m = 0.48, t = 2.004317: stable = 0
For m = 0.49, t = 0.883478: stable = 1
For m = 0.49, t = 2.021771: stable = 0
For m = 0.51, t = 0.882391: stable = 1
For m = 0.51, t = 2.039172: stable = 0
For m = 0.52, t = 0.881314: stable = 1
For m = 0.52, t = 2.056522: stable = 0
For m = 0.53, t = 0.880246: stable = 1
For m = 0.53, t = 2.073821: stable = 0
For m = 0.54, t = 0.879188: stable = 1
For m = 0.55, t = 0.878139: stable = 1
For m = 0.56, t = 0.877099: stable = 1
For m = 0.57, t = 0.876068: stable = 1
For m = 0.58, t = 0.875046: stable = 1
For m = 0.59, t = 0.874032: stable = 1
For m = 0.60, t = 0.873027: stable = 1
For m = 0.61, t = 0.872029: stable = 1
For m = 0.62, t = 0.871040: stable = 1
For m = 0.63, t = 0.870059: stable = 1
For m = 0.64, t = 0.869085: stable = 1
For m = 0.65, t = 0.868119: stable = 1
For m = 0.66, t = 0.867161: stable = 1
For m = 0.67, t = 0.066626: stable = 0
For m = 0.67, t = 0.866210: stable = 1
For m = 0.68, t = 0.068546: stable = 0
For m = 0.68, t = 0.865266: stable = 1
For m = 0.69, t = 0.070490: stable = 0
For m = 0.69, t = 0.864329: stable = 1
For m = 0.70, t = 0.072458: stable = 0
For m = 0.70, t = 0.863399: stable = 1
For m = 0.71, t = 0.074450: stable = 0
For m = 0.71, t = 0.862475: stable = 1
For m = 0.72, t = 0.076466: stable = 0
For m = 0.72, t = 0.861559: stable = 1
For m = 0.73, t = 0.078506: stable = 0
For m = 0.73, t = 0.860649: stable = 1
For m = 0.74, t = 0.080570: stable = 0
For m = 0.74, t = 0.859745: stable = 1
For m = 0.75, t = 0.082657: stable = 0
For m = 0.75, t = 0.858848: stable = 1
For m = 0.76, t = 0.084768: stable = 0
For m = 0.76, t = 0.857957: stable = 1
For m = 0.77, t = 0.086902: stable = 0
For m = 0.77, t = 0.857072: stable = 1
For m = 0.78, t = 0.089060: stable = 0
For m = 0.78, t = 0.856193: stable = 1
For m = 0.79, t = 0.091241: stable = 0
For m = 0.79, t = 0.855319: stable = 1
For m = 0.80, t = 0.093446: stable = 0
For m = 0.80, t = 0.854452: stable = 1
For m = 0.81, t = 0.095673: stable = 0
For m = 0.81, t = 0.853590: stable = 1
For m = 0.82, t = 0.097923: stable = 0
For m = 0.82, t = 0.852734: stable = 1
For m = 0.83, t = 0.100197: stable = 0
For m = 0.83, t = 0.851883: stable = 1
For m = 0.84, t = 0.102493: stable = 0
For m = 0.84, t = 0.851037: stable = 1
For m = 0.85, t = 0.104812: stable = 0
For m = 0.85, t = 0.850197: stable = 1
For m = 0.86, t = 0.107153: stable = 0
For m = 0.86, t = 0.849361: stable = 1
For m = 0.87, t = 0.109517: stable = 0
For m = 0.87, t = 0.848531: stable = 1
For m = 0.88, t = 0.111904: stable = 0
For m = 0.88, t = 0.847706: stable = 1
For m = 0.89, t = 0.114313: stable = 0
For m = 0.89, t = 0.846885: stable = 1
For m = 0.90, t = 0.116745: stable = 0
For m = 0.90, t = 0.846069: stable = 1
For m = 0.91, t = 0.119199: stable = 0
For m = 0.91, t = 0.845258: stable = 1
For m = 0.92, t = 0.121675: stable = 0
For m = 0.92, t = 0.844451: stable = 1
For m = 0.93, t = 0.124173: stable = 0
For m = 0.93, t = 0.843649: stable = 1
For m = 0.94, t = 0.126693: stable = 0
For m = 0.94, t = 0.842851: stable = 1
For m = 0.95, t = 0.129236: stable = 0
For m = 0.95, t = 0.842057: stable = 1
For m = 0.96, t = 0.131800: stable = 0
For m = 0.96, t = 0.841268: stable = 1
For m = 0.97, t = 0.134386: stable = 0
For m = 0.97, t = 0.840482: stable = 1
For m = 0.98, t = 0.136994: stable = 0
For m = 0.98, t = 0.839700: stable = 1
For m = 0.99, t = 0.139624: stable = 0
For m = 0.99, t = 0.838922: stable = 1
For m = 1.00, t = 0.142275: stable = 0
For m = 1.00, t = 0.838148: stable = 1
% Plot fixed points as a function of m with stability info
figure;
hold on;
for i = 1:length(m_values)
t_vals = fixed_points{i};
stability_vals = stability_info{i};
for j = 1:length(t_vals)
if stability_vals(j)
plot(m_values(i), t_vals(j), 'go'); % Stable points in green
else
plot(m_values(i), t_vals(j), 'ro'); % Unstable points in red
end
end
end
xlabel('m');
ylabel('Fixed Point t');
title('Fixed Points and Stability as a Function of m');
legend('Stable', 'Unstable');
hold off;
댓글 수: 21
David Goodmanson
2024년 6월 6일
Hi Sabrina,
I ran the code, and after -- in the second part -- I changed a bunch of capital letters to small letters and funny single quote marks to good single quote marks (I don't know how that part could have run), everything agreed and came out Stable.
Torsten
2024년 6월 6일
편집: Torsten
2024년 6월 6일
J is always empty in your first code (see above) - thus I guess that this is the reason that the eigenvalue check is always positive.
The command "diff" to differentiate a function is not applicable in numerical computations - at least not for the purpose of your code.
Sabrina Garland
2024년 6월 6일
@Torsten Thanks a lot. I didn't notice my Jacobian matrix was blank. What should I use instead of diff? Any suggestions? Please help.
Torsten
2024년 6월 6일
편집: Torsten
2024년 6월 6일
Why not using the same method as in your second code ?
J(1,1) = (eq1([k_solution+1e-6, t_solution],m)-eq1([k_solution, t_solution],m))/1e-6;
J(1,2) = (eq1([k_solution, t_solution+1e-6],m)-eq1([k_solution, t_solution],m))/1e-6;
J(2,1) = (eq2([k_solution+1e-6, t_solution],m)-eq2([k_solution, t_solution],m))/1e-6;
J(2,2) = (eq2([k_solution, t_solution+1e-6],m)-eq2([k_solution, t_solution],m))/1e-6;
Sabrina Garland
2024년 6월 6일
편집: Torsten
2024년 6월 6일
I did and I got entire system as unstable. So, I switched. Here's the code I worked with -
% Define the equations as anonymous functions
eq1 = @(vars, m) (sqrt(vars(1))/sqrt(1-vars(1))) + ((vars(2)*(2*(m^3) + vars(2)^3 - 3*vars(2)*((m+1)^2))^2)/(6*vars(2) - 3*((m-vars(2))^2)) + ((m-vars(2))^2)*(m+2*vars(2))*(m/(3*vars(2)) + 2/3)) / ((m^3 - (vars(2)^2)*(3*m+3) + 2*(vars(2)^3))*(m/(3*vars(2)) - (2*m+vars(2))/(3*(2*vars(2)-((m-vars(2))^2))) + 2/3) - vars(2)*((m-vars(2))^2)*(2*m+vars(2))*((2*m/3) + vars(2)/3));
eq2 = @(vars, m) vars(2) - ((sqrt(vars(1))/sqrt(1-vars(1)))*(((m/vars(2))+2)/3) - (1/3)*(2 + (m/vars(2)) + ((2*m+vars(2))/(((m-vars(2))^2)-2*vars(2))))) / ((sqrt(vars(1))/sqrt(1-vars(1)))*(2*(m^3) - 3*((1+m)^2)*vars(2) + vars(2)^3)/(3*(((m-vars(2))^2)-2*vars(2))) - ((2*m+vars(2))/3));
% Define the range of m values
m_values = linspace(0, 1, 100); % 100 values of m between 0 and 1
% Preallocate arrays to store solutions
k_solutions = zeros(size(m_values));
t_solutions = zeros(size(m_values));
stabilities = cell(size(m_values));
% Loop over m values and solve the system of equations for each m
for i = 1:length(m_values)
m = m_values(i);
% System of equations for current m
system_of_equations = @(vars) [eq1(vars, m); eq2(vars, m)];
% Initial guess for [k, t]
initial_guess = [0.75, 1.5];
% Solve the system of equations using fsolve
options = optimoptions('fsolve', 'Display', 'off');
solution = fsolve(system_of_equations, initial_guess, options);
% Store solutions if they meet the criteria
k_solution = solution(1);
t_solution = solution(2);
if k_solution > 0.5 && k_solution < 1 && t_solution > 0
k_solutions(i) = k_solution;
t_solutions(i) = t_solution;
% Compute the Jacobian matrix using finite differences
delta = 1e-6;
J = zeros(2); % Initialize Jacobian matrix
% Calculate the partial derivatives for the Jacobian matrix
for j = 1:2
perturbed_solution = solution;
perturbed_solution(j) = perturbed_solution(j) + delta;
f_perturbed = system_of_equations(perturbed_solution);
f_original = system_of_equations(solution);
J(:, j) = (f_perturbed - f_original) / delta;
end
% Calculate eigenvalues of the Jacobian matrix
eigenvalues = eig(J);
% Analyze stability
if all(real(eigenvalues) < 0)
stabilities{i} = 'Stable';
elseif all(real(eigenvalues) == 0)
% Use center manifold method for stability analysis
% Modify this part with your center manifold method implementation
stabilities{i} = 'Center manifold method';
elseif any(real(eigenvalues) > 0)
stabilities{i} = 'Unstable';
end
else
k_solutions(i) = NaN;
t_solutions(i) = NaN;
stabilities{i} = 'NaN';
end
end
% Display solutions and stabilities
disp('Solutions for each m:');
Solutions for each m:
for i = 1:length(m_values)
fprintf('m = %.2f, k = %.4f, t = %.4f, Stability = %s\n', m_values(i), k_solutions(i), t_solutions(i), stabilities{i});
end
m = 0.00, k = 0.8968, t = 1.3405, Stability = Unstable
m = 0.01, k = 0.8900, t = 1.3562, Stability = Unstable
m = 0.02, k = 0.8831, t = 1.3715, Stability = Unstable
m = 0.03, k = 0.8762, t = 1.3864, Stability = Unstable
m = 0.04, k = 0.8693, t = 1.4010, Stability = Unstable
m = 0.05, k = 0.8624, t = 1.4154, Stability = Unstable
m = 0.06, k = 0.8556, t = 1.4294, Stability = Unstable
m = 0.07, k = 0.8488, t = 1.4432, Stability = Unstable
m = 0.08, k = 0.8420, t = 1.4569, Stability = Unstable
m = 0.09, k = 0.8354, t = 1.4703, Stability = Unstable
m = 0.10, k = 0.8288, t = 1.4836, Stability = Unstable
m = 0.11, k = 0.8223, t = 1.4967, Stability = Unstable
m = 0.12, k = 0.8159, t = 1.5096, Stability = Unstable
m = 0.13, k = 0.8097, t = 1.5225, Stability = Unstable
m = 0.14, k = 0.8035, t = 1.5352, Stability = Unstable
m = 0.15, k = 0.7975, t = 1.5479, Stability = Unstable
m = 0.16, k = 0.7916, t = 1.5604, Stability = Unstable
m = 0.17, k = 0.7858, t = 1.5729, Stability = Unstable
m = 0.18, k = 0.7802, t = 1.5853, Stability = Unstable
m = 0.19, k = 0.7747, t = 1.5976, Stability = Unstable
m = 0.20, k = 0.7693, t = 1.6099, Stability = Unstable
m = 0.21, k = 0.7641, t = 1.6221, Stability = Unstable
m = 0.22, k = 0.7590, t = 1.6343, Stability = Unstable
m = 0.23, k = 0.7540, t = 1.6464, Stability = Unstable
m = 0.24, k = 0.7492, t = 1.6585, Stability = Unstable
m = 0.25, k = 0.7445, t = 1.6706, Stability = Unstable
m = 0.26, k = 0.7399, t = 1.6826, Stability = Unstable
m = 0.27, k = 0.7355, t = 1.6946, Stability = Unstable
m = 0.28, k = 0.7312, t = 1.7067, Stability = Unstable
m = 0.29, k = 0.7270, t = 1.7187, Stability = Unstable
m = 0.30, k = 0.7229, t = 1.7306, Stability = Unstable
m = 0.31, k = 0.7190, t = 1.7426, Stability = Unstable
m = 0.32, k = 0.7151, t = 1.7546, Stability = Unstable
m = 0.33, k = 0.7114, t = 1.7666, Stability = Unstable
m = 0.34, k = 0.7078, t = 1.7786, Stability = Unstable
m = 0.35, k = 0.7043, t = 1.7905, Stability = Unstable
m = 0.36, k = 0.7009, t = 1.8025, Stability = Unstable
m = 0.37, k = 0.6977, t = 1.8145, Stability = Unstable
m = 0.38, k = 0.6945, t = 1.8265, Stability = Unstable
m = 0.39, k = 0.6914, t = 1.8385, Stability = Unstable
m = 0.40, k = 0.6884, t = 1.8505, Stability = Unstable
m = 0.41, k = 0.6855, t = 1.8625, Stability = Unstable
m = 0.42, k = 0.6827, t = 1.8745, Stability = Unstable
m = 0.43, k = 0.6799, t = 1.8866, Stability = Unstable
m = 0.44, k = 0.6773, t = 1.8986, Stability = Unstable
m = 0.45, k = 0.6747, t = 1.9107, Stability = Unstable
m = 0.46, k = 0.6722, t = 1.9228, Stability = Unstable
m = 0.47, k = 0.6698, t = 1.9349, Stability = Unstable
m = 0.48, k = 0.6675, t = 1.9470, Stability = Unstable
m = 0.49, k = 0.6652, t = 1.9591, Stability = Unstable
m = 0.51, k = 0.6630, t = 1.9712, Stability = Unstable
m = 0.52, k = 0.6608, t = 1.9834, Stability = Unstable
m = 0.53, k = 0.6587, t = 1.9955, Stability = Unstable
m = 0.54, k = 0.6567, t = 2.0077, Stability = Unstable
m = 0.55, k = 0.9565, t = 0.8397, Stability = Unstable
m = 0.56, k = 0.9575, t = 0.8376, Stability = Unstable
m = 0.57, k = 0.9586, t = 0.8355, Stability = Unstable
m = 0.58, k = 0.9596, t = 0.8334, Stability = Unstable
m = 0.59, k = 0.9606, t = 0.8313, Stability = Unstable
m = 0.60, k = 0.9616, t = 0.8292, Stability = Unstable
m = 0.61, k = 0.9626, t = 0.8272, Stability = Unstable
m = 0.62, k = 0.9636, t = 0.8251, Stability = Unstable
m = 0.63, k = 0.9646, t = 0.8230, Stability = Unstable
m = 0.64, k = 0.9655, t = 0.8210, Stability = Unstable
m = 0.65, k = 0.9665, t = 0.8189, Stability = Unstable
m = 0.66, k = 0.9674, t = 0.8168, Stability = Unstable
m = 0.67, k = 0.9683, t = 0.8148, Stability = Unstable
m = 0.68, k = 0.9692, t = 0.8127, Stability = Unstable
m = 0.69, k = 0.9701, t = 0.8107, Stability = Unstable
m = 0.70, k = 0.9709, t = 0.8086, Stability = Unstable
m = 0.71, k = 0.9718, t = 0.8066, Stability = Unstable
m = 0.72, k = 0.9726, t = 0.8045, Stability = Unstable
m = 0.73, k = 0.9734, t = 0.8025, Stability = Unstable
m = 0.74, k = 0.9742, t = 0.8004, Stability = Unstable
m = 0.75, k = 0.9749, t = 0.7984, Stability = Unstable
m = 0.76, k = 0.9757, t = 0.7963, Stability = Unstable
m = 0.77, k = 0.9764, t = 0.7943, Stability = Unstable
m = 0.78, k = 0.9771, t = 0.7922, Stability = Unstable
m = 0.79, k = 0.9778, t = 0.7901, Stability = Unstable
m = 0.80, k = 0.9785, t = 0.7881, Stability = Unstable
m = 0.81, k = 0.9791, t = 0.7860, Stability = Unstable
m = 0.82, k = 0.9797, t = 0.7839, Stability = Unstable
m = 0.83, k = 0.9804, t = 0.7819, Stability = Unstable
m = 0.84, k = 0.9810, t = 0.7798, Stability = Unstable
m = 0.85, k = 0.9815, t = 0.7777, Stability = Unstable
m = 0.86, k = 0.9821, t = 0.7756, Stability = Unstable
m = 0.87, k = 0.9826, t = 0.7735, Stability = Unstable
m = 0.88, k = 0.9832, t = 0.7713, Stability = Unstable
m = 0.89, k = 0.9837, t = 0.7692, Stability = Unstable
m = 0.90, k = 0.9842, t = 0.7671, Stability = Unstable
m = 0.91, k = 0.9846, t = 0.7649, Stability = Unstable
m = 0.92, k = 0.9851, t = 0.7627, Stability = Unstable
m = 0.93, k = 0.9856, t = 0.7606, Stability = Unstable
m = 0.94, k = 0.9860, t = 0.7584, Stability = Unstable
m = 0.95, k = 0.9864, t = 0.7562, Stability = Unstable
m = 0.96, k = 0.9868, t = 0.7539, Stability = Unstable
m = 0.97, k = 0.9872, t = 0.7517, Stability = Unstable
m = 0.98, k = 0.9875, t = 0.7494, Stability = Unstable
m = 0.99, k = 0.9879, t = 0.7471, Stability = Unstable
m = 1.00, k = 0.9882, t = 0.7448, Stability = Unstable
% Plot solutions
figure;
plot(m_values, k_solutions, '-o', 'DisplayName', 'k');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
hold on;
plot(m_values, t_solutions, '-o', 'DisplayName', 't');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
xlabel('m');
ylabel('Values');
title('Solutions as a Function of m');
legend('k', 't');
hold off;
% Plot stability
figure;
plot(m_values, strcmp(stabilities, 'Stable'), '-o', 'DisplayName', 'Stable');
hold on;
plot(m_values, strcmp(stabilities, 'Unstable'), '-o', 'DisplayName', 'Unstable');
xlabel('m');
ylabel('Stability');
title('Stability as a Function of m');
legend('Stable', 'Unstable');
hold off;
Sabrina Garland
2024년 6월 6일
Copied the wrong code. Thanks for pointing out. I did at solutions. Initially, I, by mistake, did at initial guess and that code remained in my history and I copied pasted here by mistake.
Torsten
2024년 6월 6일
편집: Torsten
2024년 6월 6일
A little improvement (not so much relevant in the present case because you only work with two equations):
You should compute
f_original = system_of_equations(solution);
once outside the j-loop and not compute it repeatedly within the j-loop.
And you should check the exitflag from "fsolve" to see if it really converged.
I suggest the following code where I changed the initial guess to the solution for the preceeding m-value:
% Define the equations as anonymous functions
eq1 = @(vars, m) (sqrt(vars(1))/sqrt(1-vars(1))) + ((vars(2)*(2*(m^3) + vars(2)^3 - 3*vars(2)*((m+1)^2))^2)/(6*vars(2) - 3*((m-vars(2))^2)) + ((m-vars(2))^2)*(m+2*vars(2))*(m/(3*vars(2)) + 2/3)) / ((m^3 - (vars(2)^2)*(3*m+3) + 2*(vars(2)^3))*(m/(3*vars(2)) - (2*m+vars(2))/(3*(2*vars(2)-((m-vars(2))^2))) + 2/3) - vars(2)*((m-vars(2))^2)*(2*m+vars(2))*((2*m/3) + vars(2)/3));
eq2 = @(vars, m) vars(2) - ((sqrt(vars(1))/sqrt(1-vars(1)))*(((m/vars(2))+2)/3) - (1/3)*(2 + (m/vars(2)) + ((2*m+vars(2))/(((m-vars(2))^2)-2*vars(2))))) / ((sqrt(vars(1))/sqrt(1-vars(1)))*(2*(m^3) - 3*((1+m)^2)*vars(2) + vars(2)^3)/(3*(((m-vars(2))^2)-2*vars(2))) - ((2*m+vars(2))/3));
% Define the range of m values
m_values = linspace(0, 1, 100); % 100 values of m between 0 and 1
% Preallocate arrays to store solutions
k_solutions = zeros(size(m_values));
t_solutions = zeros(size(m_values));
stabilities = cell(size(m_values));
% Initial guess for [k, t]
initial_guess = [0.75, 1.5];
% Loop over m values and solve the system of equations for each m
for i = 1:length(m_values)
m = m_values(i);
% System of equations for current m
system_of_equations = @(vars) [eq1(vars, m); eq2(vars, m)];
% Solve the system of equations using fsolve
options = optimoptions('fsolve', 'Display', 'off');
[solution,~,exitflag] = fsolve(system_of_equations, initial_guess, options);
%exitflag
% Store solutions if they meet the criteria
k_solution = solution(1);
t_solution = solution(2);
if k_solution > 0.5 && k_solution < 1 && t_solution > 0
k_solutions(i) = k_solution;
t_solutions(i) = t_solution;
% Compute the Jacobian matrix using finite differences
delta = 1e-6;
J = zeros(2); % Initialize Jacobian matrix
f_original = system_of_equations(solution);
% Calculate the partial derivatives for the Jacobian matrix
for j = 1:2
perturbed_solution = solution;
perturbed_solution(j) = perturbed_solution(j) + delta;
f_perturbed = system_of_equations(perturbed_solution);
J(:, j) = (f_perturbed - f_original) / delta;
end
% Calculate eigenvalues of the Jacobian matrix
eigenvalues = eig(J);
% Analyze stability
if all(real(eigenvalues) < 0)
stabilities{i} = 'Stable';
elseif all(real(eigenvalues) == 0)
% Use center manifold method for stability analysis
% Modify this part with your center manifold method implementation
stabilities{i} = 'Center manifold method';
elseif any(real(eigenvalues) > 0)
stabilities{i} = 'Unstable';
end
else
k_solutions(i) = NaN;
t_solutions(i) = NaN;
stabilities{i} = 'NaN';
end
% Initial guess for [k, t]
initial_guess = solution;
end
% Display solutions and stabilities
disp('Solutions for each m:');
Solutions for each m:
for i = 1:length(m_values)
fprintf('m = %.2f, k = %.4f, t = %.4f, Stability = %s\n', m_values(i), k_solutions(i), t_solutions(i), stabilities{i});
end
m = 0.00, k = 0.8968, t = 1.3405, Stability = Unstable
m = 0.01, k = 0.8900, t = 1.3562, Stability = Unstable
m = 0.02, k = 0.8831, t = 1.3715, Stability = Unstable
m = 0.03, k = 0.8762, t = 1.3864, Stability = Unstable
m = 0.04, k = 0.8693, t = 1.4010, Stability = Unstable
m = 0.05, k = 0.8624, t = 1.4154, Stability = Unstable
m = 0.06, k = 0.8556, t = 1.4294, Stability = Unstable
m = 0.07, k = 0.8488, t = 1.4432, Stability = Unstable
m = 0.08, k = 0.8420, t = 1.4569, Stability = Unstable
m = 0.09, k = 0.8354, t = 1.4703, Stability = Unstable
m = 0.10, k = 0.8288, t = 1.4836, Stability = Unstable
m = 0.11, k = 0.8223, t = 1.4967, Stability = Unstable
m = 0.12, k = 0.8159, t = 1.5096, Stability = Unstable
m = 0.13, k = 0.8097, t = 1.5225, Stability = Unstable
m = 0.14, k = 0.8035, t = 1.5352, Stability = Unstable
m = 0.15, k = 0.7975, t = 1.5479, Stability = Unstable
m = 0.16, k = 0.7916, t = 1.5604, Stability = Unstable
m = 0.17, k = 0.7858, t = 1.5729, Stability = Unstable
m = 0.18, k = 0.7802, t = 1.5853, Stability = Unstable
m = 0.19, k = 0.7747, t = 1.5976, Stability = Unstable
m = 0.20, k = 0.7693, t = 1.6099, Stability = Unstable
m = 0.21, k = 0.7641, t = 1.6221, Stability = Unstable
m = 0.22, k = 0.7590, t = 1.6343, Stability = Unstable
m = 0.23, k = 0.7540, t = 1.6464, Stability = Unstable
m = 0.24, k = 0.7492, t = 1.6585, Stability = Unstable
m = 0.25, k = 0.7445, t = 1.6706, Stability = Unstable
m = 0.26, k = 0.7399, t = 1.6826, Stability = Unstable
m = 0.27, k = 0.7355, t = 1.6946, Stability = Unstable
m = 0.28, k = 0.7312, t = 1.7067, Stability = Unstable
m = 0.29, k = 0.7270, t = 1.7187, Stability = Unstable
m = 0.30, k = 0.7229, t = 1.7306, Stability = Unstable
m = 0.31, k = 0.7190, t = 1.7426, Stability = Unstable
m = 0.32, k = 0.7151, t = 1.7546, Stability = Unstable
m = 0.33, k = 0.7114, t = 1.7666, Stability = Unstable
m = 0.34, k = 0.7078, t = 1.7786, Stability = Unstable
m = 0.35, k = 0.7043, t = 1.7905, Stability = Unstable
m = 0.36, k = 0.7009, t = 1.8025, Stability = Unstable
m = 0.37, k = 0.6977, t = 1.8145, Stability = Unstable
m = 0.38, k = 0.6945, t = 1.8265, Stability = Unstable
m = 0.39, k = 0.6914, t = 1.8385, Stability = Unstable
m = 0.40, k = 0.6884, t = 1.8505, Stability = Unstable
m = 0.41, k = 0.6855, t = 1.8625, Stability = Unstable
m = 0.42, k = 0.6827, t = 1.8745, Stability = Unstable
m = 0.43, k = 0.6799, t = 1.8866, Stability = Unstable
m = 0.44, k = 0.6773, t = 1.8986, Stability = Unstable
m = 0.45, k = 0.6747, t = 1.9107, Stability = Unstable
m = 0.46, k = 0.6722, t = 1.9228, Stability = Unstable
m = 0.47, k = 0.6698, t = 1.9349, Stability = Unstable
m = 0.48, k = 0.6675, t = 1.9470, Stability = Unstable
m = 0.49, k = 0.6652, t = 1.9591, Stability = Unstable
m = 0.51, k = 0.6630, t = 1.9712, Stability = Unstable
m = 0.52, k = 0.6608, t = 1.9834, Stability = Unstable
m = 0.53, k = 0.6587, t = 1.9955, Stability = Unstable
m = 0.54, k = 0.6567, t = 2.0077, Stability = Unstable
m = 0.55, k = 0.6547, t = 2.0199, Stability = Unstable
m = 0.56, k = 0.6528, t = 2.0321, Stability = Unstable
m = 0.57, k = 0.6510, t = 2.0444, Stability = Unstable
m = 0.58, k = 0.6492, t = 2.0566, Stability = Unstable
m = 0.59, k = 0.6474, t = 2.0689, Stability = Unstable
m = 0.60, k = 0.6457, t = 2.0811, Stability = Unstable
m = 0.61, k = 0.6441, t = 2.0934, Stability = Unstable
m = 0.62, k = 0.6425, t = 2.1057, Stability = Unstable
m = 0.63, k = 0.6409, t = 2.1180, Stability = Unstable
m = 0.64, k = 0.6394, t = 2.1304, Stability = Unstable
m = 0.65, k = 0.6379, t = 2.1427, Stability = Unstable
m = 0.66, k = 0.6365, t = 2.1551, Stability = Unstable
m = 0.67, k = 0.6351, t = 2.1674, Stability = Unstable
m = 0.68, k = 0.6337, t = 2.1798, Stability = Unstable
m = 0.69, k = 0.6324, t = 2.1922, Stability = Unstable
m = 0.70, k = 0.6311, t = 2.2046, Stability = Unstable
m = 0.71, k = 0.6299, t = 2.2170, Stability = Unstable
m = 0.72, k = 0.6286, t = 2.2295, Stability = Unstable
m = 0.73, k = 0.6274, t = 2.2419, Stability = Unstable
m = 0.74, k = 0.6263, t = 2.2544, Stability = Unstable
m = 0.75, k = 0.6252, t = 2.2668, Stability = Unstable
m = 0.76, k = 0.6241, t = 2.2793, Stability = Unstable
m = 0.77, k = 0.6230, t = 2.2918, Stability = Unstable
m = 0.78, k = 0.6219, t = 2.3043, Stability = Unstable
m = 0.79, k = 0.6209, t = 2.3168, Stability = Unstable
m = 0.80, k = 0.6199, t = 2.3294, Stability = Unstable
m = 0.81, k = 0.6189, t = 2.3419, Stability = Unstable
m = 0.82, k = 0.6180, t = 2.3544, Stability = Unstable
m = 0.83, k = 0.6171, t = 2.3670, Stability = Unstable
m = 0.84, k = 0.6162, t = 2.3795, Stability = Unstable
m = 0.85, k = 0.6153, t = 2.3921, Stability = Unstable
m = 0.86, k = 0.6144, t = 2.4047, Stability = Unstable
m = 0.87, k = 0.6136, t = 2.4173, Stability = Unstable
m = 0.88, k = 0.6128, t = 2.4299, Stability = Unstable
m = 0.89, k = 0.6120, t = 2.4425, Stability = Unstable
m = 0.90, k = 0.6112, t = 2.4551, Stability = Unstable
m = 0.91, k = 0.6104, t = 2.4677, Stability = Unstable
m = 0.92, k = 0.6097, t = 2.4803, Stability = Unstable
m = 0.93, k = 0.6090, t = 2.4929, Stability = Unstable
m = 0.94, k = 0.6082, t = 2.5056, Stability = Unstable
m = 0.95, k = 0.6076, t = 2.5182, Stability = Unstable
m = 0.96, k = 0.6069, t = 2.5309, Stability = Unstable
m = 0.97, k = 0.6062, t = 2.5435, Stability = Unstable
m = 0.98, k = 0.6056, t = 2.5562, Stability = Unstable
m = 0.99, k = 0.6049, t = 2.5688, Stability = Unstable
m = 1.00, k = 0.6043, t = 2.5815, Stability = Unstable
% Plot solutions
figure;
plot(m_values, k_solutions, '-o', 'DisplayName', 'k');
hold on;
plot(m_values, t_solutions, '-o', 'DisplayName', 't');
xlabel('m');
ylabel('Values');
title('Solutions as a Function of m');
legend('k', 't');
hold off;
% Plot stability
figure;
plot(m_values, strcmp(stabilities, 'Stable'), '-o', 'DisplayName', 'Stable');
hold on;
plot(m_values, strcmp(stabilities, 'Unstable'), '-o', 'DisplayName', 'Unstable');
xlabel('m');
ylabel('Stability');
title('Stability as a Function of m');
legend('Stable', 'Unstable');
hold off;
Sabrina Garland
2024년 6월 6일
편집: Torsten
2024년 6월 6일
Thanks for suggestion. I am still stuck.
% Define the equations as anonymous functions
eq1 = @(vars, m) (sqrt(vars(1))/sqrt(1-vars(1))) + ((vars(2)*(2*(m^3) + vars(2)^3 - 3*vars(2)*((m+1)^2))^2)/(6*vars(2) - 3*((m-vars(2))^2)) + ((m-vars(2))^2)*(m+2*vars(2))*(m/(3*vars(2)) + 2/3)) / ((m^3 - (vars(2)^2)*(3*m+3) + 2*(vars(2)^3))*(m/(3*vars(2)) - (2*m+vars(2))/(3*(2*vars(2)-((m-vars(2))^2))) + 2/3) - vars(2)*((m-vars(2))^2)*(2*m+vars(2))*((2*m/3) + vars(2)/3));
eq2 = @(vars, m) vars(2) - ((sqrt(vars(1))/sqrt(1-vars(1)))*(((m/vars(2))+2)/3) - (1/3)*(2 + (m/vars(2)) + ((2*m+vars(2))/(((m-vars(2))^2)-2*vars(2))))) / ((sqrt(vars(1))/sqrt(1-vars(1)))*(2*(m^3) - 3*((1+m)^2)*vars(2) + vars(2)^3)/(3*(((m-vars(2))^2)-2*vars(2))) - ((2*m+vars(2))/3));
% Define the range of m values
m_values = linspace(0, 1, 100); % 100 values of m between 0 and 1
% Preallocate arrays to store solutions
k_solutions = zeros(size(m_values));
t_solutions = zeros(size(m_values));
stabilities = cell(size(m_values));
% Loop over m values and solve the system of equations for each m
for i = 1:length(m_values)
m = m_values(i);
% System of equations for current m
system_of_equations = @(vars) [eq1(vars, m); eq2(vars, m)];
% Initial guess for [k, t]
initial_guess = [0.75, 1.5];
% Solve the system of equations using fsolve
options = optimoptions('fsolve', 'Display', 'off');
[solution, ~, exitflag] = fsolve(system_of_equations, initial_guess, options);
% Check if fsolve converged
if exitflag > 0
% Store solutions if they meet the criteria
k_solution = solution(1);
t_solution = solution(2);
if k_solution > 0.5 && k_solution < 1 && t_solution > 0
k_solutions(i) = k_solution;
t_solutions(i) = t_solution;
% Compute the Jacobian matrix using finite differences
delta = 1e-6;
J = zeros(2); % Initialize Jacobian matrix
% Compute f_original once outside the loop
f_original = system_of_equations(solution);
% Calculate the partial derivatives for the Jacobian matrix
for j = 1:2
perturbed_solution = solution;
perturbed_solution(j) = perturbed_solution(j) + delta;
f_perturbed = system_of_equations(perturbed_solution);
J(:, j) = (f_perturbed - f_original) / delta;
end
% Calculate eigenvalues of the Jacobian matrix
eigenvalues = eig(J);
% Analyze stability
if all(real(eigenvalues) < 0)
stabilities{i} = 'Stable';
elseif all(real(eigenvalues) == 0)
% Use center manifold method for stability analysis
% Modify this part with your center manifold method implementation
stabilities{i} = 'Center manifold method';
elseif any(real(eigenvalues) > 0)
stabilities{i} = 'Unstable';
end
else
k_solutions(i) = NaN;
t_solutions(i) = NaN;
stabilities{i} = 'NaN';
end
else
k_solutions(i) = NaN;
t_solutions(i) = NaN;
stabilities{i} = 'NaN';
end
end
% Display solutions and stabilities
disp('Solutions for each m:');
Solutions for each m:
for i = 1:length(m_values)
fprintf('m = %.2f, k = %.4f, t = %.4f, Stability = %s\n', m_values(i), k_solutions(i), t_solutions(i), stabilities{i});
end
m = 0.00, k = 0.8968, t = 1.3405, Stability = Unstable
m = 0.01, k = 0.8900, t = 1.3562, Stability = Unstable
m = 0.02, k = 0.8831, t = 1.3715, Stability = Unstable
m = 0.03, k = 0.8762, t = 1.3864, Stability = Unstable
m = 0.04, k = 0.8693, t = 1.4010, Stability = Unstable
m = 0.05, k = 0.8624, t = 1.4154, Stability = Unstable
m = 0.06, k = 0.8556, t = 1.4294, Stability = Unstable
m = 0.07, k = 0.8488, t = 1.4432, Stability = Unstable
m = 0.08, k = 0.8420, t = 1.4569, Stability = Unstable
m = 0.09, k = 0.8354, t = 1.4703, Stability = Unstable
m = 0.10, k = 0.8288, t = 1.4836, Stability = Unstable
m = 0.11, k = 0.8223, t = 1.4967, Stability = Unstable
m = 0.12, k = 0.8159, t = 1.5096, Stability = Unstable
m = 0.13, k = 0.8097, t = 1.5225, Stability = Unstable
m = 0.14, k = 0.8035, t = 1.5352, Stability = Unstable
m = 0.15, k = 0.7975, t = 1.5479, Stability = Unstable
m = 0.16, k = 0.7916, t = 1.5604, Stability = Unstable
m = 0.17, k = 0.7858, t = 1.5729, Stability = Unstable
m = 0.18, k = 0.7802, t = 1.5853, Stability = Unstable
m = 0.19, k = 0.7747, t = 1.5976, Stability = Unstable
m = 0.20, k = 0.7693, t = 1.6099, Stability = Unstable
m = 0.21, k = 0.7641, t = 1.6221, Stability = Unstable
m = 0.22, k = 0.7590, t = 1.6343, Stability = Unstable
m = 0.23, k = 0.7540, t = 1.6464, Stability = Unstable
m = 0.24, k = 0.7492, t = 1.6585, Stability = Unstable
m = 0.25, k = 0.7445, t = 1.6706, Stability = Unstable
m = 0.26, k = 0.7399, t = 1.6826, Stability = Unstable
m = 0.27, k = 0.7355, t = 1.6946, Stability = Unstable
m = 0.28, k = 0.7312, t = 1.7067, Stability = Unstable
m = 0.29, k = 0.7270, t = 1.7187, Stability = Unstable
m = 0.30, k = 0.7229, t = 1.7306, Stability = Unstable
m = 0.31, k = 0.7190, t = 1.7426, Stability = Unstable
m = 0.32, k = 0.7151, t = 1.7546, Stability = Unstable
m = 0.33, k = 0.7114, t = 1.7666, Stability = Unstable
m = 0.34, k = 0.7078, t = 1.7786, Stability = Unstable
m = 0.35, k = 0.7043, t = 1.7905, Stability = Unstable
m = 0.36, k = 0.7009, t = 1.8025, Stability = Unstable
m = 0.37, k = 0.6977, t = 1.8145, Stability = Unstable
m = 0.38, k = 0.6945, t = 1.8265, Stability = Unstable
m = 0.39, k = 0.6914, t = 1.8385, Stability = Unstable
m = 0.40, k = 0.6884, t = 1.8505, Stability = Unstable
m = 0.41, k = 0.6855, t = 1.8625, Stability = Unstable
m = 0.42, k = 0.6827, t = 1.8745, Stability = Unstable
m = 0.43, k = 0.6799, t = 1.8866, Stability = Unstable
m = 0.44, k = 0.6773, t = 1.8986, Stability = Unstable
m = 0.45, k = 0.6747, t = 1.9107, Stability = Unstable
m = 0.46, k = 0.6722, t = 1.9228, Stability = Unstable
m = 0.47, k = 0.6698, t = 1.9349, Stability = Unstable
m = 0.48, k = 0.6675, t = 1.9470, Stability = Unstable
m = 0.49, k = 0.6652, t = 1.9591, Stability = Unstable
m = 0.51, k = 0.6630, t = 1.9712, Stability = Unstable
m = 0.52, k = 0.6608, t = 1.9834, Stability = Unstable
m = 0.53, k = 0.6587, t = 1.9955, Stability = Unstable
m = 0.54, k = 0.6567, t = 2.0077, Stability = Unstable
m = 0.55, k = 0.9565, t = 0.8397, Stability = Unstable
m = 0.56, k = 0.9575, t = 0.8376, Stability = Unstable
m = 0.57, k = 0.9586, t = 0.8355, Stability = Unstable
m = 0.58, k = 0.9596, t = 0.8334, Stability = Unstable
m = 0.59, k = 0.9606, t = 0.8313, Stability = Unstable
m = 0.60, k = 0.9616, t = 0.8292, Stability = Unstable
m = 0.61, k = 0.9626, t = 0.8272, Stability = Unstable
m = 0.62, k = 0.9636, t = 0.8251, Stability = Unstable
m = 0.63, k = 0.9646, t = 0.8230, Stability = Unstable
m = 0.64, k = 0.9655, t = 0.8210, Stability = Unstable
m = 0.65, k = 0.9665, t = 0.8189, Stability = Unstable
m = 0.66, k = 0.9674, t = 0.8168, Stability = Unstable
m = 0.67, k = 0.9683, t = 0.8148, Stability = Unstable
m = 0.68, k = 0.9692, t = 0.8127, Stability = Unstable
m = 0.69, k = 0.9701, t = 0.8107, Stability = Unstable
m = 0.70, k = 0.9709, t = 0.8086, Stability = Unstable
m = 0.71, k = 0.9718, t = 0.8066, Stability = Unstable
m = 0.72, k = 0.9726, t = 0.8045, Stability = Unstable
m = 0.73, k = 0.9734, t = 0.8025, Stability = Unstable
m = 0.74, k = 0.9742, t = 0.8004, Stability = Unstable
m = 0.75, k = 0.9749, t = 0.7984, Stability = Unstable
m = 0.76, k = 0.9757, t = 0.7963, Stability = Unstable
m = 0.77, k = 0.9764, t = 0.7943, Stability = Unstable
m = 0.78, k = 0.9771, t = 0.7922, Stability = Unstable
m = 0.79, k = 0.9778, t = 0.7901, Stability = Unstable
m = 0.80, k = 0.9785, t = 0.7881, Stability = Unstable
m = 0.81, k = 0.9791, t = 0.7860, Stability = Unstable
m = 0.82, k = 0.9797, t = 0.7839, Stability = Unstable
m = 0.83, k = 0.9804, t = 0.7819, Stability = Unstable
m = 0.84, k = 0.9810, t = 0.7798, Stability = Unstable
m = 0.85, k = 0.9815, t = 0.7777, Stability = Unstable
m = 0.86, k = 0.9821, t = 0.7756, Stability = Unstable
m = 0.87, k = 0.9826, t = 0.7735, Stability = Unstable
m = 0.88, k = 0.9832, t = 0.7713, Stability = Unstable
m = 0.89, k = 0.9837, t = 0.7692, Stability = Unstable
m = 0.90, k = 0.9842, t = 0.7671, Stability = Unstable
m = 0.91, k = 0.9846, t = 0.7649, Stability = Unstable
m = 0.92, k = 0.9851, t = 0.7627, Stability = Unstable
m = 0.93, k = 0.9856, t = 0.7606, Stability = Unstable
m = 0.94, k = 0.9860, t = 0.7584, Stability = Unstable
m = 0.95, k = 0.9864, t = 0.7562, Stability = Unstable
m = 0.96, k = 0.9868, t = 0.7539, Stability = Unstable
m = 0.97, k = 0.9872, t = 0.7517, Stability = Unstable
m = 0.98, k = 0.9875, t = 0.7494, Stability = Unstable
m = 0.99, k = 0.9879, t = 0.7471, Stability = Unstable
m = 1.00, k = 0.9882, t = 0.7448, Stability = Unstable
% Plot solutions
figure;
plot(m_values, k_solutions, '-o', 'DisplayName', 'k');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
hold on;
plot(m_values, t_solutions, '-o', 'DisplayName', 't');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
xlabel('m');
ylabel('Values');
title('Solutions as a Function of m');
legend('k', 't');
hold off;
% Plot stability
figure;
plot(m_values, strcmp(stabilities, 'Stable'), '-o', 'DisplayName', 'Stable');
hold on;
plot(m_values, strcmp(stabilities, 'Unstable'), '-o', 'DisplayName', 'Unstable');
xlabel('m');
ylabel('Stability');
title('Stability as a Function of m');
legend('Stable', 'Unstable');
hold off;
Sabrina Garland
2024년 6월 6일
Stuck on the answers - I don't know which answers are stable. Using this method (extending my second code perturbed definition of differentiation), I get instability everywhere. While using, my original code method I get stability. Furthermore, when I input the capital, instead of solving it, I get stable and unstable solution. Which one is correct?
Torsten
2024년 6월 6일
편집: Torsten
2024년 6월 6일
Given the nonlinear system
% Define the equations as anonymous functions
eq1 = @(vars, m) (sqrt(vars(1))/sqrt(1-vars(1))) + ((vars(2)*(2*(m^3) + vars(2)^3 - 3*vars(2)*((m+1)^2))^2)/(6*vars(2) - 3*((m-vars(2))^2)) + ((m-vars(2))^2)*(m+2*vars(2))*(m/(3*vars(2)) + 2/3)) / ((m^3 - (vars(2)^2)*(3*m+3) + 2*(vars(2)^3))*(m/(3*vars(2)) - (2*m+vars(2))/(3*(2*vars(2)-((m-vars(2))^2))) + 2/3) - vars(2)*((m-vars(2))^2)*(2*m+vars(2))*((2*m/3) + vars(2)/3));
eq2 = @(vars, m) vars(2) - ((sqrt(vars(1))/sqrt(1-vars(1)))*(((m/vars(2))+2)/3) - (1/3)*(2 + (m/vars(2)) + ((2*m+vars(2))/(((m-vars(2))^2)-2*vars(2))))) / ((sqrt(vars(1))/sqrt(1-vars(1)))*(2*(m^3) - 3*((1+m)^2)*vars(2) + vars(2)^3)/(3*(((m-vars(2))^2)-2*vars(2))) - ((2*m+vars(2))/3));
you only get unstable solutions for 0 <= m <= 1. That's understandable from your code.
Maybe you could explain what you do in your second approach and how this is related to the first investigation for stability. Since your function f has changed, I can't understand why you think both approaches will give the same result, especially since you keep k constant as k = 0.6945.
Steven Lord
2024년 6월 6일
In the cases where you expected the code to report stability but it reported an unstable result, what are the values of the positive eigenvalues? Are they much greater than zero or are they essentially zero but because of numerical noise are just barely greater than zero?
Sabrina Garland
2024년 6월 6일
Thanks for response! But, the result should be stability at some of the solution. The system can't be entirely unstable. @Steven Lord that's very helpful remark. Let me check that.
Sabrina Garland
2024년 6월 6일
Here's the code checking the eigenvalues. As I could see, eigenvalues for t are near zero but eigenvalues for k are quite large.
Should I take different perturbation for k and t?
% Define the equations as anonymous functions eq1 = @(vars, m) (sqrt(vars(1))/sqrt(1-vars(1))) + ((vars(2)*(2*(m^3) + vars(2)^3 - 3*vars(2)*((m+1)^2))^2)/(6*vars(2) - 3*((m-vars(2))^2)) + ((m-vars(2))^2)*(m+2*vars(2))*(m/(3*vars(2)) + 2/3)) / ((m^3 - (vars(2)^2)*(3*m+3) + 2*(vars(2)^3))*(m/(3*vars(2)) - (2*m+vars(2))/(3*(2*vars(2)-((m-vars(2))^2))) + 2/3) - vars(2)*((m-vars(2))^2)*(2*m+vars(2))*((2*m/3) + vars(2)/3)); eq2 = @(vars, m) vars(2) - ((sqrt(vars(1))/sqrt(1-vars(1)))*(((m/vars(2))+2)/3) - (1/3)*(2 + (m/vars(2)) + ((2*m+vars(2))/(((m-vars(2))^2)-2*vars(2))))) / ((sqrt(vars(1))/sqrt(1-vars(1)))*(2*(m^3) - 3*((1+m)^2)*vars(2) + vars(2)^3)/(3*(((m-vars(2))^2)-2*vars(2))) - ((2*m+vars(2))/3));
% Define the range of m values m_values = linspace(0, 1, 100); % 100 values of m between 0 and 1
% Preallocate arrays to store solutions k_solutions = zeros(size(m_values)); t_solutions = zeros(size(m_values)); stabilities = cell(size(m_values));
% Loop over m values and solve the system of equations for each m for i = 1:length(m_values) m = m_values(i);
% System of equations for current m system_of_equations = @(vars) [eq1(vars, m); eq2(vars, m)];
% Initial guess for [k, t] initial_guess = [0.75, 1.5];
% Solve the system of equations using fsolve options = optimoptions('fsolve', 'Display', 'off'); [solution, ~, exitflag] = fsolve(system_of_equations, initial_guess, options);
% Check if fsolve converged if exitflag > 0 % Store solutions if they meet the criteria k_solution = solution(1); t_solution = solution(2);
if k_solution > 0.5 && k_solution < 1 && t_solution > 0 k_solutions(i) = k_solution; t_solutions(i) = t_solution;
% Compute the Jacobian matrix using finite differences delta = 1e-6; J = zeros(2); % Initialize Jacobian matrix
% Compute f_original once outside the loop f_original = system_of_equations(solution);
% Calculate the partial derivatives for the Jacobian matrix for j = 1:2 perturbed_solution = solution; perturbed_solution(j) = perturbed_solution(j) + delta; f_perturbed = system_of_equations(perturbed_solution); J(:, j) = (f_perturbed - f_original) / delta; end
% Calculate eigenvalues of the Jacobian matrix eigenvalues = eig(J);
% Debug: print eigenvalues for inspection fprintf('m = %.2f, k = %.4f, t = %.4f, Eigenvalues: %.6f, %.6f\n', m, k_solution, t_solution, eigenvalues(1), eigenvalues(2));
% Analyze stability if all(real(eigenvalues) < 0) stabilities{i} = 'Stable'; elseif all(real(eigenvalues) == 0) % Use center manifold method for stability analysis % Modify this part with your center manifold method implementation stabilities{i} = 'Center manifold method'; elseif any(real(eigenvalues) > 0) stabilities{i} = 'Unstable'; end else k_solutions(i) = NaN; t_solutions(i) = NaN; stabilities{i} = 'NaN'; end else k_solutions(i) = NaN; t_solutions(i) = NaN; stabilities{i} = 'NaN'; end end
% Display solutions and stabilities disp('Solutions for each m:'); for i = 1:length(m_values) fprintf('m = %.2f, k = %.4f, t = %.4f, Stability = %s\n', m_values(i), k_solutions(i), t_solutions(i), stabilities{i}); end
% Plot solutions figure; plot(m_values, k_solutions, '-o', 'DisplayName', 'k'); hold on; plot(m_values, t_solutions, '-o', 'DisplayName', 't'); xlabel('m'); ylabel('Values'); title('Solutions as a Function of m'); legend('k', 't'); hold off;
% Plot stability figure; plot(m_values, strcmp(stabilities, 'Stable'), '-o', 'DisplayName', 'Stable'); hold on; plot(m_values, strcmp(stabilities, 'Unstable'), '-o', 'DisplayName', 'Unstable'); xlabel('m'); ylabel('Stability'); title('Stability as a Function of m'); legend('Stable', 'Unstable'); hold off;
Sabrina Garland
2024년 6월 6일
Thanks a ton for your suggestion @Torsten and @Steven. My code is stable where it should be now! I made one teensy error that made all the difference. While comparing eigenvalues I realised that I was getting same eigenvalues on t but with signs reversed and then it hit me - I defined equations in my second code as f(x) - y. While in 1st code I defined it as y-f(x). I couldn't have figured it out if it wasn't for both of you.
Torsten
2024년 6월 7일
As I could see, eigenvalues for t are near zero but eigenvalues for k are quite large.
The equations are not separable - there are no eigenvalues for t and eigenvalues for k. So you cannot say that the system is stable with respect to t and unstable with respect to k or something similar.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)