Why can't I write this row vector?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Armando MAROZZI
am 22 Mär. 2020
Kommentiert: Armando MAROZZI
am 22 Mär. 2020
I simply want a 1x3 row vector like this:
. I tried the following:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278700/image.png)
[x(1,3); x(2,3); x(3,3)]
but I got the following error:
Unrecognized function or variable 'x'.
Why? How to sort it out?
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 22 Mär. 2020
Bearbeitet: John D'Errico
am 22 Mär. 2020
Very often, people who are just starting to use MATLAB, think that if you don't know the value of something, then it must be symbolic. That is not always true. I'll give some examples later. But to do what you are asking right now, just do this:
X = sym('X',[1,3])
X =
[X1, X2, X3]
As I said, you can have an unknown that will then be estimated. For example, if we stay in the purely numerical domain, we can solve for an unknown vector. This eample is pretty simple, but...
fun = @(X) sum((X - [1 2 3]).^2);
Xinit = [4 4 4];
Xfinal = fminsearch(fun,Xinit)
Xfinal =
0.99999144502901 1.99997109582809 2.99995541073201
Of course, the minimum arises at the vector [1 2 3].
1 Kommentar
Weitere Antworten (1)
Image Analyst
am 22 Mär. 2020
Define x somehow before that line, like these examples
x = magic(3)
x = rand(3)
x = randi(100, 3, 3)
or whatever.
3 Kommentare
Image Analyst
am 22 Mär. 2020
Bearbeitet: Image Analyst
am 22 Mär. 2020
I don't have that toolbox so I don't know what kind of assumptions it makes. I've added it to the product list, which you forgot to do when you created this posting.
What are you going to do after that? How are you going to use x? Or that 3 element, 1-D column vector you're trying to make from the 2-D x matrix?
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!