python中带范围的图函数

python中带范围的图函数,python,matplotlib,graph,Python,Matplotlib,Graph,这是我关于stackoverflow的第一个问题,如果我丢失了一些数据,他们告诉我,我需要的是用python语言创建一个函数图,但我没有找到关于如何创建的信息,我找到了如何创建图,但没有找到函数的限制 我需要在python中绘制的图形类似于此函数的范围 这就是函数 { V₁x 0 ≤ x < a { V₁x - q(x-a)/2 a ≤ x ≤ a+l # probably it's q(x-a)²/2 M(x) = { V₂(L-

这是我关于stackoverflow的第一个问题,如果我丢失了一些数据,他们告诉我,我需要的是用python语言创建一个函数图,但我没有找到关于如何创建的信息,我找到了如何创建图,但没有找到函数的限制

我需要在python中绘制的图形类似于此函数的范围
这就是函数

       { V₁x             0 ≤ x < a
       { V₁x - q(x-a)/2  a ≤ x ≤ a+l  # probably it's q(x-a)²/2
M(x) = { V₂(L-x)         a+l < x ≤ L
       { 0               otherwise



from matplotlib import pyplot as plt
x1 = [40, 50, 60, 70, 80, 90, 100]
y1 = [40, 50, 60, 70, 80, 90, 100]
plt.plot(x1, y1)
plt.xlabel('Like Geeks X Axis')
plt.ylabel('Like Geeks Y Axis')
axes = plt.axes()
axes.set_xlim([4, 8])
axes.set_ylim([-0.5, 2.5])
plt.show()
{V₁x0≤ x
我想你可以创建一个函数来复制你的数学公式,然后用这个函数得到y

如果您需要代码是通用的,请按如下方式执行:

从matplotlib导入pyplot作为plt
def create_功能(V1、V2、a、l、q、l):
def f(x):
如果x>=0且xelif x>=a和xa+l和x我想你可以创建一个函数来复制你的数学公式,然后用这个函数得到y

如果您需要代码是通用的,请按如下方式执行:

从matplotlib导入pyplot作为plt
def create_功能(V1、V2、a、l、q、l):
def f(x):
如果x>=0且xelif x>=a和x a+l和x如果我理解您的意图,绘制部分承受恒定分布荷载的梁的弯矩图,这是您的图表

这里是产生它的代码…但首先是一些初步的评论

  • 如果它真的是弯矩,那么它的定义是错误的,我冒昧地修改了你的定义
  • Matplotlib(及其兄弟Numpy)不涉及符号的操作(如果需要,请查看Sympy),因此所有涉及的量q、l、a和l都必须指定为数字
也就是说,这是代码

import matplotlib.pyplot as plt

def M(L, a, l, q, npoints=201):
    # npoints is an OPTIONAL argument with a default value
    from numpy import linspace, where
    # we MATERIALIZE our x axis as a sequence of points, an array in Python-speak
    x = linspace(0, L, npoints)
    # compute the reactions
    V2 = (l*q)*(a+l/2) / L
    V1 = l*q-V2
    # compute the bending moment,
    # our where is similar to Excel "IF()" function, if you know Excel 
    bm = where(x<a, V1*x, where(x<a+l, V1*x - q*(x-a)**2/2, V2*(L-x)))
    # the caller of this function wants to know the points in the arrays x and bm
    return x, bm

# L = 10 units of length, a = 4, l = 2;  q = 40 units of force per unit of length
x, bm = M(10, 4, 2, 40) # note: no optional npoints, 201 points will be used

fig, ax = plt.subplots()
ax.plot(x, bm)
# good mannered individuals plot the bending moment on the side of tension stresses
# so we invert the y axis
ax.invert_yaxis()
ax.grid()
plt.show()
导入matplotlib.pyplot作为plt
defm(L,a,L,q,npoints=201):
#npoints是具有默认值的可选参数
从numpy导入linspace,其中
#我们将x轴具体化为一系列点,Python中的数组
x=linspace(0,L,npoints)
#计算反应
V2=(l*q)*(a+l/2)/l
V1=l*q-V2
#计算弯矩,
#如果您知道Excel,我们的where类似于Excel的“IF()”函数

bm=式中(x如果我理解您的意图,绘制部分承受恒定分布荷载的梁的弯矩图,这是您的图表

这里是产生它的代码…但首先是一些初步的评论

  • 如果它真的是弯矩,那么它的定义是错误的,我冒昧地修改了你的定义
  • Matplotlib(及其兄弟Numpy)不涉及符号的操作(如果需要,请查看Sympy),因此所有涉及的量q、l、a和l都必须指定为数字
也就是说,这是代码

import matplotlib.pyplot as plt

def M(L, a, l, q, npoints=201):
    # npoints is an OPTIONAL argument with a default value
    from numpy import linspace, where
    # we MATERIALIZE our x axis as a sequence of points, an array in Python-speak
    x = linspace(0, L, npoints)
    # compute the reactions
    V2 = (l*q)*(a+l/2) / L
    V1 = l*q-V2
    # compute the bending moment,
    # our where is similar to Excel "IF()" function, if you know Excel 
    bm = where(x<a, V1*x, where(x<a+l, V1*x - q*(x-a)**2/2, V2*(L-x)))
    # the caller of this function wants to know the points in the arrays x and bm
    return x, bm

# L = 10 units of length, a = 4, l = 2;  q = 40 units of force per unit of length
x, bm = M(10, 4, 2, 40) # note: no optional npoints, 201 points will be used

fig, ax = plt.subplots()
ax.plot(x, bm)
# good mannered individuals plot the bending moment on the side of tension stresses
# so we invert the y axis
ax.invert_yaxis()
ax.grid()
plt.show()
导入matplotlib.pyplot作为plt
defm(L,a,L,q,npoints=201):
#npoints是具有默认值的可选参数
从numpy导入linspace,其中
#我们将x轴具体化为一系列点,Python中的数组
x=linspace(0,L,npoints)
#计算反应
V2=(l*q)*(a+l/2)/l
V1=l*q-V2
#计算弯矩,
#如果您知道Excel,我们的where类似于Excel的“IF()”函数

bm=这能回答你的问题吗?安德烈斯,你确定区间
a@sophros据我理解,你提到的问题是关于a(误解)表示具有单点不连续性的函数的方法,因此这里给出的答案不适用。这是否回答了您的问题?Andres,您确定区间
a@sophros据我理解,你提到的问题是关于a(误解)表示具有单点不连续性的函数的方法,因此这里给出的答案不适用。