#!/usr/bin/python2.5 # -*- coding: utf-8 -*- from commands import getoutput MAXIMA_COMMAND = '/usr/bin/maxima --batch-string="fpprec : 5;string(%s);" --very-quiet' def exec_maxima(expr): answer = getoutput(MAXIMA_COMMAND % expr).split("\n")[-1].strip() return answer def diff(expr, var): return exec_maxima('diff('+expr+','+var+')') def tex(expr): answer = getoutput(MAXIMA_COMMAND % ('tex('+expr+')')).split("\n")[-2].strip().replace('\$\$','') return answer def count(expr, values): for key in values.keys(): expr = expr.replace(key,values[key]) return exec_maxima(expr) def count_pi(expr, values): for key in values.keys(): expr = expr.replace(key,values[key]) return exec_maxima('bfloat('+expr.replace('pi','3.141592653589793')+')') # # Приклад використання # #print exec_maxima('true or false') #answer = diff('e^x*cos(x)','x') #print answer #print tex(answer) #print count('sin(x)',{'x':str(float(1))}) #print count('sin(x) + sin(y)',{'x':'pi/2', 'y':str(float(0))}) #Вкажіть тут свої дані # # Вирішення варіанту №24 # print '--------VARIANT #24---------------' x = '-4*cos(pi*t/3)-1' y = '-4*sin(pi*t/3)' t1 = str(float(1)) #x = '4*t' #y = '16*t^2-1' #t1 = str(float(0.5)) print 'x = '+x + ' = '+count_pi(x,{'t':t1}) print 'y = '+y + ' = '+count_pi(y,{'t':t1}) vx = diff(x,'t') vy = diff(y,'t') vx_num = count_pi(vx,{'t':t1}) vy_num = count_pi(vy,{'t':t1}) print 'vx = dx/dt = '+vx+' = '+vx_num+' см/сек' print 'vy = dy/dt = '+vy+' = '+vy_num+' см/сек' ax = diff(vx,'t') ay = diff(vy,'t') ax_num = count_pi(ax,{'t':t1}) ay_num = count_pi(ay,{'t':t1}) print 'ax = d^2x/dt^2 = '+ax+' = '+ax_num+' см/сек^2' print 'ay = d^2y/dt^2 = '+ay+' = '+ay_num+' см/сек^2 \n' v_template = 'sqrt((vx)^2+(vy)^2)' v = count(v_template, {'vx':vx,'vy':vy}) v_num = count_pi(v_template,{'vx':vx_num,'vy':vy_num}) print 'v = '+count(v_template,{})+' = '+v+' = ' + v_num+' см/сек \n' a_template = 'sqrt((ax)^2+(ay)^2)' a = count(a_template, {'ax':ax,'ay':ay}) a_num = count_pi(a_template,{'ax':ax_num,'ay':ay_num}) print 'a = '+count(a_template,{})+' = '+a+' = ' + a_num+' см/сек^2 \n' at_template = 'abs(((vx)*(ax)+(vy)*(ay)))/(v)' at_num = count_pi(at_template,{'vx':vx_num,'vy':vy_num,'ax':ax_num,'ay':ay_num,'v':v_num}) print 'at = '+ count(at_template,{})+' = '+at_num+' см/сек^2 ' an_template = 'abs(((vx)*(ay)-(vy)*(ax)))/(v)' an_num = count_pi(an_template,{'vx':vx_num,'vy':vy_num,'ax':ax_num,'ay':ay_num,'v':v_num}) print 'an = '+ count(an_template,{})+' = '+an_num+' см/сек^2 \n' ro_template = '(v)^2/(an)' ro_num = count_pi(ro_template,{'v':v_num, 'an':an_num}) print 'ro = '+count(ro_template, {})+' = '+ro_num+' см'