-1

I am trying to calculate bending on my beam, but I get error. I am new at coding so I have no idea what is wrong. If I put only integer or float is working, but when I insert array I get this error

def poves(x):
    eta1 = a/L
    eta2 = (a+b)/L
    zeta = x/L
    E = 210e3 #MPA
    F1 = Ft_1
    F2 = Ft_3
    Iy = 50**4*np.pi/64 ##mm
    if(0<=x<=a):
        return F1 * L * zeta*(1-eta2)/(E*Iy)
    elif(a<x<=L):
        return F1 * L * eta2*(1-zeta)/(E*Iy)
    else:
        print(f'Nope')
ValueError                                Traceback (most recent call last)
<ipython-input-149-e30266137f00> in <module>
----> 1 poves(x)

<ipython-input-148-290878c57829> in poves(x)
      7     F2 = Ft_3
      8     Iy = 50**4*np.pi/64 ##mm
----> 9     if(0<=x<=a):
     10         return F1 * L * zeta*(1-eta2)/(E*Iy)
     11     elif(a<x<=L):

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
jan
  • 49
  • 9

1 Answers1

0

As pointed out by the ValueError, your x is an array. In that case, try using all as following:

if np.all((0<=x) & (x<=a)):

Example

a = 13
x = np.array([1, 2, 3, 4, 12, 4, 0.1, 3, 9])

if np.all((0<=x) & (x<=a)):
    print ("Condition fulfilled")
else:    
    print ("Condition not fulfilled")

# Condition fulfilled

In case of list, you can compare each element by iterating over the elements of x.

Example

a = 10
x = [1, 2, 3, 4, 12, 4, 0.1, 3, 9]

if all(0<=i<=a for i in x):
    print ("Condition fulfilled")
else:    
    print ("Condition not fulfilled")

# Condition not fulfilled

a = 15
x = [1, 2, 3, 4, 12, 4, 0.1, 3, 9]

if all(0<=i<=a for i in x):
    print ("Condition fulfilled")
else:    
    print ("Condition not fulfilled")

# Condition fulfilled
Sheldore
  • 37,862
  • 7
  • 57
  • 71
  • I want to return new array. Half of my x will go throuh if statment half of them wont go. – jan Jun 02 '19 at 17:05
  • @jan : I don't get your point. I answered the problematic part. Please [provide a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) to explain what you mean and what you want – Sheldore Jun 02 '19 at 17:12
  • I have array from 0 to 100 with 100 points, a values is 47 if x is smaler then 47 i want to use one eqation if x is larger then 47 I want to use the other eqation. Sorry for bad english :( – jan Jun 02 '19 at 17:14