I'm new to MATLAB and coding, so any help is much appreciated. I wanted to make a program that calculates the sum of an arithmetic progressions of natural numbers where you input N as the total natural number of terms in the sequence and the common difference between the terms is 1 and calculating it using the while loop. I have no idea how to code this program so I will be much grateful if anyone could help me. Thanks in advance!
CodePudding user response:
total number stands for N in your question. diff stands for difference of each term in arithmetic progression. start stands for initial value of given arithmetic progression.
total_number=5;
diff=3;
start=1;
sum=0;
i=1;
while i<=total_number
tmp=start diff*(i-1);
sum=sum tmp;
i=i 1;
end
I hope this answer helps.