[Python] Sympy won't accept I as a symbol while differentiating

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    I made a simple program to calculate std for a given set of numbers and a function. While inputing some data today I realized that if one of the variables is called I it gives 0 as the derivative.

    Here is the relevant part of the code:

    for i in range(50):
    des=input(f'Introduce variable: ')
    if des == str(0):
    break
    variables.append(des)

    valores=[]
    incertidumbres=[]
    for i in range(len(variables)):
    valores.append(float(input(f'Dame el valor de la variable {variables}: ')))
    incertidumbres.append(float(input(f'Dame el valor de la incertidumbre de {variables}: ')))
    variables=sp.symbols(variables)

    parciales=[]
    ponderado=[]
    for i in range(len(variables)):
    parciales.append(sp.diff(funcion,variables))
    print(f"La derivada de la función respecto a {variables} es {parciales}")
    parciales=sp.lambdify(variables,parciales)
    ponderado.append(parciales(*valores)**2*incertidumbres**2)


    Sorry for the variables being in spanish.

    If I input the ecuation a+b i get 1 and 1 as derivatives but i get 0 and 1 when I input I+a.

    I was expecting the results to be consistent. Changing the name of the variable shouldn't affect the result, right?

    Continue reading...

Compartilhe esta Página