加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

如何在Python上绘制一个相似的方程

发布时间:2020-12-20 12:33:49 所属栏目:Python 来源:网络整理
导读:我尝试使用matplotlib在 python上绘制图形,但我不能得到预期的结果. 公式1:1/2 *(w1 w2)1/2 * np.sqrt(4 *(g)** 2(w2-w1)** 2) 公式2:1/2 *(w1 w2) – 1/2 * np.sqrt(4 *(g)** 2(w2-w1)** 2) 我的python代码: import matplotlib.pyplot as pltimport nump
我尝试使用matplotlib在 python上绘制图形,但我不能得到预期的结果.

公式1:1/2 *(w1 w2)1/2 * np.sqrt(4 *(g)** 2(w2-w1)** 2)

公式2:1/2 *(w1 w2) – 1/2 * np.sqrt(4 *(g)** 2(w2-w1)** 2)

我的python代码:

import matplotlib.pyplot as plt
import numpy as np

def W_p(w1,w2,g):
   return 1/2 * (w1 + w2) + 1/2 * np.sqrt(4*(g)**2 + (w2-w1)**2)

def W_m(w1,g):
    return 1/2 * (w1 + w2) - 1/2 * np.sqrt(4*(g)**2 + (w2-w1)**2)

w1 = np.linspace(-10,10,1)
w2 = np.linspace(0.9,1.10,0.1)
g = 1

plt.plot(W_p(w1,g),'r',W_m(w1,'b')

plt.show()

generatad图应该如下图所示:

解决方法

numpy.linspace(start,stop,num=50,endpoint=True,retstep=False,
dtype=None)

Return evenly spaced numbers over a specified interval.

Returns num evenly spaced samples,calculated over the interval
[start,stop].

The endpoint of the interval can optionally be excluded.

Parameters:

start : scalar The starting value of the sequence.

stop :
scalar The end value of the sequence,unless endpoint is set to False.
In that case,the sequence consists of all but the last of num + 1
evenly spaced samples,so that stop is excluded. Note that the step
size changes when endpoint is False.

num : int,optional Number of samples to generate. Default is 50. Must be non-negative.

….

必须改变

w1 = np.linspace(-10,1.1,0.1)

w1 = np.linspace(-10,100)
w2 = np.linspace(0.9,100)

enter image description here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读