Funcions definides a trossos¶
Dissenya la funció
fun_mat_1que avaluï la següent funció matemàtica per un valor real,x, donat. La funció ha de retornar un valor real.\[\begin{split}f(x) = \begin{cases} \frac{5x-1}{\sqrt{\lvert x-1 \rvert}} & x<=-1 \\ 2^{x} & x>-1 \end{cases}\end{split}\]Desa la funció al fitxer
fun_mat_1.py. La funció ha de passar el següent doctest:>>> round(fun_mat_1(-104.2), 2) -50.89 >>> round(fun_mat_1(-1.8), 2) -5.98 >>> round(fun_mat_1(-1.0), 2) -4.24 >>> round(fun_mat_1(0.0), 2) 1.0 >>> round(fun_mat_1(3.5), 2) 11.31 >>> round(fun_mat_1(10.0), 2) 1024.0
Nota
Podeu descarregar el fitxer amb tests
fun_mat_1.txtDissenya la funció
fun_mat_2que avaluï la següent funció matemàtica per dos valors reals,xiy, donats. La funció ha de retornar un valor real.\[\begin{split}g(x,y) = \begin{cases} \frac{x^2-y^2}{e^{x+y}-1} & x>-y, \\ 2^x & x=-y, \\ \frac{\sin (x^2-y^2)}{x+y} & x<-y. \end{cases}\end{split}\]Desa la funció al fitxer
fun_mat_2.py. La funció ha de passar el següent doctest:>>> round(fun_mat_2(4.2, 4.2), 4) 0.0 >>> round(fun_mat_2(-0.3, 0.7), 4) -0.8133 >>> round(fun_mat_2(20.9, -11.1), 4) 0.0174 >>> round(fun_mat_2(10.0, -10.0), 4) 1024.0 >>> round(fun_mat_2(0.0, 0.0), 4) 1.0 >>> round(fun_mat_2(0.3, -0.3), 4) 1.2311 >>> round(fun_mat_2(-5.5, 4.2), 4) -0.0336 >>> round(fun_mat_2(0.0, -11.1), 4) -0.0572
Nota
Podeu descarregar el fitxer amb tests
fun_mat_2.txtDissenya la funció
fun_mat_3que avaluï la següent funció matemàtica per dos valors reals,xiy, donats. La funció ha de retornar un valor real.\[\begin{split}h(x,y) = \begin{cases} x^2+y, & \mbox{si } x>=1\\ sin(x), & \mbox{si } 0<x<1\\ y*cos(x), & \mbox{si } x<=0 \end{cases}\end{split}\]Desa la funció al fitxer
fun_mat_3.py. La funció ha de passar el següent doctest:>>> round(fun_mat_3(4.2, 4.2), 4) 21.84 >>> round(fun_mat_3(1.0, 0.7), 4) 1.7 >>> round(fun_mat_3(0.9, -11.1), 4) 0.7833 >>> round(fun_mat_3(0.15, 0.0), 4) 0.1494 >>> round(fun_mat_3(-5.5, 4.2), 4) 2.9764 >>> round(fun_mat_3(-0.7, -11.1), 4) -8.4897
Nota
Podeu descarregar el fitxer amb tests
fun_mat_3.txt
Solució
Disposeu de solucions als fitxers fun_mat_1.py, fun_mat_2.py, fun_mat_3.py