Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python How to call a float in this function ?

I have defined those three functions:

```
def deriv(y,x) :
dx = 10**(-5)
dx2 = dx/2
return ((y(x+dx2)-y(x-dx2))/(dx))

def fex(y,x) :
y_0 = y(x)
return (np.sqrt(1 + deriv(y,x)**2))/(np.sqrt(2*9.81*(y_0-y(x))))

def tang(y,a,x):
y_a= y(a)
return(y_a+deriv(y,a)*(x-a))

```



I am using numpy and `x` is a list of numbers that is generated by this command: `x = np.linspace(0,1,100)` that creates a list of 100 numbers between zero and one.

My goal is to have a list of numbers that represent the values on the tangent that correspond to the elements of the `x` list.

So I wrote that in my code:

tang(fex(y,x),a, x)

But my problem goes as follows: When the computer tries to find `y(a)` in the tangent function he do not understand that I am looking for `fex(y,a)` so it there is an error wich is `TypeError: 'numpy.ndarray' object is not callable`. So i figured out that the `fex` element that recieve `tang` is a list wich is no problem for the rest of the program but just for this `y(a)` thing it is.
 
I'm not much of Python expert, but I don't see a function y() being defined here. So how are calls to y(a) or y(x) supposed to work ? It seems from your wording you expect y(a) to be equivalent to fex(y,a), but why should this be so ?

The error message suggests that you are calling a NumPy array as if it were a function. You may want to try square brackets instead of round brackets.

Also, please always post code in code tags.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom