benchmarks.wiki / Public workspace

SciCode / 38.1 / Given two vectors, return the cross-product of these two vectors. The input…

Problem

Answer published by the source. Consult the official source to check your work against its answer.

step background

Background Given the two input vectors $$ \begin{aligned} & \mathbf{a}=a_1 \mathbf{i}+a_2 \mathbf{j}+a_3 \mathbf{k} \\ & \mathbf{b}=b_1 \mathbf{i}+b_2 \mathbf{j}+b_3 \mathbf{k} \end{aligned} $$ their cross product a × b can be expanded using distributivity: $$ \begin{aligned} \mathbf{a} \times \mathbf{b}= & \left(a_1 \mathbf{i}+a_2 \mathbf{j}+a_3 \mathbf{k}\right) \times\left(b_1 \mathbf{i}+b_2 \mathbf{j}+b_3 \mathbf{k}\right) \\ = & a_1 b_1(\mathbf{i} \times \mathbf{i})+a_1 b_2(\mathbf{i} \times \mathbf{j})+a_1 b_3(\mathbf{i} \times \mathbf{k})+ \\ & a_2 b_1(\mathbf{j} \times \mathbf{i})+a_2 b_2(\mathbf{j} \times \mathbf{j})+a_2 b_3(\mathbf{j} \times \mathbf{k})+ \\ & a_3 b_1(\mathbf{k} \times \mathbf{i})+a_3 b_2(\mathbf{k} \times \mathbf{j})+a_3 b_3(\mathbf{k} \times \mathbf{k}) \end{aligned} $$ From this decomposition, by using the above-mentioned equalities and collecting similar terms, we obtain: $$ \begin{aligned} \mathbf{a} \times \mathbf{b}= & a_1 b_1 \mathbf{0}+a_1 b_2 \mathbf{k}-a_1 b_3 \mathbf{j} \\ & -a_2 b_1 \mathbf{k}+a_2 b_2 \mathbf{0}+a_2 b_3 \mathbf{i} \\ & +a_3 b_1 \mathbf{j}-a_3 b_2 \mathbf{i}+a_3 b_3 \mathbf{0} \\ = & \left(a_2 b_3-a_3 b_2\right) \mathbf{i}+\left(a_3 b_1-a_1 b_3\right) \mathbf{j}+\left(a_1 b_2-a_2 b_1\right) \mathbf{k} \end{aligned} $$ For column vectors, we can represent the same result as follows: $$ \mathbf{a} \times \mathbf{b}=\left[\begin{array}{l} a_2 b_3-a_3 b_2 \\ a_3 b_1-a_1 b_3 \\ a_1 b_2-a_2 b_1 \end{array}\right] $$
Plain-text mathematical notation (without MathML)
Background
Given the two input vectors
$$
\begin{aligned}
& \mathbf{a}=a_1 \mathbf{i}+a_2 \mathbf{j}+a_3 \mathbf{k} \\
& \mathbf{b}=b_1 \mathbf{i}+b_2 \mathbf{j}+b_3 \mathbf{k}
\end{aligned}
$$
their cross product a × b can be expanded using distributivity:
$$
\begin{aligned}
\mathbf{a} \times \mathbf{b}= & \left(a_1 \mathbf{i}+a_2 \mathbf{j}+a_3 \mathbf{k}\right) \times\left(b_1 \mathbf{i}+b_2 \mathbf{j}+b_3 \mathbf{k}\right) \\
= & a_1 b_1(\mathbf{i} \times \mathbf{i})+a_1 b_2(\mathbf{i} \times \mathbf{j})+a_1 b_3(\mathbf{i} \times \mathbf{k})+ \\
& a_2 b_1(\mathbf{j} \times \mathbf{i})+a_2 b_2(\mathbf{j} \times \mathbf{j})+a_2 b_3(\mathbf{j} \times \mathbf{k})+ \\
& a_3 b_1(\mathbf{k} \times \mathbf{i})+a_3 b_2(\mathbf{k} \times \mathbf{j})+a_3 b_3(\mathbf{k} \times \mathbf{k})
\end{aligned}
$$

