How can I create and add a variable to a vector?
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Andrew Newell
2011 年 2 月 6 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!