0

I'm a student of mechanical engineering, and this is the first year I've met with the Python environment, or the distribution of it Anaconda. I was given a task to find the zeroes of this function:

⋅sin()cos()+⋅cos()sin()2−⋅cos()−ℎ⋅sin()=0

With the parameters:

D = 220mm,
h = 1040mm,
l = 1420mm,where
n = 81

is the number of equally distanced points on the function and the function is limited to :

∈[0,2] where is a np.array.

plotted function The issue is, when I try to insert the function in bisect(fun, a, b), the error says

'numpy.ndarray' object is not callable

Can someone aid a noob programer ? Thanks.

Wyvern
  • 11
  • 2

1 Answers1

1

The question is not clear, you should share your code and the title should say scipy, not simpy, if I am correct.

Apart from this, I do not get the same plot of the function, can you check if it is correct?

If you want to use the bisection method you should do something like this:

import numpy as np
from scipy.optimize import bisect

def fun(x, D, h, l):
    return D * np.sin(x) * np.cos(x) + l * np.cos(x) * np.sin(x) * 2 - l * np.cos(x) - h * np.sin(x)

D = 220
h = 1040
l = 1420

print(bisect(lambda x: fun(x, D, h, l), 0, 2*np.pi))

Note that the bisection method only finds one zero, and this does not work at all because the two extremes of the function have the same sign. For this particular function, you could run the bisect in the intervals (0, pi) and (pi, 2pi) to find both zeros.

Diego Palacios
  • 1,096
  • 6
  • 22