how to you multiply a 4x4 matrix with a vector 4x1?

4x4 matrix a a vector of [x, y, z, 1]

in java perhaps?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    | a₁₁ a₁₂ a₁₃ a₁₄ | . . | x | . . | a₁₁x + a₁₂y + a₁₃z + a₁₄ |

    | a₂₁ a₂₂ a₂₃ a₂₄ | .*. | y| .= | a₂₁x + a₂₂y + a₂₃z + a₂₄ |

    | a₃₁ a₃₂ a₃₃ a₃₄ | . . | z | . . | a₃₁x + a₃₂y + a₃₃z + a₃₄ |

    | a₄₁ a₄₂ a₄₃ a₄₄ | . . | 1 | . . | a₄₁x + a₄₂y + a₄₃z + a₄₄ |

    If you're coding this in a program, you can do it as follows (sorry, I don't program in java, so I am using Turing):

    -------------------- --------------------

    First we define a 4x4 array A, variables x, y, z, and a one-dimensional array B with 4 elements. (B will be solution of A x V)

    Code should be similar to this:

    for i : 1..4

    ` ` B(i) := A(i,1)*x + A(i,2)*y, A(i,3)*z + A(i,4)

    end for

    Note: ` ` characters are there just to create spacing. They don't mean anything.

    -------------------- --------------------

    An alternate method is to keep values of x, y, z, 1 in a one-dimensional array (with 4 elements) named V

    Then we can use nested for statements to calculate B:

    for i: 1..4

    ` ` B(i) := 0

    ` ` for j: 1..4

    ` ` ` ` B(i) := B(i) + A(i,j)*V(j)

    ` ` end for

    end for

    • Login to reply the answers
  • 4 years ago

    | a₁₁ a₁₂ a₁₃ a₁₄ | . . | x | . . | a₁₁x + a₁₂y + a₁₃z + a₁₄ |

    | a₂₁ a₂₂ a₂₃ a₂₄ | .*. | y| .= | a₂₁x + a₂₂y + a₂₃z + a₂₄ |

    | a₃₁ a₃₂ a₃₃ a₃₄ | . . | z | . . | a₃₁x + a₃₂y + a₃₃z + a₃₄ |

    | a₄₁ a₄₂ a₄₃ a₄₄ | . . | 1 | . . | a₄₁x + a₄₂y + a₄₃z + a₄₄ |

    • Login to reply the answers
Still have questions? Get your answers by asking now.