如何从Python中的一组线性方程中绘制平面?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何从Python中的一组线性方程中绘制平面?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1427字,纯文字阅读大概需要3分钟。
内容图文
我有一个带有三个方程的线性系统:
x1– 2x2 + x3 = 0
2x2
– 8x3 = 8
-4x1 + 5x2 + 9x3 = -9
解集是(29,16,3),它是这些平面交叉处的点.
希望是否有人可以使用Matplotlib在3D空间中绘制这些平面,以清楚地显示问题.
解决方法:
你的第三个等式说:
-4x 5y 9z – 9 = 0
或者一般来说,你的等式是
a x b y c z d = 0
正常是(a,b,c)
>如果a不为0,则平面上的点为(-d / a,0,0)
>如果b不为0,则平面上的点为(0,-d / b,0)
>如果c不为0,则平面上的点为(0,0,-d / c)
将其插入绘图库中,该绘图库采用法向量和平面上的点,并执行3次(每个平面一个).
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
point1 = np.array([0,0,0])
normal1 = np.array([1,-2,1])
point2 = np.array([0,-4,0])
normal2 = np.array([0,2,-8])
point3 = np.array([0,0,1])
normal3 = np.array([-4,5,9])
# a plane is a*x+b*y+c*z+d=0
# [a,b,c] is the normal. Thus, we have to calculate
# d and we're set
d1 = -np.sum(point1*normal1)# dot product
d2 = -np.sum(point2*normal2)# dot product
d3 = -np.sum(point3*normal3)# dot product
# create x,y
xx, yy = np.meshgrid(range(30), range(30))
# calculate corresponding z
z1 = (-normal1[0]*xx - normal1[1]*yy - d1)*1./normal1[2]
z2 = (-normal2[0]*xx - normal2[1]*yy - d2)*1./normal2[2]
z3 = (-normal3[0]*xx - normal3[1]*yy - d3)*1./normal3[2]
# plot the surface
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx,yy,z1, color='blue')
plt3d.plot_surface(xx,yy,z2, color='yellow')
plt3d.plot_surface(xx,yy,z3, color='cyan')
plt.show()
内容总结
以上是互联网集市为您收集整理的如何从Python中的一组线性方程中绘制平面?全部内容,希望文章能够帮你解决如何从Python中的一组线性方程中绘制平面?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。