- Get first row of x1.
- Get first column of x2.
- Make A into row vector.
- Make a new vector from row of x1 and column of x2.
- Do element wise multiplication to get result.
How can I easily plot a system of linear equations?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I would like to quickly plot a vector field of a system of first-order linear equations, for example:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/206470/image.png)
Which I made using:
clear,clc
A = [1, 1;
4, 1;]
[x1,x2]=meshgrid(-2:0.2:2,-2:0.2:2);
x1=flip(x1);
x1dot=zeros(length(x1),length(x2));
x2dot=x1dot;
for i=1:length(x1)
for j=1:length(x2)
x1dot(i,j) = A(1,1)*x1(1,i) + A(1,2)*x2(j,1);
x2dot(i,j) = A(2,1)*x1(1,i) + A(2,2)*x2(j,1);
end
end
x1dotn= x1dot./sqrt(x1dot.^2+x2dot.^2);
x2dotn= x2dot./sqrt(x1dot.^2+x2dot.^2);
quiver(x2,x1,x1dotn,x2dotn);
This works fine, however I feel like this is quite cumbersome and could be done more elegantly and easier? Perhaps there is even a function for it I missed?
0 commentaires
Réponses (1)
Harshit Jain
le 4 Mar 2019
Since you are using only the first row of x1 and first column of x2, you can vectorize this implementation.
Steps which you can do.
These are not exact steps but a rough idea so that you can use this to solve the problem.
0 commentaires
Voir également
Catégories
En savoir plus sur Animation 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!