x = sympy.symbols('x')
f = lambda x: x**2 * sympy.E**(-x)

"""
Explanation: OMA 2. kolokvij 2013/2014
1. naloga
Podana je funkcija $f(x)=x^2 e^{-x}$.
End of explanation
"""


equation = sympy.Eq(f(x), 0)
equation

solutions = sympy.solve(equation)
s = 'Nicle: ${0}$'.format(latex(solutions))
display(HTML(s))

derivative = sympy.diff(f(x), x)
equation = sympy.Eq(derivative, 0)
equation

solutions = sympy.solve(equation)
s = 'Stacionarne tocke: ${0}$'.format(latex(solutions))
display(HTML(s))

"""
Explanation: 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$.
End of explanation
"""


sympy.plotting.plot(f(x), (x, -1, 5))

"""
Explanation: Narisi graf funkcije $f$.
End of explanation
"""


f = lambda x: x/((x-1)*(x-2))
sympy.integrate(f(x))

"""
Explanation: 2. naloga
Izracunaj nedoloceni integral racionalne funkcije 
$$\int \frac{x}{(x-1)(x-2)}.$$
End of explanation
"""


f = lambda x: x*sympy.cos(x)
sympy.integrate(f(x))

"""
Explanation: Z integracijo po delih izracunaj
$$\int_{0}^{\pi}x\cos(x)dx.$$
End of explanation
"""


f = sympy.symbols('f', cls=sympy.Function)
equation = sympy.Eq(f(x).diff(x)-f(x)/x, 2*x**2)
equation

solution = sympy.dsolve(equation, f(x))
solution

"""
Explanation: 3. naloga
Resi linearno diferencialno enacbo prvega reda
$$ y' - \frac{y}{x} = 2x^2.$$
End of explanation
"""


equation = solution.subs(f(x), 2).subs(x, 1)
equation

c1 = sympy.solve(equation)[0]
C1 = sympy.symbols('C1')
sympy.expand(solution.subs(C1, c1))

"""
Explanation: Upostevajmo se robni pogoj.
End of explanation
"""


f = lambda x: sympy.atan(4/x) - sympy.atan(1/x)
f(x)

"""
Explanation: 4. naloga
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})$.
End of explanation
"""


x = sympy.symbols('x', positive=True)
equation = sympy.Eq(f(x).diff(x), 0)

equation

solutions = sympy.solve(equation)
solutions

"""
Explanation: Kandidati za resitev so stacionarne tocke zgornje funkcije, torej nicle njenega odvoda. Pri tem dodatno zahtevamo, da so resitve pozitivne.
End of explanation
"""


