darksantos

Ejercicio141

Jun 11th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from modulepythong import *
  3. from math import sqrt
  4.    
  5. a=float(raw_input('Ingrese a: '))
  6. b=float(raw_input('Ingrese b: '))
  7. c=float(raw_input('Ingrese c: '))
  8.  
  9. discriminante = b**2 - 4*a*c
  10.  
  11. if discriminante >= 0:
  12.     x1 = (-b + sqrt(discriminante )) / (2 * a)
  13.     x2 = (-b - sqrt(discriminante )) / (2 * a)
  14.     if x1>x2:
  15.         x1,x2=x2,x1
  16.     print 'Las soluciones son: '
  17.     print x1,x2
  18.    
  19.     valor=(-b)/(2*a)
  20.    
  21.     y=abs((a*(valor**2))+(b*valor)+c)
  22.    
  23.     m=max( abs(x1),abs(x2))
  24.    
  25.     window_size(500, 500)
  26.     window_coordinates(-m-3, -y-3, m+3, y+3)    
  27.    
  28.     create_line( 0     , y+2.5 , 0     , -y-2.5, 'blue')
  29.     create_line( -m-2.5 , 0    , m+2.5 , 0    , 'blue')
  30.    
  31.     plus=float(0.01)
  32.     x=float(x1-2)
  33.    
  34.     while x <= x2+2 :
  35.         y=((a*(x**2))+(b*x)+c)    
  36.         z=(a*((x+plus)**2)+(b*(x+plus))+c)
  37.         create_line(x, y, x+plus, z, 'red')
  38.         x = x+plus
  39.     create_text(x1+0.5, 0.5, x1, 10, 'SW')
  40.     create_text(x2+0.5, 0.5, x2, 10, 'SW')
  41.     print'Pulsa <Return> para salir: '
  42.     raw_input()
  43. else:
  44.     print 'No hay soluciones reales'
Advertisement
Add Comment
Please, Sign In to add comment