How to put a limit to my vector?

Asked

Viewed 27 times

0

I am doing a work, and in it I find a vector with possible values for a variable, however, the values that really meet the answer, are contained in the restriction 1.5 < R < 2 . How I would transform the vector R complete in the vector R real that meets the restriction? ie, the one that the house 0 begins with the value 1.5.

Ex: 1.5 < V < 2 , whereas V is a decreasing vector with 7 thousand houses.

Follow what I tried to do:

   
import numpy as np
import matplotlib.pyplot as plt

# Parametros Físicos:
m = 0.558 # massa (kg)

# Parâmetros Modais:
zeta = np.arange(0.000001,(np.sqrt(1/2)-0.001),0.0001) # fator amortecimento 

# Força externa aplicada:
F0 = 200 # amplitude da força (N)

rpico = np.sqrt(1-2*zeta**2)

ZY = (rpico**2)/((1-rpico**2)**2 + (2*zeta*rpico)**2)**(1/2)
i = j = 0
while i < 7061:
    i = i + 1
    if ZY[i]>1.5 and ZY[i]<2:
        zyl[j] = ZY[i]
        j = j+1 
        
        
plt.figure()
plt.plot(zeta,rpico)
plt.xlabel('Zeta')
plt.ylabel('rpico')
plt.title('-')
plt.grid (True)

plt.figure()
plt.plot(rpico,zyl)
plt.xlabel('rpico')
plt.ylabel('ZY')
plt.title('-')
plt.grid (True)

1 answer

0

I made the following change to the code:

ZY = (rpico**2)/((1-rpico**2)**2 + (2*zeta*rpico)**2)**(1/2)
zyl = []

for item in ZY:
  if item > 1.5 and item < 2:
    zyl.append(item)

The idea is the same as yours: create a new array with valid values. However, in your code, you had not created the variable zyl before entering the loop, then there was an error. So I created it empty at the beginning.

Instead of traversing the ZY vector with two indices (i,j) it is easier to loop by iterating straight through the ZY values themselves.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.