In [4]:
import math
import sympy
from sympy import latex
from IPython.display import HTML, display
%matplotlib notebook
sympy.init_printing()
Podana je funkcija $f(x)=x^2 e^{-x}$.
In [5]:
x = sympy.symbols('x')
f = lambda x: x**2 * sympy.E**(-x)
Doloci definicijsko obmocje ${\cal D}_f$ in izracunaj limiti v robovih ${\cal D}_f$.
Ker je eksponentna funkcija definirana povsod, je ${\cal D}_f = \mathbb{R}$.
$\displaystyle{\lim_{x\to\infty} x^2 e^{-x} = 0}.$
$\displaystyle{\lim_{x\to -\infty} x^2 e^{-x} = \infty}.$
Poisci nicle in stacionarne tocke funkcije $f$.
In [6]:
equation = sympy.Eq(f(x), 0)
equation
Out[6]:
In [7]:
solutions = sympy.solve(equation)
s = 'Nicle: ${0}$'.format(latex(solutions))
display(HTML(s))
In [8]:
derivative = sympy.diff(f(x), x)
equation = sympy.Eq(derivative, 0)
equation
Out[8]:
In [9]:
solutions = sympy.solve(equation)
s = 'Stacionarne tocke: ${0}$'.format(latex(solutions))
display(HTML(s))
Narisi graf funkcije $f$.
In [10]:
sympy.plotting.plot(f(x), (x, -1, 5))
Out[10]:
Izracunaj nedoloceni integral racionalne funkcije $$\int \frac{x}{(x-1)(x-2)}.$$
In [14]:
f = lambda x: x/((x-1)*(x-2))
sympy.integrate(f(x))
Out[14]:
Z integracijo po delih izracunaj $$\int_{0}^{\pi}x\cos(x)dx.$$
In [15]:
f = lambda x: x*sympy.cos(x)
sympy.integrate(f(x))
Out[15]:
Resi linearno diferencialno enacbo prvega reda $$ y' - \frac{y}{x} = 2x^2.$$
In [16]:
f = sympy.symbols('f', cls=sympy.Function)
equation = sympy.Eq(f(x).diff(x)-f(x)/x, 2*x**2)
equation
Out[16]:
In [17]:
solution = sympy.dsolve(equation, f(x))
solution
Out[17]:
Upostevajmo se robni pogoj.
In [18]:
equation = solution.subs(f(x), 2).subs(x, 1)
equation
Out[18]:
In [19]:
c1 = sympy.solve(equation)[0]
C1 = sympy.symbols('C1')
sympy.expand(solution.subs(C1, c1))
Out[19]:
Turist si v cerkvi ogleduje 3m visoko okno, ki se nahaja 1m nad njegovimi ocmi. Kako dalec od stene, na kateri se nahajo okno, naj se postavi, da bo razlika kotov pod katerimi vidi spodnji in zgornji kot okna najvecja?
Najprej nastavimo enacbo. Kot, pod katerim iz razdalje $x$ vidimo spodnji del okna $\arctan(\frac{1}{x})$, zgorjnji del pa vidimo pod kotom $\arctan(\frac{4}{x})$.
In [20]:
f = lambda x: sympy.atan(4/x) - sympy.atan(1/x)
f(x)
Out[20]:
Kandidati za resitev so stacionarne tocke zgornje funkcije, torej nicle njenega odvoda. Pri tem dodatno zahtevamo, da so resitve pozitivne.
In [24]:
x = sympy.symbols('x', positive=True)
equation = sympy.Eq(f(x).diff(x), 0)
equation
Out[24]:
In [25]:
solutions = sympy.solve(equation)
solutions
Out[25]:
Postaviti se mora 2 metra od stene.