c++ - Finding scalar in a vector equality programatically -


i have 2 vectors v1 , v2 equality

x*v1 = v2

both v1 , v2 known time need determine x. know certainty there single x solves equation.

by hand can set system of equations x. in fact don't need gaussian elimination since it's such simple setup. led me try x = v2.x / v1.x. can lead division zero.

i'm writing in c++ if that's important.

thanks!

the asker’s own solution flawed, because fail if (v1.x + v1.y + v1.z) adds zero:

x = (v2.x + v2.y + v2.z) / (v1.x + v1.y + v1.z)

here correct solution problem:

x = (v2.x * v1.x + v2.y * v1.y + v2.z * v1.z) /     (v1.x * v1.x + v1.y * v1.y + v1.z * v1.z); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -