for loop to create a vector V of the squares
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Use a for loop to create a vector V of the squares of the numbers -25 through 25.
I am looking for some help to get me started writing the code and help writing it itself. I am unsure of where to even start with this problem. Thanks in advance.
0 commentaires
Réponse acceptée
the cyclist
le 16 Sep 2019
Because this is a very basic MATLAB question, and you don't even know how to start, I would recommending watching the MATLAB Onramp tutorial.
3 commentaires
the cyclist
le 16 Sep 2019
It's a conundrum, because doing this calculation using a for loop is very "anti-MATLAB". "Making a vector of the squares" leaps right to the answer, and can be done in one line without a for loop -- and is actually the best way to do this.
But since your instructor is presumably trying to teach you about for loops ...
I suggest that you first decide on your algorithm, without writing any MATLAB code. Write down the list of steps. The first step might be "create an object with all the values from -25 to 25", for example. Then, convert those steps into MATLAB code.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!