How can I create and add a variable to a vector?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Andrew Newell
on 6 Feb 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 Comments
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!