I'm trying to build a code that asks the user to enter the equation then the code will get the derivate of it, so I can use the derivative in numerical method.
This is my current code that calculates the true/approximate value/error (this is my first python program so pardon the mess)
def ggxp(x,h):
z1= int(((ggx(x)*ggx(h)) - ggx(x))/h)
return z1
def ggxd(x):
z2= 4*x+1
return z2
def ggx(x):
z3= int(2*x^2+x-5)
return z3
x = int(input("Enter x \n"));
c =2;
while c > 0:
h= int(input("Enter h \n"))
y0 = ggxd(x)
y1= ggxp(x,h)
TrueError=y0-y1;
print("The approximate value at ", x ," is ", y1 ," \n")
if c == 2:
prevA = y1;
c= c-1;
print ("The true value at ",x," is ",y0,"\n")
RelativeTE= int((TrueError/y0)*100);
print ("the relative true error is ", RelativeTE ,"\n")
if prevA != y1:
Ea = int(prevA - y1);
REa = int((Ea / y1) * 100)
print("The approximate error is " , Ea , "\n")
print("The relative approximate error is ", REa, "\n")
I want a program that runs like this but the user is the one who enters the function then the program will get the derivative by itself and then continue. (I know it's easier to do in matlab but I don't have access to matlab)