Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 norm mcgrim Splitter Posts: 157 Threads: 30 Joined: Mar 2019 Reputation: 0 Likes received: 1 #1 Mar-21-2019, 10:00 AM (This post was last modified: Mar-21-2019, 10:34 AM by mcgrim.) I am writing a program that takes a vector as parameter and returns the corresponding normalized vector. The first part of the program attempts this task manually (without the function 'norm') and the second part is with the 'norm' function. I have written them both and the program runs but I cannot understand why I get different outcomes. I get 1.06 in the fist part and 3.74 in the second. why? (both parts are separated by #------------------------------------) ``` import numpy as np from numpy import array from scipy.linalg import norm """ V=[1,2,3] n_vec=sqrt(V[0]**2+V[1]**2+V[2]**3) def v_vector(V): return ((V[0]/n_vec)+(V[1]/n_vec)+(V[2]/n_vec)) print(v_vector(V)) """ #----------------------------------------------------------- V=[1,2,3] def v_vector(V): return (linalg.norm(V)) print(v_vector(V)) ``` I solved this issue myself, but I am not sure how to remove this post. nilamo Last Thursdayist Posts: 3,173 Threads: 80 Joined: Sep 2016 Reputation: 129 Likes received: 707 #2 Mar-21-2019, 07:05 PM So what was the solution? mcgrim Splitter Posts: 157 Threads: 30 Joined: Mar 2019 Reputation: 0 Likes received: 1 #3 Mar-22-2019, 12:39 PM the second step is actually correct but incomplete as it merely calculated the norm instead of the whole unit vector. « Next Oldest | Next Newest »

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)