Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Some trouble with difference equations

1 Ansicht (letzte 30 Tage)
paul
paul am 15 Feb. 2012
Geschlossen: MATLAB Answer Bot am 20 Aug. 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 Kommentare
Andrew Newell
Andrew Newell am 15 Feb. 2012
What are your starting values for r, y, etc.?
Andrew Newell
Andrew Newell am 15 Feb. 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?

Antworten (1)

Rick Rosson
Rick Rosson am 16 Feb. 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 Kommentare
Rick Rosson
Rick Rosson am 16 Feb. 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 am 16 Feb. 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.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by