{"action":"opened","issue":{"url":"https://api.github.com/repos/tbeu/Modelica/issues/1260","repository_url":"https://api.github.com/repos/tbeu/Modelica","labels_url":"https://api.github.com/repos/tbeu/Modelica/issues/1260/labels{/name}","comments_url":"https://api.github.com/repos/tbeu/Modelica/issues/1260/comments","events_url":"https://api.github.com/repos/tbeu/Modelica/issues/1260/events","html_url":"https://github.com/tbeu/Modelica/issues/1260","id":197104279,"number":1260,"title":"Complex.scalarProduct not a scalar product","user":{"login":"modelica-trac-importer","id":22202507,"avatar_url":"https://avatars.githubusercontent.com/u/22202507?v=3","gravatar_id":"","url":"https://api.github.com/users/modelica-trac-importer","html_url":"https://github.com/modelica-trac-importer","followers_url":"https://api.github.com/users/modelica-trac-importer/followers","following_url":"https://api.github.com/users/modelica-trac-importer/following{/other_user}","gists_url":"https://api.github.com/users/modelica-trac-importer/gists{/gist_id}","starred_url":"https://api.github.com/users/modelica-trac-importer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/modelica-trac-importer/subscriptions","organizations_url":"https://api.github.com/users/modelica-trac-importer/orgs","repos_url":"https://api.github.com/users/modelica-trac-importer/repos","events_url":"https://api.github.com/users/modelica-trac-importer/events{/privacy}","received_events_url":"https://api.github.com/users/modelica-trac-importer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"beutlich","id":14896695,"avatar_url":"https://avatars.githubusercontent.com/u/14896695?v=3","gravatar_id":"","url":"https://api.github.com/users/beutlich","html_url":"https://github.com/beutlich","followers_url":"https://api.github.com/users/beutlich/followers","following_url":"https://api.github.com/users/beutlich/following{/other_user}","gists_url":"https://api.github.com/users/beutlich/gists{/gist_id}","starred_url":"https://api.github.com/users/beutlich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beutlich/subscriptions","organizations_url":"https://api.github.com/users/beutlich/orgs","repos_url":"https://api.github.com/users/beutlich/repos","events_url":"https://api.github.com/users/beutlich/events{/privacy}","received_events_url":"https://api.github.com/users/beutlich/received_events","type":"User","site_admin":false},"assignees":[{"login":"beutlich","id":14896695,"avatar_url":"https://avatars.githubusercontent.com/u/14896695?v=3","gravatar_id":"","url":"https://api.github.com/users/beutlich","html_url":"https://github.com/beutlich","followers_url":"https://api.github.com/users/beutlich/followers","following_url":"https://api.github.com/users/beutlich/following{/other_user}","gists_url":"https://api.github.com/users/beutlich/gists{/gist_id}","starred_url":"https://api.github.com/users/beutlich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beutlich/subscriptions","organizations_url":"https://api.github.com/users/beutlich/orgs","repos_url":"https://api.github.com/users/beutlich/repos","events_url":"https://api.github.com/users/beutlich/events{/privacy}","received_events_url":"https://api.github.com/users/beutlich/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2016-12-22T06:30:58Z","updated_at":"2016-12-22T06:30:58Z","closed_at":null,"body":"**Reported by petar on 26 Aug 2013 06:57 UTC**\nThe scalar product for complex vectors is actually not a scalar product. Currently, the scalar product for complex vectors is defined as:\n\n```\n\n    function scalarProduct \"Scalar product c1*c2 of two complex vectors\"\n      import Complex;\n      input Complex c1[:] \"Vector of Complex numbers 1\";\n      input Complex c2[size(c1, 1)] \"Vector of Complex numbers 2\";\n      output Complex c3 \"= c1*c2\";\n    algorithm\n      c3:=Complex(0);\n      for i in 1:size(c1, 1) loop\n              c3:=c3 + c1[i] * c2[i];\n      end for;\n      /*\n       c3 :=Complex(c3.re + c1[i].re*c2[i].re - c1[i].im*c2[i].im,\n                    c3.im + c1[i].re*c2[i].im + c1[i].im*c2[i].re);\n       */\n    end scalarProduct;\n```\n\n\nwhich is just the scalar product for real vectors translated to complex vectors. An example of why this is not a proper scalar product is that using this scalar product you can get v \\* v = 0 instead of the expected v \\* v = norm(v)^2. (A concrete example where this happens is v = (1 + i, 1 - i)). For more information, see Wikipedia; http://en.wikipedia.org/wiki/Scalar_product#Complex_vectors.\n\nTo get a mathematically sound scalar product for complex numbers you need to apply conjugation on one of the vectors (which one differs between fields; quantum physicists mostly conjugate the left vector and mathematicians the right vector). I.e., the code should be:\n\n```\n\n      for i in 1:size(c1, 1) loop\n              c3:=c3 + ComplexConjugate(c1[i]) * c2[i];\n      end for;\n\n```\n\nor\n\n```\n\n      for i in 1:size(c1, 1) loop\n              c3:=c3 + c1[i] * ComplexConjugate(c2[i]);\n      end for;\n```\n\n\nwhere ComplexConjugate is the function mapping a + bi to a - bi.\n\n----\n\nMigrated-From: https://trac.modelica.org/Modelica/ticket/1260"}}
{"actor":{"display_login":"modelica-trac-importer"}}