System of Difference Equation: Cobweb model in interelated markets

조회 수: 2 (최근 30일)
Massimiliano Garavalli
Massimiliano Garavalli 2022년 3월 2일
답변: Vinayak 2024년 1월 10일
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