I have 2 vectors that are scalar multiples of each other but their components have an unknown 'z'. ie
v1=[a, bz+c, e-zd ]
v2=[e, fz+g, h+z]
Only z is a variable/unknown, the rest are just numeric coefficients. How do i solve this using matlab??
I tried using linsolve but it doesnt seem to support symbolic arguments (z).
$k$ and $z$ can be found fairly quickly by hand. However, since you are interested in formulating it using Matlab, let us consider that instead. The equations to be solved are
\begin{align} a &= k e \\ b z + c &= k (f z + g) \\ e - z d &= k (h + z), \end{align}
where $k$ is some unknown constant of proportionality. Note: Since $k$ and $z$ are both unknowns, this is no longer a system of linear equations; instead it is a system of nonlinear equations. To formulate this in Matlab, we can use
fsolve. First let us reformulate the problem as follows. First\begin{align} a - k e &= 0 \\ b z + c - k (f z + g) &= 0 \\ e - z d - k (h + z) &= 0. \end{align}
The system of nonlinear equations can now be formulated as solving the equation $\textbf{F}(\textbf{x}) = \textbf{0}$, where
\begin{equation} \textbf{F}(\textbf{x}) = \begin{bmatrix} a - k e \\ b z + c - k (f z + g) \\ e - z d - k (h + z) \end{bmatrix} \text{ and } \textbf{x} = \begin{bmatrix} k \\ z \end{bmatrix}. \end{equation}
For example, to use
fsolveto solve the above function, you could typewhere the initial guess for the solver is
x0 = [0; 0], the solution (if it exists) isx,fvalshould be approximately equal to0, andexitflagdescribes iffsolvewas able to find a solution (see thefsolvehelp page for more info). If there is no solution, then you might need to do some nonlinear optimization, but hopefully there will be a solution.