Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Some trouble with difference equations

1 visualización (últimos 30 días)
paul
paul el 15 de Feb. de 2012
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hey,
I'm not a heavy matlab user and started programming on ml this weak...
I've got the following problem (whicht i can't solve despite heavy use of google):
I got the following equation system which i want to solve nummeric over time
r(t)=-a_r-b_r*y(t-1)-c_r*ir(t-1)-d_r*lamda(t-1)+r(t-1)
y(t)=a_y+b_y*(ir(t)-pi(t))+c_y*r(t)
pi(t)=a_pi+b_pi*y(t)+c_pi*r(t)
ir(t)=a_i+b_i*y(t)+c_i*pi(t)+d_i*r(t)+e_i*lamda(t)
lamda(t)=a_l+b_l*y(t)+c_l*ir(t)+d_l*pi(t)
the variables indicated with t are the one of interest and start values are given...
the variables a,b,c,d,e are constant coefficients given as well... The problem is to solve for one period and then in the next step for arbitraly many.
I have tried with loops (the problem was to integrate the break condition properly) and fsolve (here i failed to add time index) but came to no conclusion.
I would be very gratefully for any help
lg
  2 comentarios
Andrew Newell
Andrew Newell el 15 de Feb. de 2012
What are your starting values for r, y, etc.?
Andrew Newell
Andrew Newell el 15 de Feb. de 2012
What is your criterion for stopping? Is it a fixed number of time intervals, e.g., 0, dt, 2*dt, ..., n*dt - or perhaps convergence?

Respuestas (1)

Rick Rosson
Rick Rosson el 16 de Feb. de 2012
Please try:
% Number of time steps:
M = 200;
% Number of state variables:
N = 5;
% Pre-allocate data array:
x = zeros(M,N);
% Coefficients for difference equations:
a = [ ... ];
b = [ ... ];
c = [ ... ];
d = [ ... ];
% List of names for the state variables:
varNames = { 'r' 'y' 'pi' 'ir' 'lambda' };
% Time increment:
dt = ... ; % <---- replace ... with desired value
% Time domain:
t = dt*(0:M-1)';
% Initial values:
x(1,:) = [ ... ]; % <---- replace ... with five initial values
% Main Loop - update state variables using difference equations:
for k = 2:M
x(k,1) = ... ;
x(k,2) = ... ;
x(k,3) = ... ;
...
...
end
% Plot results:
figure;
plot(t,x(:,1));
title(varNames{1});
HTH.
  6 comentarios
Rick Rosson
Rick Rosson el 16 de Feb. de 2012
Yes, Walter makes several good points. The code I posted is meant to provide a template that you can use as a starting point. Once you get something that works, you can tweak the code for speed, memory, precision, convergence rate, etc.
Walter Roberson
Walter Roberson el 16 de Feb. de 2012
Additional note that becomes obvious once you know it:
current time (t) is always the initial time plus the sum of the time steps that have been taken.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by