Plotting an ELU function with GNU Octave
Alexandru Munteanu <[email protected]>
| Newsgroups | gmane.comp.gnu.octave.general |
|---|---|
| Organization | West University of Timișoara |
| Message-ID | <[email protected]> |
Hello,
I am trying to create plots for an ELU (Exponential Liniear Unit)
funciton. The function is defined as follows:
function e = elu(z, alpha)
if z >= 0
e = z
else
e = alpha * ((exp(z)) - 1)
endif
endfunction
So this is pretty simple so far (alpha is a constant of values 0.01),
and I can test to evaluate it in the interpreter and everything is
working as expected.
However, I want to plot the values of elu(x), where x belongs to the
interval (-5, 5).
function plot_elu
x = -5:0.01:5
y = elu(x, 0.01)
plot(x, y, "linewidth", 5)
set(gca,"fontsize", 25)
axis([-6, 6, -1.2, 1.2])
grid on;
endfunction
This is where the plot goes wrong: it creates the plot as if the values
for elu are all going on the second branch of the if-then-else
statement.
I have attached what the plot looks like. Any help in this direction is appreciated.
--
Alexandru Munteanu
elu.png
(image/png, 25.5 KB) - not displayed
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEXCSdNtOuHQI4zFhkSYeGi1biKfYFAmAcPjcACgkQSYeGi1bi KfY8CQ//Sm4HGwLjtBPnXSa6CzdDFBIJ4TAGEvmE6RcL2LIZDoHOIigaL+cdR/+r 8gTzLB5IxXsVCsR1xuMSmjO7hHeDW32zo6Pf155fMe6oDEaCuhjMi7UMobUBA+kR hsgdtqR0epWMh8AflOSSNaOjstDlTwC+W59X55dcc+PMi3xcsk/ZG+65BHl1e0li TfDOCctLic4+cMl6PHfNVDaNnnOwfrw+7RVWwbKYjD/wg11RRBZZpRxch78AAZt3 HRWHDOBxlWce5VWFUou5yOpClY1cCNQ6RuiexNSWZn345a7pAVXFtkgoIx+JlIyL B1HafjU263m5FbGO4ewTgQu/Cr5tFmQwMqQ9zbHtllInztKThTZvQcNqVRlauwdw RFPA0rFqyqh5YKah/bo3/MojLbRV98AMX/Lu9+5J9oyRLfgQ1UBfs+n0Cd1qqzQ/ GKi58ayqF0+NWcm5298SMka/NN9Px3OOny7ADC9KRbOXz3rH6cdok3NADIERWFM1 9+sGjXg82PNCafkxoUrxo0KxpmwyowfCDEV9/whzUyxuzTxQqe7CXlvcx7DPQtXU Lk339qiMoru6F7sBdMxGlq4kGiUZ8Gl3J+n1KvkaZUII+QOM2lGPH4Ua3/NPLUba ggAonXkhmMkHW7e17qhM5LEfr66riK1J+nB04IuW0dEJ6OlW8OQ= =RpFL -----END PGP SIGNATURE-----