plotar expressão simbólica como fórmula matemática?

25 views
Skip to first unread message

padovani

unread,
Sep 15, 2015, 8:43:03 PM9/15/15
to lis...@googlegroups.com
Oi pessoal,

agluma dica de como plotar automaticamente uma s-expression como fórmula matemática? (de preferência simplificando expressões)

por exemplo: queria ver essa expressão aqui como função "f(x) = ...":

(+ (- 38 -42) (cos (+ (* (* (* x x) (+ 83 (cos (abs (cos (/ (/ x x) 28)))))) (- (abs x) (+ (abs -16) x))) x)))

(foi gerada algoritmicamente... não está simplificada)

abs!

Pascal J. Bourguignon

unread,
Sep 16, 2015, 12:56:50 AM9/16/15
to lis...@googlegroups.com
Você poderia reescrever a expressão em uma expressão maxima e ter
maxima exibi-lo.

(defun maxima-sexp (sexp)
(cond
((typep sexp 'ratio) `((rat simp) ,(numerator sexp) ,(denominator sexp)))
((numberp sexp) sexp)
((symbolp sexp) (intern (concatenate 'string "$" (symbol-name sexp))))
((atom sexp) (error "I don't know how to handle ~S" sexp))
((eq '/ (first sexp))
(list '(MTIMES SIMP)
(maxima-sexp (second sexp))
(list '(MEXPT SIMP) (maxima-sexp (third sexp)) -1)))
((member (first sexp) '(+ - *))
(list* (list (cdr (assoc (first sexp) '((+ . mplus)
(- . mminus)
(* . mtimes)))) 'simp)
(mapcar (function maxima-sexp) (rest sexp))))
(t
(list* (list (intern (concatenate 'string "%" (symbol-name (first sexp)))) 'simp)
(mapcar (function maxima-sexp) (rest sexp))))))


[pjb@kuiper :0.0 ~]$ maxima

Maxima 5.34.1 http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.12 (a.k.a. GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) :lisp (defun maxima-sexp (sexp) (cond ((typep sexp 'ratio) `((rat simp) ,(numerator sexp) ,(denominator sexp))) ((numberp sexp) sexp) ((symbolp sexp) (intern (concatenate 'string "$" (symbol-name sexp)))) ((atom sexp) (error "I don't know how to handle ~S" sexp)) ((eq '/ (first sexp)) (list '(MTIMES SIMP) (maxima-sexp (second sexp)) (list '(MEXPT SIMP) (maxima-sexp (third sexp)) -1))) ((member (first sexp) '(+ - *)) (list* (list (cdr (assoc (first sexp) '((+ . mplus) (- . mminus) (* . mtimes)))) 'simp) (mapcar (function maxima-sexp) (rest sexp)))) (t (list* (list (intern (concatenate 'string "%" (symbol-name (first sexp)))) 'simp) (mapcar (function maxima-sexp) (rest sexp))))))

MAXIMA-SEXP
(%i1) :lisp (displa (maxima-sexp '(+ (- 38 -42) (cos (+ (* (* (* x x) (+ 83 (cos (abs (cos (/ (/ x x) 28)))))) (- (abs x) (+ (abs -16) x))) x)))))
x
cos(x - ((x x) (cos(abs(cos(----))) + 83)) abs(x) (x + abs(- 16))) - 38
x 28
NIL
[pjb@kuiper :0.0 ~]$


http://maxima.sourceforge.net/
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

padovani

unread,
Sep 16, 2015, 10:50:36 AM9/16/15
to lis...@googlegroups.com
2015-09-16 1:56 GMT-03:00 Pascal J. Bourguignon <p...@informatimago.com>:

Você poderia reescrever a expressão em uma expressão maxima e ter
maxima exibi-lo.

Muito obrigado, Pascal!

Não havia usado o Maxima antes e funcionou perfeitamente! 

Você saberia dizer se há uma maneira de utilizá-lo a partir de um input via linha de comando e obter a imagem da função em formato de arquivo e o código LaTeX como saída?

(vou buscar por aqui também)

obrigado mais uma vez! 

José H.

namekuseijin

unread,
Sep 20, 2015, 11:16:46 PM9/20/15
to lis...@googlegroups.com

holy crap, dude! You speak portuguese too? you really are an informatimago... :)

--
You received this message because you are subscribed to the Google Groups "Lisp-br" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-br+u...@googlegroups.com.
To post to this group, send email to lis...@googlegroups.com.
Visit this group at http://groups.google.com/group/lisp-br.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages