Adding number in a sequence

7 vues (au cours des 30 derniers jours)
Abul Hasib
Abul Hasib le 21 Sep 2019
Commenté : Guillaume le 21 Sep 2019
How do i make a code,where I have to add the previous numbers to next numbers in a sequence. I used a for loop
for jj=0:13
x=jj
this code gives me the value of 0 to 13.right?
but I need to add all the terms with a previous term . what can I do?
  3 commentaires
Abul Hasib
Abul Hasib le 21 Sep 2019
Modifié(e) : Abul Hasib le 21 Sep 2019
n=[1:15]
while n==isprime(n)
for n=1:15
for jj=0:16
x=(n+jj)^(99/100)
end
end
end
thats what I have done so far,,but I need to add the values of x with each other. when i run the function i only ge6t the name of the file on the command window ,,no output except for the array of n in 1st line
Guillaume
Guillaume le 21 Sep 2019
I have absolutely no idea what you're attempting to do with that code. It doesn't make any sense.
i only ge6t the name of the file on the command window ,,no output except for the array of n in 1st line
That would be because the while condition is not true to start with. So the code inside the while is never executed and only the first line has any effect.
Note that isprime return either 0 or 1. So if n is scalar, n == isprime(n) will definitively be false for any n different from 0 or 1. And since isprime is 0, the only n value for which n == isprime(n) is true is n = 0. But also note that your n is a vector.

Connectez-vous pour commenter.

Réponses (1)

David Hill
David Hill le 21 Sep 2019
  2 commentaires
Abul Hasib
Abul Hasib le 21 Sep 2019
Modifié(e) : Abul Hasib le 21 Sep 2019
what does the 2 do in that function? I am new to matlab,,so i am having hard time putting these all togteher. also it said for the value of n=-13, x should be 63.6
David Hill
David Hill le 21 Sep 2019
You can lookup the function. Matlab has great descriptions.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by