Seguimos buscando a Arshak. Ayudanos compartiendo!
Encuesta no oficial de docentes
Resultados de la encuesta no oficial de docentes
Probaste el SIGA Helper?

Donar $100 Donar $200 Donar $500 Donar mensualmente


Enviar respuesta 
 
Calificación:
  • 0 votos - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
Buscar en el tema
algoritmo para logaritmos
Autor Mensaje
LeaTex Sin conexión
Presidente del CEIT
.
********

Ing. en Sistemas
Facultad Regional Buenos Aires

Mensajes: 4.848
Agradecimientos dados: 56
Agradecimientos: 264 en 55 posts
Registro en: Apr 2008
BlogSpot Facebook Google+ Last.fm LinkedIn Twitter
YouTube
Mensaje: #1
algoritmo para logaritmos
en base a una consulta por ahí de cómo calcular logaritmos a mano, me puse a investigar un poco y se me ocurrió hacer un pequeño algoritmo que calcule el logaritmo de un número, usando mi lenguaje predilecto.

si se animan pueden testearlo o poner algoritmos en otros lenguajes.



| funcCaract funcMant logaritmo logaritmoNeperiano logaritmoNatural precision |

precision := 3.

funcCaract := [:b :a :c :f | | cc |
cc := c.
(a < b)
ifTrue: [
(a < 1)
ifTrue: [f valueWithArguments: (Array with: b with: (a raisedTo: -1) with: c with: f)]
ifFalse: [Array with: cc with: a]]
ifFalse: [cc := f valueWithArguments: (Array with: b with: (a/b) with: c+1 with: f)]].

funcMant := [:b :r :m :p :c :f |
(p > 0) ifTrue: [
(r < b)
ifTrue: [m at: p put: c.
f valueWithArguments: ((OrderedCollection new) add: b; add: (r raisedTo: 10); add: m; add: (p-1); add: 0; add: f; yourself) asArray]
ifFalse: [f valueWithArguments: ((OrderedCollection new) add: b; add: (r/b); add: m; add: p; add: c+1; add: f; yourself) asArray]].
m].

logaritmo := [:base :argumento | | caracteristica mantisaCalc mantisa result |
caracteristica := 0.
mantisaCalc := 0.
mantisa := (Array new: precision+2) atAllPut: 0; yourself.
(argumento <= 0) ifTrue: [Error signal: 'el argumento debe ser positivo'].
(argumento = 1)
ifFalse: [(argumento = base)
ifTrue: [caracteristica := 1]
ifFalse: [result := funcCaract valueWithArguments: (Array with: base with: argumento with: 0 with: funcCaract).
caracteristica := result at: 1.
result := funcMant valueWithArguments: ((OrderedCollection new) add: base; add: ((result at: 2) raisedTo: 10); add: mantisa; add: precision+2; add: 0; add: funcMant; yourself) asArray]].
mantisa reverse doWithIndex: [:dec :i | mantisaCalc := mantisaCalc + (dec / (10 raisedTo: i))].
(((caracteristica + mantisaCalc) roundTo: (10 raisedTo: precision negated)) * ((argumento < 1) ifTrue: [-1] ifFalse: [1])) asFloat ].

logaritmoNeperiano := [:argumento | logaritmo value: Float e value: argumento ].
logaritmoNatural := [:argumento | logaritmo value: 10 value: argumento ].

"-- pruebas --"
Transcript cr; show: 'log 30 = '; show: (logaritmo value: 10 value: 30) printString.
Transcript cr; show: 'log 5 = '; show: (logaritmoNatural value: 5) printString.
Transcript cr; show: 'log 10 = '; show: (logaritmoNatural value: 10) printString.
Transcript cr; show: 'ln e = '; show: (logaritmoNeperiano value: Float e) printString.



(Este mensaje fue modificado por última vez en: 16-08-2015 03:52 por LeaTex.)
16-08-2015 02:37
Visita su sitio web Encuentra todos sus mensajes Agregar agradecimiento Cita este mensaje en tu respuesta
[-] LeaTex recibio 2 Gracias por este post
Joke (17-08-2015), rod77 (17-08-2015)
LeaTex Sin conexión
Presidente del CEIT
.
********

Ing. en Sistemas
Facultad Regional Buenos Aires

Mensajes: 4.848
Agradecimientos dados: 56
Agradecimientos: 264 en 55 posts
Registro en: Apr 2008
BlogSpot Facebook Google+ Last.fm LinkedIn Twitter
YouTube
Mensaje: #2
RE: algoritmo para logaritmos
bueno, después de muchas pruebas en el entorno del foro, logré hacerlo funcionar.

me tiraba errores por todos lados, al parecer está bastante limitada la implementación, pero finalmente lo logré.

si le aumentan la precisión, o si utilizan un argumento muy grande, no van a conseguir resultados acá porque la recursión es muy grande y hace que se rompa. pero en un IDE en serio (como pharo) pueden probar números enormes con una gran precisión.



Transcript show: 50 ln printString



(Este mensaje fue modificado por última vez en: 16-08-2015 04:01 por LeaTex.)
16-08-2015 03:59
Visita su sitio web Encuentra todos sus mensajes Agregar agradecimiento Cita este mensaje en tu respuesta
LautaroCutri Sin conexión
Campeon del cubo Rubik
Re Bien!!
****

Ing. en Sistemas
Facultad Regional Buenos Aires

Mensajes: 142
Agradecimientos dados: 11
Agradecimientos: 9 en 8 posts
Registro en: Sep 2014
Mensaje: #3
RE: algoritmo para logaritmos
+10

[Imagen: Wn6vpAn.png]
16-08-2015 14:34
Visita su sitio web Encuentra todos sus mensajes Agregar agradecimiento Cita este mensaje en tu respuesta
Joke Sin conexión
Empleado de Fotocopiadora
En la práctica la teoría es ...
**

Ing. en Sistemas
Facultad Regional Resistencia

Mensajes: 31
Agradecimientos dados: 30
Agradecimientos: 3 en 3 posts
Registro en: Dec 2012
Mensaje: #4
RE: algoritmo para logaritmos
Muy bueno! Está programado en SmallTalk no?
17-08-2015 14:53
Encuentra todos sus mensajes Agregar agradecimiento Cita este mensaje en tu respuesta
LeaTex Sin conexión
Presidente del CEIT
.
********

Ing. en Sistemas
Facultad Regional Buenos Aires

Mensajes: 4.848
Agradecimientos dados: 56
Agradecimientos: 264 en 55 posts
Registro en: Apr 2008
BlogSpot Facebook Google+ Last.fm LinkedIn Twitter
YouTube
Mensaje: #5
RE: algoritmo para logaritmos
(17-08-2015 14:53)Joke escribió:  Muy bueno! Está programado en SmallTalk no?

así es.

17-08-2015 17:06
Visita su sitio web Encuentra todos sus mensajes Agregar agradecimiento Cita este mensaje en tu respuesta
Buscar en el tema
Enviar respuesta 




Usuario(s) navegando en este tema: 1 invitado(s)