Please help me write a MATLAB program that constructs a column matrix b, such that
b1 = 3x1 – 3/4y0
b2 = 3x2
…
bn-2 = 3xn-2
bn-1 = 3xn-1 – 3/4yn
where x and y are variables. Notice that y only appears in the first and last entries of b.
My problem is that I don’t know how variables work in MATLAB. I tried
b = 3*x
and it says
??? Undefined function or variable ‘x’
So, how do we create variables instead of constants?
Thanks!
EDIT:
From your comments above, what you need is MATLAB’s symbolic toolbox, which allows you to perform computations in terms of variables (without assigning an explicit value to them). Here’s a small example:
You will need to use
expandsometimes to get the full form of the polynomial, because the default behaviour is to keep it in its simplest form, which is(1+x)^2. Here’s another example to find the roots of a general quadraticI think you meant
bnandxnin the last line… Anyway, here’s how you do it:You can also do it in a single line as
where
nis the length of your vector.