绘制隐式函数fx,y= 0,其中x,y进行矩阵乘法

问题描述

作为隐式函数,其中“ A”是n * 2矩阵

0 = np.dot((x,y),A)

0 = xA 11 yA 12

0 = xA 21 yA 22

...

0 = xA n1 yA n2

是否可以通过matplotlib或其他方式在同一图上绘制所有线而不会产生大的循环?

解决方法

给定n*2矩阵A,对于每一行i,一行由A[i,0]*x + A[i,1]*y == 0定义。这意味着0,0和点x=A[i,1],y=-A[i,0]总是在线上。与任何值相乘,例如通过归一化将再次给出在线上的点。

以下代码显示了三种可视化这些行的方法:

  • 一些线段与x=A[i,0]x=-A[i,y=A[i,0]一起切成一个圆。
  • 相同的线段一直延伸到情节的边界。
  • 圆上只有一些终点。
import matplotlib.pyplot as plt
import numpy as np
from numpy.linalg import norm
from matplotlib.collections import LineCollection

n = 10
radius = 20
A = np.random.uniform(-10,10,(n,2))
B = A / norm(A,axis=1,keepdims=True) * radius # normalize and put on a circle with given radius
lines = np.dstack([B[:,-B[:,0],B[:,0]]).reshape(-1,2,2)

fig,axes = plt.subplots(ncols=3,figsize=(14,4))
for ax in axes:
    ax.set_aspect('equal')
for ax in axes[:2]:
    lc = LineCollection(lines,colors='blue',linewidths=2)
    ax.add_collection(lc)
    if ax == axes[0]:
        ax.scatter(A[:,-A[:,color='crimson')
        ax.scatter(-A[:,A[:,color='crimson')
    elif ax == axes[1]:
        ax.set_xlim(-radius / 2,radius / 2)
        ax.set_ylim(-radius / 2,radius / 2)
for k in range(2):
    axes[2].scatter(lines[:,k,lines[:,color='crimson')
axes[0].set_title('lines in circle and dots')
axes[1].set_title('lines till border')
axes[2].set_title('dots on circle')
plt.show()

example plot

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...