Funcions matemàtiques¶
Dissenyeu una funció en Python equivalent a cadascuna de les
definicions de funcions matemàtiques donades. Utilitzeu el mateix nom
de la definició matemàtica com a nom de les funcions en Python. Deseu
totes les funcions al mateix mòdul funcmat.py.
\(f(x) = \frac{5}{2}x^4 + \frac{x^2}{6} + 7\). La funció ha de passar el següent doctest:
>>> a = f(0.0) >>> print(round(a, 4)) 7.0 >>> print(round(f(10.1), 4)) 26039.1019 >>> print(round(f(-1.4), 4)) 16.9307 >>> print(round(f(6.0), 4)) 3253.0 >>> print(round(f(-0.12345), 4)) 7.0031
Nota
Podeu descarregar el fitxer amb tests
test-funcmat1.txt.\(g(x)= \frac{(3x-2)}{2} + \frac{(x-7)^3}{7} + 2\) La funció ha de passar el següent doctest:
>>> print(round(g(0.0), 4)) -48.0 >>> print(round(g(7.0), 4)) 11.5 >>> print(round(g(1.2345), 4)) -24.527 >>> print(round(g(-123.45), 4)) -317311.8987 >>> print(round(g(2.222), 4)) -11.2496
Nota
Podeu descarregar el fitxer amb tests
test-funcmat2.txt.\(h(x,y) = \frac{y \sin x}{y^2-4}\). Suposeu que el paràmetre x està expressat en graus.
La funció ha de passar el següent doctest:
>>> print(round(h(0.0, 0.0), 4)) -0.0 >>> print(round(h(45.0, 1.99), 4)) -35.2667 >>> print(round(h(90.0, 0.0), 4)) -0.0 >>> print(round(h(-90.0, 2.4), 4)) -1.3636 >>> print(round(h(360.0, 0.0), 4)) 0.0
Nota
Podeu descarregar el fitxer amb tests
test-funcmat3.txt.Què passa si avaluem aquesta funció en el punt (1,2)?
Fent crides a les funcions definides als apartats anteriors, dissenya la funció \(k(x)= \sqrt{f(x)}-g(x^2)\). La funció ha de passar el següent doctest:
>>> print(round(k(0.0), 4)) 50.6458 >>> print(round(k(2.0), 4)) 3.7612 >>> print(round(k(-20.0), 4)) -8671176.6291 >>> print(round(k(9.876), 4)) -106005.465 >>> print(round(k(0.00836345), 4)) 50.6442 >>> print(round(k(-1.01111), 4)) 31.108
Nota
Podeu descarregar el fitxer amb tests
test-funcmat4.txt.
Solucions
Disposeu de solucions al fitxer funcmat.py.