System of Difference Equation: Cobweb model in interelated markets

5 次查看(过去 30 天)
Hi everybody. I am having problems in solving a system of two difference equation (order=1). I do not find the right procedure and i am not able to write the script. The system is this:
x(t)= -0.4x(t-1)
y(t)= 0.4x(t-1) - 0.5y(t-1)
The aim is to graphically show if the solution X(T)=0 is in equlibrium. Thus, the procedure should calculate eigenvector and eigenvalues and allow me to define C1 and C2 in the general solution. Thank you! I attached the exercise file below.

回答(1 个)

Vinayak
Vinayak 2024-1-10
Hi Massimiliano,
I understand you want to calculate eigen values and eigen vectors for the given set of equations. I have created a sample code to solve the equations you provided, you can adjust the values of C1 and C2 before calculating the initial conditions using the eigen vectors.
% Define the system matrix A
A = [-0.4, 0;
0.4, -0.5];
% Calculate eigenvalues and eigenvectors
[eigenvectors, eigenvalues] = eig(A);
% Set the number of iterations (time steps)
num_iterations = 50;
% Initialize arrays to store the solutions
x_vals = zeros(1, num_iterations);
y_vals = zeros(1, num_iterations);
% Adjust C1 C2 and initial conditions using eigenvectors
C1 = 1;
C2 = 1;
initial_conditions = C1 * eigenvectors(:,1) + C2 * eigenvectors(:,2);
% Set initial values
x_vals(1) = initial_conditions(1);
y_vals(1) = initial_conditions(2);
% Iterate and compute the solution
for t = 2:num_iterations
Z = A * [x_vals(t-1); y_vals(t-1)];
x_vals(t) = Z(1);
y_vals(t) = Z(2);
end
% Plot the solutions
figure;
plot(0:num_iterations-1, x_vals);
figure;
plot(0:num_iterations-1, y_vals);
% Check if the system is in equilibrium
if all(abs(diag(eigenvalues)) < 1)
disp('The system is stable and the equilibrium X(T) = 0 is reached.');
else
disp('The system is unstable and the equilibrium X(T) = 0 is not reached.');
end
You may refer to the following documentation link for more information abouteig” function:
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Dynamic System Models 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by