# Problems defining a function with lists

mrahikka shared this problem 2 months ago
Not a Problem

Using GG Classic 5.0.498.0, the same happens with 6.

I decided to learn quarternions. Wanted to define their product. (the ggb-file is attatched)

p:={3,(1,-2,1)}

q:={2,(-1,2,3)}

The product of quarternions is very complicated expression, so I wanted to create a function to play with them.

First I studied how to calculate the first term in product, it is p(1)*q(1) = 6, it works OK. Then the function:

Tu(a,b):=a(1)*b(1)

->Tu(a, b):=a(1) * b(1)

But when I use it, I will get a list

Tu(p,q)

->{6, (-2)}

Why is it a list and where did -2 come from?

1

IMHO a problem because Tu(a,b) works as a*b not a(1)*b(1) (use variables numbers not lists)

-2 is the dot product of vectors ( ( 1,-2,1) and (-1,2,3) )

1

Je ne sais si cela t'intéresse mais pour "m'amuser" je viens d'essayer de créer un outil à partir de ton écriture de quaternions

j'espère qu'il fonctionne correctement (je n'ai fait qu'une seule vérification : le résultat pour Outil1(test1,test2) est correct)

1

thanks

1

Hi mrahikka!

Your product Tu(p,q) is the same as p*q and GG interprets it as product of the first component and the second component with each other:

So Tu(p,q)={3,(1,-2,1)}*{2,(-1,2,3)}={3*2,(1,-2,1)*(-1,2,3)}={6,-1*1+2*(-2)+3*1}={6,-2}

GG does not know, that a and b in the definition of your function Tu(a,b) are not numbers, but of the form a=(a1,(a2,a3,a4)) with ak real numbers, so it interprets a and a(1) as real number.

One way to define your product is using this: https://en.wikipedia.org/wi...

Take a look at the attached file.

Hope that helps you and kind regards

mire2

1

@mire2

erreur : il manque -Elément(p, 2)*Elément(q, 2) dans la composante numérique

1

Yes, I am forgetful ... and in addition to I think you have to replace in the second component cross(Element(p,2),(Element(q,2)) by: cross(vector(Element(p,2)),vector((Element(q,2)))

Hope that it is now correct.

1

thanks