1

the following is a (very)shorterned vesrion of my program

the normvecs vector is not getting overwritten , you woud be able to see for yourself just once you run this code snippet , the parameters are correct geom function takes an n+1 X 2 array and n as input, i guess i'm doing something really stupid (which i think i am) or i don't understand this behavior

import numpy as np

#geometry calculations
def geom(pts,n):
    r = np.zeros(n)
    normvecs = np.zeros((n,2))
    tgtvecs  = np.zeros((n,2))
    alphap = np.zeros(n)
    cpts = np.zeros((n,2))
    #collocation points
    cpts[:,0] = (pts[0:n,0]+pts[1:n+1,0])/2  
    cpts[:,1] = (pts[0:n,1]+pts[1:n+1,1])/2
    #length of panels
    r[:] = np.sqrt((pts[0:n,0]-pts[1:n+1,0])**2 + (pts[0:n,1]-pts[1:n+1,1])**2)
    #angle of each panel with the horizantal(chord)/refernce axis
    alphap[:] = np.arctan2(pts[1:n+1,1]-pts[0:n,1],pts[1:n+1,0]-pts[0:n,0])
    #normal vectors
    normvecs[:,0] = -np.sin(alphap[:])
    normvecs[:,1] =  np.cos(alphap[:])
    xx = np.cos(alphap[:])
    print(normvecs[:,0],normvecs[:,1],np.cos(alphap[:]),xx)
    return

geom(np.random.rand(31,2),30)

normvecs[:,1] is showing just negative of nomvecs[:,0] i wasn't able to overwrite like normvecs[:,1] = xx (no errors .. but just printed the same thing)

I maynot sound clear,once if you run you may see what i'm trying to tell.

what's the problem?(if it is so!)

1 Answer 1

2

I see no problem at all. Running a more concise version of your code:

import numpy as np

#geometry calculations
def geom(pts,n):
    normvecs = np.zeros((n,2))
    alphap = np.zeros(n)
    alphap[:] = np.arctan2(pts[1:n+1,1]-pts[0:n,1],pts[1:n+1,0]-pts[0:n,0])
    normvecs[:,0] = -np.sin(alphap[:])
    normvecs[:,1] =  np.cos(alphap[:])
    print np.abs(normvecs[:,0])-np.abs(normvecs[:,1])
    return

geom(np.random.rand(31,2),30)

produces something like this:

[ 0.47500019 -0.03182906 -0.46597523  0.7479451   0.12580804 -0.36311644
  0.06406616 -0.29641905 -0.39982319 -0.98493049 -0.4431009  -0.29506693
 -0.25931983  0.67831564 -0.80676608 -0.53007712  0.63448069  0.67457029
  0.25457744 -0.82095266 -0.27461275 -0.91244341 -0.69530798 -0.69023852
  0.18840807  0.49891863  0.52417747  0.06833423  0.83449866  0.47608894]

Which suggests to me that the elements of two rows of normvecs you are saying are identical in magnitude are not.

Sign up to request clarification or add additional context in comments.

4 Comments

yes there is no problem , it was an unseen logical error i skipped one line in the code(considering it irrelevant) posted where i had this (wrong, my bad!) assignment tgtvecs[:,0] = np.cos(alphap[:]) ; normvecs[:,] = np.sin(alphap[:])
you would have got the same error , if you had just run my program without modifying it .. anyway thanx
No I wouldn't have. It produced no errors as you posted it, all I did after I saw it worked was remove the redundant code that had no effect on the output array you were asking about, and made the output less confusing by printing the difference between the two rows. Otherwise is it precisely as you posted it, sorry.
again you are right!, it would produce no errors , precisely because of the one line removed!!! , thanx again for clearing this up! and yeah i got the whole thing working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.