In [1]:
import sympy
from sympy import Eq,solve
from sympy.abc import x,y
sympy.init_printing()
In [2]:
f = lambda x: (2*x+2)/(x-1)
enacba = Eq(f(y),x)
enacba
Out[2]:
In [3]:
resitve = solve(enacba,y) # izrazimo y
resitve
Out[3]:
In [4]:
invf = sympy.lambdify(x,resitve[0])
Eq(y,invf(x))
Out[4]:
Narišimo še grafe funkcij. Uporabimo lahko funkcijo plot
iz knjižnice matplotlib
.
In [5]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
t = np.linspace(-8,8,200)
fig, ax = plt.subplots()
plt.plot(t,f(t),'.',label="$f(x)$")
plt.plot(t,invf(t),'.',label="$f^{-1}(x)$")
plt.plot(t,t,'k',label="$y=x$")
ax.axis("equal")
plt.ylim(-5,5)
ax.legend(loc=2)
# set the x-spine (see below for more info on `set_position`)
ax.spines['left'].set_position('zero')
# turn off the right spine/ticks
ax.spines['right'].set_color('none')
ax.yaxis.tick_left()
# set the y-spine
ax.spines['bottom'].set_position('zero')
# turn off the top spine/ticks
ax.spines['top'].set_color('none')
ax.xaxis.tick_bottom()
In [6]:
t = np.linspace(0,2)
plt.plot(t,2**t,label="$y=2^x$")
plt.plot(t,3+np.zeros(t.shape),label="$y=3$")
plt.grid()
plt.legend()
plt.title(" $y=3$ prenemo na graf funkcije in odčitamo $x$")
Out[6]:
Vrednost $\log_2(3)$ je rešitev enačbe $3=e^x$ in je približno enaka $1.6$.
In [7]:
np.log(3)/np.log(2)
Out[7]:
In [8]:
import disqus
%reload_ext disqus
%disqus matpy