# coding:utf-8
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-5, 5, 100)
interval0 = [1 if (abs(i)<=1) else 0 for i in x]
interval1 = [1 if (2>abs(i)>1) else 0 for i in x]
interval2 = [1 if (5>abs(i)>=2) else 0 for i in x]
y = ( 1-2*abs(x)**2+abs(x)**3)* interval0 + (-1*x**3+5*x**2-8*x+4) * interval1 + 0*interval2
plt.plot(x,y)
plt.show()
y = ( 1-2*abs(x)**2+abs(x)**3)* interval0 + (-1*x**3+5*x**2-8*x+4) * interval1 + 0*interval2
ValueError: operands could not be broadcast together with shapes (100,) (0,)
Process finished with exit code 1
uj5u.com熱心網友回復:
報錯是因為陣列維度不一樣轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/147532.html
下一篇:yalmip問題求解
