Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h3>Power Law Calculator</h3>
<p>Enter three data points (Duration in minutes and Power in watts):</p>

<label for="x1">Short effort duration (minutes):</label>
<input type="number" id="x1" placeholder="e.g. 10"><br>

<label for="y1">Short effort power (watts):</label>
<input type="number" id="y1" placeholder="e.g. 300"><br>

<label for="x2">Medium effort duration (minutes):</label>
<input type="number" id="x2" placeholder="e.g. 20"><br>

<label for="y2">Medium effort power (watts):</label>
<input type="number" id="y2" placeholder="e.g. 250"><br>

<label for="x3">Long effort duration (minutes):</label>
<input type="number" id="x3" placeholder="e.g. 40"><br>

<label for="y3">Long effort power (watts):</label>
<input type="number" id="y3" placeholder="e.g. 200"><br>

<button onclick="calculatePotentialFit()">Calculate</button>

<h4>Results:</h4>
<p><strong>Estimated function:</strong> <span id="functionOutput"></span></p>
<p><strong>Power loss when duration doubles:</strong> <span id="powerLoss"></span>%</p>
<p><strong>Calculated values:</strong></p>
<ul id="valuesOutput"></ul>


              
            
!

CSS

              
                HTML CSS JSResult Skip Results Iframe
EDIT ON
#calculator {
  max-width: 400px;
  margin: auto;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background-color: #f9f9f9;
  text-align: center;
}

input {
  width: 80px;
  margin: 5px;
}

button {
  padding: 10px 20px;
  background-color: #0073aa;
  color: white;
  border: none;
  cursor: pointer;
  margin-top: 10px;
}

button:hover {
  background-color: #005177;
}
              
            
!

JS

              
                function calculatePotentialFit() {
  let x = [
    parseFloat(document.getElementById("x1").value),
    parseFloat(document.getElementById("x2").value),
    parseFloat(document.getElementById("x3").value)
  ];

  let y = [
    parseFloat(document.getElementById("y1").value),
    parseFloat(document.getElementById("y2").value),
    parseFloat(document.getElementById("y3").value)
  ];

  // Transformar datos a escala logarítmica para regresión potencial
  let logX = x.map((val) => Math.log(val));
  let logY = y.map((val) => Math.log(val));

  // Cálculo de los coeficientes de regresión potencial
  let sumLogX = logX.reduce((a, b) => a + b, 0);
  let sumLogY = logY.reduce((a, b) => a + b, 0);
  let sumLogXLogY = logX
    .map((xi, i) => xi * logY[i])
    .reduce((a, b) => a + b, 0);
  let sumLogX2 = logX.map((xi) => xi * xi).reduce((a, b) => a + b, 0);

  let n = x.length;
  let b =
    (n * sumLogXLogY - sumLogX * sumLogY) / (n * sumLogX2 - sumLogX * sumLogX);
  let logA = (sumLogY - b * sumLogX) / n;
  let a = Math.exp(logA);

  // Mostrar la función obtenida
  document.getElementById("functionOutput").innerText = `y = ${a.toFixed(
    4
  )} * x^${b.toFixed(4)}`;

  // Calcular pérdida de potencia al duplicar X
  let powerLoss = (1 - Math.pow(2, b)) * 100;
  document.getElementById("powerLoss").innerText = powerLoss.toFixed(2);

  // Calcular valores en puntos específicos
  let timePoints = [5, 10, 20, 30, 60, 120, 180, 240, 300]; // Minutos
  let valuesOutput = document.getElementById("valuesOutput");
  valuesOutput.innerHTML = "";

  timePoints.forEach((t) => {
    let calculatedPower = a * Math.pow(t, b);
    valuesOutput.innerHTML += `<li>Duración: ${t} min - Potencia: ${calculatedPower.toFixed(
      2
    )}</li>`;
  });
}
              
            
!
999px

Console