From this decomposition, by using the above-mentioned equalities and collecting similar terms, we obtain:

$$
\begin{aligned}
\mathbf{a} \times \mathbf{b}= & a_1 b_1 \mathbf{0}+a_1 b_2 \mathbf{k}-a_1 b_3 \mathbf{j} \\
& -a_2 b_1 \mathbf{k}+a_2 b_2 \mathbf{0}+a_2 b_3 \mathbf{i} \\
& +a_3 b_1 \mathbf{j}-a_3 b_2 \mathbf{i}+a_3 b_3 \mathbf{0} \\
= & \left(a_2 b_3-a_3 b_2\right) \mathbf{i}+\left(a_3 b_1-a_1 b_3\right) \mathbf{j}+\left(a_1 b_2-a_2 b_1\right) \mathbf{k}
\end{aligned}
$$

For column vectors, we can represent the same result as follows:

$$
\mathbf{a} \times \mathbf{b}=\left[\begin{array}{l}
a_2 b_3-a_3 b_2 \\
a_3 b_1-a_1 b_3 \\
a_1 b_2-a_2 b_1
\end{array}\right]
$$
Original LaTeX notation
Background
Given the two input vectors
$$
\begin{aligned}
& \mathbf{a}=a_1 \mathbf{i}+a_2 \mathbf{j}+a_3 \mathbf{k} \\
& \mathbf{b}=b_1 \mathbf{i}+b_2 \mathbf{j}+b_3 \mathbf{k}
\end{aligned}
$$
their cross product a × b can be expanded using distributivity:
$$
\begin{aligned}
\mathbf{a} \times \mathbf{b}= & \left(a_1 \mathbf{i}+a_2 \mathbf{j}+a_3 \mathbf{k}\right) \times\left(b_1 \mathbf{i}+b_2 \mathbf{j}+b_3 \mathbf{k}\right) \\
= & a_1 b_1(\mathbf{i} \times \mathbf{i})+a_1 b_2(\mathbf{i} \times \mathbf{j})+a_1 b_3(\mathbf{i} \times \mathbf{k})+ \\
& a_2 b_1(\mathbf{j} \times \mathbf{i})+a_2 b_2(\mathbf{j} \times \mathbf{j})+a_2 b_3(\mathbf{j} \times \mathbf{k})+ \\
& a_3 b_1(\mathbf{k} \times \mathbf{i})+a_3 b_2(\mathbf{k} \times \mathbf{j})+a_3 b_3(\mathbf{k} \times \mathbf{k})
\end{aligned}
$$

From this decomposition, by using the above-mentioned equalities and collecting similar terms, we obtain:

$$
\begin{aligned}
\mathbf{a} \times \mathbf{b}= & a_1 b_1 \mathbf{0}+a_1 b_2 \mathbf{k}-a_1 b_3 \mathbf{j} \\
& -a_2 b_1 \mathbf{k}+a_2 b_2 \mathbf{0}+a_2 b_3 \mathbf{i} \\
& +a_3 b_1 \mathbf{j}-a_3 b_2 \mathbf{i}+a_3 b_3 \mathbf{0} \\
= & \left(a_2 b_3-a_3 b_2\right) \mathbf{i}+\left(a_3 b_1-a_1 b_3\right) \mathbf{j}+\left(a_1 b_2-a_2 b_1\right) \mathbf{k}
\end{aligned}
$$

For column vectors, we can represent the same result as follows:

$$
\mathbf{a} \times \mathbf{b}=\left[\begin{array}{l}
a_2 b_3-a_3 b_2 \\
a_3 b_1-a_1 b_3 \\
a_1 b_2-a_2 b_1
\end{array}\right]
$$

step description prompt

Given two vectors, return the cross-product of these two vectors. The input should be two numpy arrays and the output should be one numpy array.

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import