How can I create and add a variable to a vector?

조회 수: 2 (최근 30일)
lamborman
lamborman 2011년 2월 6일
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.

답변 (1개)

Andrew Newell
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.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by