Creating mathematical charts using chart.js jQuery [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Have you got any ideas how to create user-interactive line math charts with chart.js library, something like in wolframalpha? I know that i need to calculate x and y to draw chart correctly and range. It should look like myExample I can do line charts with static data, put in a code but need to know how to draw it after user provide function e.g 2x+5. All ideas and tricks will be very useful :) Thanks

Use math.js to parse the string input into a function.
// If "input" is a variable representing the string input for y
var f = math.eval('f(x) = ' + input');
Then compute a range of values for f to pass into chart.js:
// If "min" and "max" are values representing the minimum and max values
var values = [],
var x = min;
var increment = (max - min) / 10000;
for (var i = 0; i < 10000; i++)
values[i] = f(x + increment * i);

Related

Javascript - Sum solution [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am getting below line in my source file and I would like to sum those values separated by pipe ("|")
There is no limit for the values coming in the line (might be 100 values)
10|20|30|40|[no limit for values] - Separator is pipe "|"
The ouptput would be 100
Please help to write a javascript function for the above query.
Regards
Jay
You should take a look at JavaScript's built-in functions: With split you can split your string into an array, with reduce you can 'reduce' your array to a single value, in that case via summation. These two links should provide you enough information for building your code.
You could try something like below:
function sum(value){
var total = 0;
var array = value.split(",").map(Number);
for( var i = 0; i < array.length; i++) {
total += array[i];
}
alert(total);
}
var value = "10|20|30|40".replace(/\|/g, ',');
console.log(sum(value));
https://jsfiddle.net/f7uqw7cL/

Library to read numbers from a string in JS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm asking if there is a method or library that reads easily numbers this type of input strings (like competitive programming):
2 3
0 1 20
1 2 2
0 2 17
I'm finding something like Scanner class of Java because it has methods to detect whether there is next number, it jumps to the next line,...
Thanks in advance!
Try with parseInt for reading numbers. Also you can get the array of numbers with strings like the ones you have provided with somehting like this:
var numbers = str.split(" ").map(function(item) { return parseInt(item); });
The best thing you can do is use functional programming to implement a set of methods you can use together in the way you see fit.
const byLine = (input) => input.split('\n');
const toInt = (el) => Number(el);
const getDigits = (el) => el.split(' ').map(toInt);
const flatten = (arr) => arr.reduce((p, c) => p.concat(c));
function scanner(input) {
return flatten(byLine(input).map(getDigits));
}
DEMO
If you have access to the lines, you could use the following:
var i, lines = [ /* your lines goes here */], row;
// get lines
for (i = 0; i < lines.length; i++) {
row = lines[i].split(' ').map(Number);
// do something with row
}

Ant System (pheromone trail) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How do I implement this in JavaScript? Thank you.
Ant System (AS) was the first ACO algorithm to be proposed in the literature (Dorigo et al. 1991, Dorigo et al. 1996). Its main characteristic is that the pheromone values are updated by all of the ants that have completed the tour. Solution components c_{i,j} are the edges of the graph, the pheromone update for \tau_{i,j}, that is, for the pheromone associated to the edge joining the cities i, and j, is performed as follows:
\tau_{i,j} <- (1-\rho)*\tau_{i,j} + \sum\limits_{k=1}^{m} \Delta\tau_{i,j}^{k}
Where the evaporation rate rho is in the interval (0,1], m is the number of ants, and \Delta*\tau_{i,j}^{k} is the quantity of pheromone laid on the the edge (i,j) by the k-th ant. If an ant uses an edge on its tour, the quantity of pheromone laid on that edge is calculated as follows,
\Delta\tau_{i,j}^{k} = 1/L_{k}
Where L_{k} is the tour length of the k-th ant. If an ant does not use the edge (i,j), then \Delta\tau_{i,j}^{k} is zero.
I'm trying....
pher[i][j]= pher[i][j] *(1.0-rho) + numAnts*(.......
So this is a sum example. But I don't understand the rest of the algorithm. Do you have any pheromone matrix for example?
function sumk2m(k0,m,f){
var result = 0;
for(var k = k0; k<m ; k++){
result = result+f(k);
}
return result
}
function isedgeintour(k){
//I don't know what's this!
}
function L(k){
//I don't know what's this either!
}
var deltapher = function (k){
if(isedgeintour(k)){
return 1/L(k);
} else {
return 0;
}
}
pher[i][j]= pher[i][j] *(1.0-rho) + sumk2m(1,numAnts,deltapher)

Javascript plugin for automatic rotation of images [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
need to let the images disappear and reappear like here (footer at) http://www.guiltypeople.nl/het-bureau/.
Each logo, disappear slowly, and reappear on a different place. Could you help me find a Javascript plugin or something to do this?
thanks
First: To overlap the images you must make a trick with position: absolute or play a bit with background. Check here, here and here.
TIP: If the position it's random and not a loop, you must implement a function which changes location of background hidden object's with jquery or javascript.
Second: When you have the images overlapped, you must make the transition effect. For this you must use a loop and the alpha css property.
In your original question you asked also for rotations and other FX, for this you don't need a plugin, check transforming with css.
Example of changin alpha property in plain javascript:
for (var i = 0; i <= 100;){
var element = document.getElementById('id');
element.style.opacity = i * 0.1;
element.style.filter = 'alpha(opacity=' + i + ')'; // IE fallback
i = i + 10;
}
You can use the iterations to make rotation also, or use less i increment to perform each action when mod condition is true, imagine you want to rotate 90 degrees 4 times and make image disapear in 10 steps:
i = i + 5; // allows 20 iterations
if (i % 25 == 0) // if you want 4 rotation steps
if (i % 10 == 0) // if you want 10 alpha modifications

javascript show progress bar while lengthy javascript calculations are in progress? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am coding a javascript based network application and in which i have to create array of 1000 rec which generate random numbers between 0 and 1 as
for (var i = 0; i < 1000; i++) {
rec[i] = Math.random();
}
it takes some seconds to generate all random numbers and show it on a div so i just want to ask to how to show progress bar while it generating values?
Are you doing something daft like writing or appending values to the DOM within the loop - thus forcing the browser to try and redraw the screen each iteration...
example 1: fiddle - 4000ms+ (for me)
for (var i = 0; i < 1000; i++) {
rec[i] = Math.random();
document.getElementById('out').innerHTML += ('<br/>'+rec[i]);
}
example 2: fiddle - 10ms (or thereabout)
for (var i = 0; i < 1000; i++) {
rec[i] = Math.random();
}
document.getElementById('out').innerHTML = rec.join('<br/>');
It should not take seconds to generate a 1000 random numbers. In comparison I'm typing this on an 8 year old laptop with a crappy Centrino processor and a simple test produces somewhere in the region of 420,000 random numbers within a second.

Categories

Resources