Can not find information on how to graph an equation that does not contain x or y variables. Trying to graph the following equation:
N= (v*12) /(3.1415 * D)
Will assign D a value from a dropdown list.
How do I assign the N and v variables to the x and y axis.
Hi,
Welcome to the community!
You need to create a range of values for v
, then apply the equation for N
. One way to do it in js is:
const range = (start, stop, step) => {
let v=start
const array = []
while(v <= stop){
array.push(v);
v=v+step
}
return array;
}
// For example
const v = range(0, 10, 0.5);
const Nfunc = (v, D) => 12 * v / (Math.PI * D); // I assume you want Pi = 3.1415....
// Then...
const N = v.map(x => Nfunc(x, D));
Thanks,
Still having trouble making this work. Need a complete working example with html, script code.
Try this:
<head>
<script src='https://cdn.plot.ly/plotly-2.11.1.min.js'></script>
</head>
<body>
<div id='myDiv'></div>
</body>
<script>
const range = (start, stop, step) => {
let v=start
const array = []
while(v <= stop){
array.push(v);
v=v+step
}
return array;
}
// For example
const D = 1.0;
const v = range(0, 10, 0.5);
const Nfunc = (v, D) => 12 * v / (Math.PI * D); // I assume you want Pi = 3.1415....
// Then...
const N = v.map(x => Nfunc(x, D));
const trace1 = {
x: v,
y: N,
mode: 'markers',
type: 'scatter'
};
const data = [trace1];
Plotly.newPlot('myDiv', data);
</script>
Still getting a JavaScript error that range is not defined.
<!DOCTYPE html>
<html>
<head>
<script src='https://cdn.plot.ly/plotly-2.11.1.min.js'></script>
</head>
<body>
<div id='myDiv'></div>
</body>
<script>
// For example
const D = 1.0;
const v = range(0, 10, 0.5);
const Nfunc = (v, D) => 12 * v / (Math.PI * D);
// Then...
const N = v.map(x => Nfunc(x, D));
const trace1 = {
x: v,
y: N,
mode: 'markers',
type: 'scatter'
};
const data = [trace1];
Plotly.newPlot('myDiv', data);
</script>
</html>
Yeah, but you deleted this part from my example…
Thanks,
That worked.