How can I create and add a variable to a vector?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have an assignment which asks me to take a set of vectors of the form :
3 0 h 0 0
and compute a set of orthonormal vectors such that the span of both sets is the same.
What I need to know is. How can I have the h in the vector as a variable, so that when I apply the algorithm to the vectors it treats the h as a number, but sort of, shows the expression for the result.
Simply entering "a = [1;0;h;0;0]" returns "??? Undefined function or variable 'h'."
I am very new to Matlab so the answer might be very simple, or Matlab just doesn't do it. I don't know.
0 comentarios
Respuestas (1)
Andrew Newell
el 6 de Feb. de 2011
If you have the Symbolic Toolbox, you can do this:
syms h
a = [3 0 h 0 0]
If not, you could create a function, for example this inline function:
createVector = @(x) [3 0 x 0 0]
so
a = createVector(1)
give
a =
3 0 1 0 0
In that case you would get a numeric answer for your set of orthonormal vectors.
0 comentarios
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!