B
B
Bernard Krapivin2018-09-22 16:40:54
JavaScript
Bernard Krapivin, 2018-09-22 16:40:54

How to add from zero to a certain number in a progression, in a certain number of steps in Javascript?

Hello!
I need to build a hyperbolic graph and for this I need an array of data.
I have a number, let's say 42, how to make it so that in 10 steps this number from zero reaches the desired value and increases exponentially ?
Each iteration must be pushed into an array.
That's what was smart enough, but here is a linear progression:

var target = 42;
var dataArr = [];
var modif = 0;
var iters = 10;
for (var i = 0; i <= iters; i++) {
  dataArr.push(modif);
  modif = modif + target / iters ;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Bernard Krapivin, 2018-09-22
@Bobrodon

Managed to get the desired result with this code:

var target = 42;
target = target+1;
var dataArr = [];
var modif = target;
var iters = 10;
 for (var i = 0; i <= iters; i++) {
  var resutl = modif;
  dataArr.push(resutl - 1);
  modif = Math.pow(modif, 0.7);
 }

console.log(dataArr)

It turned out such a graph with an initial number of 5.59
37a8cb9ef0.jpg

R
Rsa97, 2018-09-22
@Rsa97

Nothing from zero. An exponential progression is a·e kx . Solving the equation
a e kx = 0
will give you x = ±∞ for any finite non-zero k

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question