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

1 Ansicht (letzte 30 Tage)
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 Kommentare

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Address Missing Coverage finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by