Unable to perform assignment because the left and right sides have a different number of elements

1 vue (au cours des 30 derniers jours)
So, i was testing some filters, when I recieved the error in the title. After some fiddling, I arrived to conclusion that i must be making a mistake by using r and dm variables as vectors. Or I am missing something?
% Constants
r = [0, 0, 0.078, 0.079, 0.079, 0.079];
s = 2;
dm = [0, 1, 1, 1, 3, 9];
% Initialize vectors
N = 300;
x1 = zeros(N, 1);
x2 = zeros(N, 1);
% Initial conditions
x1(1) = 1001;
x2(1) = 50;
% Simulate deterministic discrete-time dynamical system
for k = 1:N
x1(k+1) = (1+r)*x1(k) - s*x2(k);
if x1(k) > 1000
x2(k+1) = x2(k) + dm;
else
x2(k+1) = x2(k) - dm;
end
% Restrict to [0, 100]
x2(k+1) = max(0, min(x2(k+1), 100));
end
% Adding the stability testing
if x1(N) < 0
disp ("bancrupt")
elseif x1(N) > 2*x1(1)
disp ("rich")
else
disp ("stable")
end
  5 commentaires
Mathieu NOE
Mathieu NOE le 1 Fév 2021
or it could work if you would make x1 and x2 as 2D matrixes...

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Address Missing Coverage dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by