Can someone give an example of a for loop for this problem?: Find the sum of 30 numbers that increments by 3. The starting number is 4. Thanks!

1 Ansicht (letzte 30 Tage)
Just a simple for loop please. Nothing too complicated. Thank you again.
  2 Kommentare
Steven Lord
Steven Lord am 7 Dez. 2018
In general if you post a question like this that sounds like a homework assignment, even if it isn't a homework assignment, I recommend posting what you've tried and asking for help improving and/or fixing it. The problem might be as simple as a typo in your code, and seeing that code may allow someone to respond within seconds with the easy fix.
From your question itself, I'm guessing you're fairly new to MATLAB. If that's right, consider going through the free MATLAB Onramp course in the Tutorial section on the Support page if you haven't already. [Click Support in the bar at the top of this page.] It will teach you some of the basics of MATLAB and perhaps fill in any gaps in what you've learned so far.
TSmith
TSmith am 10 Dez. 2018
Ok. Thank you. Yes, I'm new to Matlab and just completed an intro course to it. I've understood everything so far except for and while loops. Thanks for your advice.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 7 Dez. 2018
x = sum(4:3:(4+3*(30-1)))
  8 Kommentare
John D'Errico
John D'Errico am 10 Dez. 2018
Bearbeitet: John D'Errico am 10 Dez. 2018
@Madhan - don't worry about upvotes anyway. Reputation is not important, and there is no race to the top. Your responses are appreciated, improving the site with your presence, regardless of an upvote or not..

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 7 Dez. 2018
Read about sum() and cumsum() loops are superfluous in this case
  9 Kommentare
madhan ravi
madhan ravi am 7 Dez. 2018
Yes I just saw your comment in your previous question @TSmith , Best of luck!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by