Computing in Matlab, for a $n\times2$ matrix, for each row$\theta_{0}*\text{first element in row}+\theta_{1}*\text{second element in row}$

47 Views Asked by At

I have a matrix $A$ s.t each row is of length $2$ and with the first element $=1$ for example $$ A=\begin{pmatrix}1 & 2\\ 1 & 5\\ 1 & 4 \end{pmatrix} $$

I have a function $h(x)=\theta_{0}+\theta_{1}x$ . I defined $$ \theta=\begin{pmatrix}\theta_{0}\\ \theta_{1} \end{pmatrix} $$

and I would like to have a vector $$ v=\begin{pmatrix}h(2)\\ h(5)\\ h(4) \end{pmatrix} $$

I noted that if the rows are $r_{1},r_{2},r_{3}$ (for example $r_{1}=\begin{pmatrix}1 & 2\end{pmatrix}$) then: $$ v=\begin{pmatrix}r_{1}*\theta\\ r_{2}*\theta\\ r_{3}*\theta \end{pmatrix} $$

How can I use what I noted to compute $v$ ?

Currently, I Isolate the second column of $A$ and I apply the function on that vector, but I feel that by using the all $1$ column of $A$ we can calculate $v$ with the rows of $A$.

Note: The setting is a machine learning class, the all $1$ column was added for this reason, but I don't see how I can code this

1

There are 1 best solutions below

0
On BEST ANSWER

This is just the matrix - vector product $A \cdot \theta$.