Azzera filtri
Azzera filtri

How can I easily plot a system of linear equations?

1 visualizzazione (ultimi 30 giorni)
I would like to quickly plot a vector field of a system of first-order linear equations, for example:
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?

Risposte (1)

Harshit Jain
Harshit Jain il 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.
  1. Get first row of x1.
  2. Get first column of x2.
  3. Make A into row vector.
  4. Make a new vector from row of x1 and column of x2.
  5. Do element wise multiplication to get result.
These are not exact steps but a rough idea so that you can use this to solve the problem.
Refer to this link to find more information about how to vectorize.

Categorie

Scopri di più su Animation in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by