fetude.py

Created by jlevon

Created on June 05, 2020

1.4 KB

etude de fonction avec tableau et dérivée, graphe de la fonction et sa dérivée


from math import *
from matplotlib.pyplot import *

df=[]
rdf=""

def fc():
  for i in range(a,b,n):
    try:
      y=f(i)
    except ValueError:
      print("a >0")
      pass
    except ZeroDivisionError:
      df.append(i)
      i=i+1
    try:
      y2=nderiv(y)
    except ZeroDivisionError:
      i=i+1
      y=nderiv(i)
    print("_________________")
    print("X=",i)
    print("F(X)=",round(f(i),3))
    print("F'(X)=",round(y2,3))
    z=input(">presse EXE<")
  return

def f(x):
    return 1/x

def nderiv(x):
    h=0.00001
    x=x-h
    z=f(x)
    x=x+2*h
    z=(f(x)-z)/(2*h)
    return z

def grf():
  axis((a-1,b+1,a-1,b+1))
  start=-(abs(a)+.5)
  end=b+.5
  steps=0.2
  x=[start+i*steps for i in range(int((end-start)/steps)+1)]
  y=[f(j) for j in x]
  w=[nderiv(k) for k in x]
  plot(x,y,'blue')
  plot(x,w,'red')
  if a>=0 and a<1:
    l=b/3
    m=l+1
  else:
    l=b/3
    m=a/3
  text(l,m+1,'bleu f(x)')
  text(l,m-1,'rouge nderiv(x)')
  show()
  
def dfs():
  if len(df)==0:
    rdf="[0;+oo["
  if len(df)==1:
    rdf="DF=x<>0"
  if len(df)==2:      
    rdf="]-oo;"+df[1]+"["
  if len(df)==3:
    rdf="]-oo;"+df[1]+"["  
  print("--------DF--------")
  print(rdf)
  print("------------------")
  z=input(">presse EXE<")
  return

print("\n"*6)
print("--Saisie Des Bornes--")
print("       d'etude")
print("\n")
a=eval(input("borne <"))
b=eval(input("borne >")) 
n=1
fc()
if len(df)!=0:
  dfs()  
grf()