creating a 8x8 matrix with only -1

i want to create a 8x8 matrix withn only the number -1 how do i do it?

Answers (3)

Torsten
Torsten on 27 Oct 2024
Moved: Torsten on 27 Oct 2024
Use "ones" to build a matrix of ones and multiply it by (-1).

1 Comment

You have to be careful to build up the 8 x 8 size for the ones() call, out of pure -1's. It is certainly possible to do.

Sign in to comment.

埃博拉酱
埃博拉酱 on 28 Oct 2024
Edited: 埃博拉酱 on 29 Oct 2024
-ones(8)
Append at 20241029 as a Cody challenge:
rand(single('('-' '))
%You don't even need -1 in your code. This can be applied to any challenge that has a limit on the number that appears in the code.
%If you're okay with using characters that aren't on your keyboard, you can even just use a Backspace character (U+0008).

6 Comments

This uses 8, which violates the rule that only -1 can be used.
Torsten
Torsten on 28 Oct 2024
Edited: Torsten on 28 Oct 2024
This is a very willful interpretation of the task. My guess was it's simply to create a 8x8 matrix of -1's.
Yes, any normal person would generate an 8×8 matrix of -1 all the way I wrote it. If you mean that the number that appears in the code can only have -1, I guess this is more appropriate as a Cody challenge rather than as a question in the Answers forum, which is more geared towards practical scenarios.
Excluding parentheses, arithmetic operators, and the output variable name, this uses nothing but negative ones (pun intended)
A = -ones((-1 + -1 + -1 + -1)*(-1 + -1))
A = 8×8
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
The + are not needed
A = -ones((-1 -1 -1 -1)*(-1 -1))
A = 8×8
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
D'oh!
I must have had my blinders on when I was coming up with that.

Sign in to comment.

Aimee
Aimee on 29 Oct 2024
hey guys thanks for all the help i got it eventuallyt with the code A = -ones(8,8). just incase anyone sees this and need help in the future.

7 Comments

Or you could simply do
A = [
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 ]
though that's not a very MATLABy way of doing it, but it does use only -1's and no 8's.
Walter Roberson
Walter Roberson on 29 Oct 2024
Edited: Image Analyst on 30 Oct 2024
This (Aimee's) solution involves the number 8, contrary to the requirement that the solution involves only -1
埃博拉酱
埃博拉酱 on 30 Oct 2024
Edited: 埃博拉酱 on 30 Oct 2024
This shows that @Walter Roberson is over-reading OP's question. He just wants an 8×8 matrix of -1s.
The requirement is "creating a 8x8 matrix with only -1" . Using an 8 in the command does not fit the requirement.
I'm not a native speaker, but isn't the usual interpretation of "creating a 8x8 matrix with only -1":
create a 8x8 matrix which has only -1's as elements
?
DGM
DGM on 30 Oct 2024
Edited: DGM on 30 Oct 2024
As a counterexample, "create fire with only flint and steel" typically does not imply that the fire contains either flint or steel. Maybe we're all wrong to be creating a matrix full of -1.
no youre correct i wanted an 8x8 matrix where the only elements were -1 i managed it eventually with the formula i used above though.

Sign in to comment.

Categories

Find more on Historical Contests in Help Center and File Exchange

Products

Release

R2024b

Asked:

on 27 Oct 2024

Commented:

on 10 Dec 2024

Community Treasure Hunt

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

Start Hunting!