How can I increment a vector by squaring?

1 Ansicht (letzte 30 Tage)
Muhammad Musa Raza
Muhammad Musa Raza am 3 Okt. 2017
Beantwortet: Darren Sill am 3 Okt. 2017
I've been asked to write and display a vector" v = [1ˆ2, 3ˆ2, 5ˆ2, ..., (2n+1)ˆ2]". So how would I write the increment for that?
  1 Kommentar
James Tursa
James Tursa am 3 Okt. 2017
What have you done so far? What specific problems are you having with your code?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 3 Okt. 2017
To square a vector element by element, you use .^2:
v = v .^ 2;
And constructing a v of [1,3,5,...] is trivial. Not sure what that has to do with incrementing a vector. Squaring is not incrementing by the normal definition of incrementing, where each element has the same number added to it, like v = v + increment.

Darren Sill
Darren Sill am 3 Okt. 2017
If you have your vector already defined, you can use the dot operator to square each term individually. I.e.
x = [1 2 3 4];
x.^2
Will return the vector [1 4 9 16]. Is that what you are asking?

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by