- 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?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Harshit Jain
2019-3-4
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!