How do I plot the dynamics of agents influencing each other?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I want to plot the influence of agents on each other in a graph. For this example, I have three agents :
k=1
x1(k)=10;
x2(k)=20;
x3(k)=30;
With k being a time step. The influence on each other will be calculated with factors in Matrix A:
A=[a11 a12 a13; a21 a22 a23; a31 a32 a33];
a11=0.1;
a12=0.2;
a13=0.3;
a21=0.4;
a22=0.5;
a23=0.6;
a31=0.7;
a32=0.8;
a33=0.9;
I want to model the influences with:
n=10;
for k=1:n;
x(k)=[x1(k);x2(k);x3(k)];
x(k+1)=A*x(k)
plot(k,x(k))
end
However, I get these errors:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in impexss (line 23)
x(k)=[x1(k);x2(k);x3(k)];
This is probably because x(k) increases in size, but I don't want it to.
Ultimately I want to see something like this in matrix form:
x1(k+1)=a11*x1(k)+a12*x2(k)+a13*x3(k);
x2(k+1)=a21*x1(k)+a22*x2(k)+a23*x3(k);
x3(k+1)=a31*x1(k)+a32*x2(k)+a33*x3(k);
x1(k+2)=a11*x1(k+1)+a12*x2(k+1)+a13*x3(k+1)
x2(k+2)=a21*x1(k+1)+a22*x2(k+1)+a23*x3(k+1)
x3(k+2)=a31*x1(k+1)+a32*x2(k+1)+a33*x3(k+1)
But I cannot figure how to code this. I also want to plot this. Could anyone please help?
Thanks in advance.
0 commentaires
Réponses (1)
Sindhu Karri
le 25 Nov 2020
Hii David,
Hope below attached code helps you
x1(1)=10;
x2(1)=20;
x3(1)=30;
A=[0.1,0.2,0.3;0.4,0.5,0.6;0.7,0.8,0.9];%a11,a12,a13,a21,a22,a23,a31,a32,a33
n=10;
for k=1:n
x1(k+1)=A(1,1)*x1(k)+A(1,2)*x2(k)+A(1,3)*x3(k);
x2(k+1)=A(2,1)*x1(k)+A(2,2)*x2(k)+A(2,3)*x3(k);
x3(k+1)=A(3,1)*x1(k)+A(3,2)*x2(k)+A(3,3)*x3(k);
end
plot(x3)%plotting
0 commentaires
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing 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!