{"id":2934,"date":"2014-12-09T12:24:10","date_gmt":"2014-12-09T12:24:10","guid":{"rendered":"http:\/\/www.dientoan.us\/?p=2934"},"modified":"2018-06-19T11:32:08","modified_gmt":"2018-06-19T11:32:08","slug":"sage-server-customization","status":"publish","type":"post","link":"http:\/\/www.dientoan.us\/?p=2934","title":{"rendered":"Sage server customization"},"content":{"rendered":"<p><script type=\"text\/x-mathjax-config\">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]}});<\/script><script type=\"text\/javascript\" src=\"\/php\/mathjax\/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"><\/script><\/p>\n<div id=container>\n<div id=left style=\"width:50%;float:left;margin-right:10px;\">\nDec. 9, 2014,<br \/>\n<u>Sage useful commands to make homework keys in Algebra &#038; Calculus<\/u>.<br \/>\n1. To save the definitions of all functions and variables including history of input and output commands:<br \/>\n%colors NoColor<br \/>\nsave_session() or save_session(&#8216;2014.12.07&#8217;)<br \/>\nThe saved session can befound in the user home directory (~), for example, 2014.12.07.sobj.<br \/>\n<u>To restore a particular session:<\/u><br \/>\nload_session (&#8216;2014.12.07.sobj&#8217;)<br \/>\n_oh (to list all output lines in the session, Python formatted).<br \/>\n_ih (to list all input commands in the session, Python formatted).<br \/>\nThe original command can be reconstructed without type declaration.<\/p>\n<p>2. To see the <u>definition of a function or a variable<\/u> (for example, dist formula)<br \/>\nshow_identifiers()<br \/>\ndist<\/p>\n<p>3. Set up log file with correct parameters (<u>Python&#8217;s output, raw input, with timestamp<\/u>). The log file is saved in the current directory RealNumber(2014.12).gen(09).log.<br \/>\nlogstart -r -o -t 2014.12.09.log append<br \/>\nlogstop to stop the log file recording.<\/p>\n<p>4. <u>Short definitions<\/u>.<br \/>\n\\(d=\\sqrt{(x_{1}-x_{2})^2+(y_{1}-y_{2})^2}\\)<br \/>\nsage: s_dis(x1,y1,x2,y2)=sqrt((x1 &#8211; x2)^2 + (y1 &#8211; y2)^2)<br \/>\nsage: s_dis(1,3,2,5)\n<\/div>\n<div id=right style=\"margin-left:50%;\">\n5. <u>Custom functions<\/u>:<br \/>\nsage: def l_dis(x1,y1,x2,y2):<br \/>\n&#8230;.:    print &#8220;Distance from (%1.2f,%1.2f) to (%1.2f,%1.2f) = %1.2f&#8221;%(x1,y1,x2,y2,sqrt((x1 &#8211; x2)^2 + (y1 &#8211; y2)^2))<br \/>\n&#8230;.:    (Enter a blank line return to end)<br \/>\nsage: l_dis(2,0,3,2)<br \/>\nDistance from (2.00,0.00) to (3.00,2.00) = 2.24<\/p>\n<p>6. To convert a <u>linear equation<\/u> from <u>standard form<\/u> (\\(2y+6x\\)\\(-3=7-2x\\)) to <u>slope-intercept form<\/u> by solving for y (\\(y=-4x+5\\)):<br \/>\nsage: solve(2*y+6*x-3==7-2*x,y)<br \/>\n[y == -4*x + 5]<\/p>\n<p>7. <u>Execute a C-interface program<\/u>. It may be necessary to stop the logging process (logstop) to disable warning\/error messages relating to the logging process. Remember to restart the log when done.<br \/>\nSee example of distance formula in homemath.c and homemath.spyx.<br \/>\n<u>Notes<\/u>:<br \/>\n7.1. C-syntax for power notation is different from sage power syntax (^).<br \/>\n7.2. Updating homemath.spyx automatically updates the compilation process.<br \/>\n7.3. The C-interface program is really in Python indented format.<\/p>\n<p>8. <u>Execute a Linux command<\/u> (php -f bc.php from a function) to support custom solutions (Roman symbols).<br \/>\nl_rom(200) (.spyx interface)<br \/>\n!php -f bc.php &#8216;rom(200)&#8217; (command shell interface)<\/p>\n<p>9. <u>Calculus functions<\/u>.<br \/>\n\\(f(x)=2x^2+4x+3\\)<br \/>\n\\(f'(x)=4x+4\\)<br \/>\nf(x)=2*x^2+4*x+3<br \/>\nf(x).derivative(x)<\/p>\n<p>10. <u>Statistical functions<\/u>.<br \/>\nmean, median, mode, range, max, min, variance, std, sort<br \/>\nv=[2,6,7,9,13,15]<br \/>\nv<br \/>\nmean(v)<br \/>\nsum(v)<br \/>\nmedian(v)<br \/>\nu=[13,15,2,6,9,7]<br \/>\nmean(u)<br \/>\nu<br \/>\nmax(u)<br \/>\nmin(u)<br \/>\nrange(u)<br \/>\ndef range(u):max(u)-min(u)<br \/>\nrange(u)<br \/>\nrange<br \/>\nu<br \/>\nrange(u)<br \/>\ndef range(u): return (max(u)-min(u))<br \/>\nrange(u)<br \/>\nrange<br \/>\nmode(u)<br \/>\nu=[13,15,2,6,9,7,7,7]<br \/>\nmode(u)<br \/>\nstd(u)<br \/>\nvariance(u)<br \/>\nu.sort()<br \/>\nsorted(u)<br \/>\nsorted(u,reverse=True)<br \/>\n9. Print format options.<br \/>\n10. Plotting opti\u1ecdns<br \/>\n10. Save individual objects to build a local math reference library.<br \/>\n11. Build a sage server for worksheet development (grade 3-12).\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Dec. 9, 2014, Sage useful commands to make homework keys in Algebra &#038; Calculus. 1. To save the definitions of all functions and variables including history of input and output commands: %colors NoColor save_session() or save_session(&#8216;2014.12.07&#8217;) The saved session can &hellip; <a href=\"http:\/\/www.dientoan.us\/?p=2934\">\u0110\u1ecdc ti\u1ebfp <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.dientoan.us\/index.php?rest_route=\/wp\/v2\/posts\/2934"}],"collection":[{"href":"http:\/\/www.dientoan.us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.dientoan.us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.dientoan.us\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.dientoan.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2934"}],"version-history":[{"count":0,"href":"http:\/\/www.dientoan.us\/index.php?rest_route=\/wp\/v2\/posts\/2934\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.dientoan.us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.dientoan.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2934"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.dientoan.us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}