How can I use a for loop to find the summation of a set variable and set number of terms
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
macabe banchero
il 7 Mar 2018
Commentato: macabe banchero
il 7 Mar 2018
So I was given the task of creating a UDF that has to do the following:(1) accepts input values for a variable, x, and a set number of terms N.(2) calculate the value of f(x) using N terms and (3) return output value of f(x). Here is what I have so far:
x = input('variable x');
n = input('number of terms, n');
for N = (0:n)
y = sum(x.^N)
end
When I enter in x=2 and n=6 for example, I know the answer is supposed to be 127. But I am not getting the answers summed up, but separate instead. How do I fix this? Thanks.
0 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!