How to put vector components into one single matrix and instead having them appear as two separate arrays
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Typing [1 2; 3 4] in the command window gives the output [1 2 3 4] %(with 3 and 4 on the second row) but typing a square matrix with dummy variables outputs two separate arrays, i.e. [2*x 1; 2 x*y] gives [2x, 1] and [2, xy] instead of [2x 1 2 xy] %(with 2 and xy on the second row). When I iterate over the matrix with dummy variables, i(1,1) outputs 2x and 1 instead of 2x. How can I put the two arrays into one matrix?
I want [2*x 1; 2 x*y] to output [2x 1
2 xy]
0 Commenti
Risposte (1)
John D'Errico
il 25 Set 2021
Modificato: John D'Errico
il 25 Set 2021
A very confusing question. But what about this does not do as you want?
syms x y
A = [2*x 1; 2 x*y]
Admittedly, that is as shown using the livescript form that Answers allows me to post online.
The array is a 2x2 array, containing the variables x and y. Perhaps you don't like the output as MATLAB normally posts to the command window.
syms x y
A = [2*x 1; 2 x*y]
A =
[2*x, 1]
[ 2, x*y]
This is still the same array. Just that the symbolic toolbox is more restricted in what it can show in the command window. Remember that the command window is a purely text interface.
But you can also do this:
pretty(A)
/ 2 x, 1 \
| |
\ 2, x y /
Which may be slightly closer to what you want to see. But pretty has its limits.
Honestly, this is all just cosmetic. There are no true differences. Mathematics is still mathematics.
If you get upset at seeing the standard form posted by MATLAB to the command window, then perhaps you need to be using livescript instead.
3 Commenti
John D'Errico
il 25 Set 2021
Modificato: John D'Errico
il 25 Set 2021
Nope. Still clear as mud. Perhaps your problem is you are not resolving the roots of that equation. You can use solve to do that, by specifying a maxdegree property.
Or perhaps your problem is eq1 and eq2 are IDENTICAL in what you claim to show the problem. And that means the example you show is meaningless and impossible.
If you want a more helpful answer, you need to show an actual example of the problem you are solving, that fails to do what you want. At the very least, you need to show an example problem that actually makes sense. The example you show is meaningless, since it duplicates the two equations. Then explain clearly what you are hoping to see as a result.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!