Assignment:
import matplotlib.pyplot as plt
import numpy as np
from sympy.parsing.sympy_parser import parse_expr
z = "-2*(x4)+5*(x3)+4*x+7"
b= parse_expr(z)
print(b)
func=sym.lambdify(x,b,"numpy")
x_num=np.linspace(0,10,1000)
y_num=2
plt.plot(x_num,func(x_num))
plt.show()
So there is 3 errors/problems in the problem terminal of studio code.
Import matploblib
x is not defined
sym.lambdify is not defined
First install the libaries:
Open a cmd/prompt and write:
pip install numpy
pip install matplotlib
pip install sympy
Next problem, x is not defined, so you declare x as such:
x = symbols('x')
last problem, says sym.lambdify is not defined.
sym is not a function
It's sum.
But it's also not what we looking for, it is prewritten lambdify only.
Not an operation on it.
So we also need to import the lib, lambdify, from the sympy
result:
import matplotlib.pyplot as plt
import numpy as np
from sympy import symbols, lambdify ## < From symport we are importing Lambdify a module in matploblip
from sympy.parsing.sympy_parser import parse_expr
x = symbols('x') ## < Declaring Variable X, that was previously not declared
z = "-2*(x4)+5*(x3)+4*x+7"
b= parse_expr(z)
print(b)
func=lambdify(x, b,"numpy") ## < Fixing syntax error it's just func=lambdify, a module prewritten in matploblib ## X is now declared
x_num=np.linspace(0,10,1000)
y_num=2
plt.plot(x_num,func(x_num))
plt.show()