This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2023' into nonlinear-constrained-optimizatoin
- Loading branch information
Showing
6 changed files
with
309 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Profit Calculation</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js"></script> | ||
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> | ||
<style> | ||
.slider { | ||
display: block; | ||
margin-bottom: 10px; | ||
width: 100%; | ||
} | ||
.slider-container { | ||
display: grid; | ||
grid-template-columns: repeat(3, 1fr); | ||
grid-gap: 10px; | ||
width: 100%; | ||
} | ||
.output { | ||
margin-top: 20px; | ||
padding: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
background-color: #f9f9f9; | ||
} | ||
.output p { | ||
margin: 5px 0; | ||
} | ||
.output .emoji { | ||
font-size: 20px; | ||
margin-right: 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="sliderContainer" class="slider-container"></div> | ||
<div id="outputContainer" class="output"></div> | ||
|
||
<script> | ||
function func(a, b, c) { | ||
var xi = [0.97, 0, 0.5, 0.85, 0.7, 0.19, 0.41, 0.78]; | ||
var yi = [0.97, 0.06, 0.7, 0.74, 0.2, 0.34, 0.29, 0.94]; | ||
var x_range = numeric.linspace(0.0001, 1, 100); | ||
|
||
var y_est = numeric.add(numeric.mul(a, numeric.pow(xi, b)), c); | ||
var error = numeric.sum(numeric.pow(numeric.sub(yi, y_est), 2)); | ||
var title = 'Total error squared = ' + error.toFixed(4); | ||
|
||
var data = [ | ||
{ | ||
x: xi, | ||
y: yi, | ||
type: 'scatter', | ||
mode: 'markers', | ||
name: 'Data points' | ||
}, | ||
{ | ||
x: x_range, | ||
y: numeric.add(numeric.mul(a, numeric.pow(x_range, b)), c), | ||
type: 'scatter', | ||
mode: 'lines', | ||
name: 'Curve fit' | ||
} | ||
]; | ||
|
||
var layout = { | ||
xaxis: { | ||
title: 'x', | ||
range: [0, 1] | ||
}, | ||
yaxis: { | ||
title: 'y', | ||
range: [0, 1] | ||
}, | ||
showlegend: true, | ||
title: { | ||
text: title, | ||
font: { | ||
size: 16 | ||
} | ||
} | ||
}; | ||
|
||
Plotly.newPlot('outputContainer', data, layout); | ||
|
||
// Add arrows to the plot | ||
for (var i = 0; i < xi.length; i++) { | ||
var arrow = { | ||
x: [xi[i], xi[i]], | ||
y: [yi[i], Math.max(Math.min(a * xi[i] ** b + c, 1), 0)], | ||
mode: 'lines', | ||
line: { | ||
color: 'red', | ||
width: 1, | ||
dash: 'dash' | ||
}, | ||
showlegend: false | ||
}; | ||
data.push(arrow); | ||
} | ||
|
||
Plotly.update('outputContainer', data, layout); | ||
} | ||
|
||
var sliderContainer = document.getElementById("sliderContainer"); | ||
var sliders = [ | ||
{ id: "a", min: 0, max: 5, value: 2, step: 0.01, description: "a" }, | ||
{ id: "b", min: 0, max: 5, value: 2, step: 0.01, description: "b" }, | ||
{ id: "c", min: 0, max: 1, value: 0, step: 0.01, description: "c" } | ||
]; | ||
|
||
sliders.forEach(function(slider) { | ||
var input = document.createElement("input"); | ||
input.type = "range"; | ||
input.min = slider.min; | ||
input.max = slider.max; | ||
input.value = slider.value; | ||
input.step = slider.step; | ||
input.id = slider.id; | ||
input.oninput = function() { | ||
document.getElementById(slider.id + "_value").textContent = this.value; | ||
func(parseFloat(document.getElementById("a").value), parseFloat(document.getElementById("b").value), parseFloat(document.getElementById("c").value)); | ||
}; | ||
input.classList.add("slider"); | ||
|
||
var label = document.createElement("label"); | ||
label.innerHTML = slider.description; | ||
label.setAttribute("for", slider.id); | ||
label.style.textAlign = "right"; | ||
|
||
var valueDisplay = document.createElement("span"); // Create a span element for value display | ||
valueDisplay.id = slider.id + "_value"; // Set the id for value display | ||
valueDisplay.textContent = slider.value; // Set the initial value | ||
|
||
sliderContainer.appendChild(label); | ||
sliderContainer.appendChild(input); | ||
sliderContainer.appendChild(valueDisplay); // Append the value display element | ||
}); | ||
|
||
var outputContainer = document.getElementById("outputContainer"); | ||
outputContainer.style.height = "400px"; | ||
|
||
// Call func with initial values | ||
func(parseFloat(document.getElementById("a").value), parseFloat(document.getElementById("b").value), parseFloat(document.getElementById("c").value)); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Profit Calculation</title> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js"></script> | ||
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> | ||
<style> | ||
.slider { | ||
display: block; | ||
margin-bottom: 10px; | ||
width: 100%; | ||
} | ||
.slider-container { | ||
display: grid; | ||
grid-template-columns: repeat(6, 1fr); | ||
grid-gap: 10px; | ||
width: 100%; | ||
} | ||
.output { | ||
margin-top: 20px; | ||
padding: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
background-color: #f9f9f9; | ||
} | ||
.output p { | ||
margin: 5px 0; | ||
} | ||
.output .emoji { | ||
font-size: 20px; | ||
margin-right: 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="sliderContainer" class="slider-container"></div> | ||
<div id="outputContainer" class="output"></div> | ||
|
||
<script> | ||
function func(n, truth) { | ||
var n_range = numeric.linspace(0, 100, 100); | ||
var profit = numeric.sub(numeric.mul(75, n_range), numeric.mul(numeric.sub(150, numeric.mul(0.01, numeric.pow(n_range, 2))), n_range)); | ||
var title = 'Negative profit for amount of bathmetry maps sold is € ' + (75 * n - (150 - 0.01 * Math.pow(n, 2)) * n).toFixed(2); | ||
|
||
var data = [ | ||
{ | ||
x: n_range, | ||
y: profit, | ||
type: 'scatter', | ||
mode: 'lines', | ||
name: 'Objective function', | ||
visible: truth ? true : 'legendonly' | ||
}, | ||
{ | ||
x: [n], | ||
y: [75 * n - (150 - 0.01 * Math.pow(n, 2)) * n], | ||
type: 'scatter', | ||
mode: 'markers', | ||
name: 'Manual solution', | ||
marker: { | ||
size: 10 // Set the size of the marker to a larger value | ||
} | ||
} | ||
]; | ||
|
||
var layout = { | ||
title: title, | ||
xaxis: { | ||
title: 'Number of bathmetry maps n sold (-)', | ||
range: [0, 100] | ||
}, | ||
yaxis: { | ||
title: 'Negative profit (€)', | ||
range: [-3000, 3000] | ||
}, | ||
showlegend: truth | ||
}; | ||
|
||
Plotly.newPlot('outputContainer', data, layout); | ||
} | ||
|
||
var sliderContainer = document.getElementById("sliderContainer"); | ||
var sliders = [ | ||
{ id: "n", min: 0, max: 100, value: 20, step: 1, description: "#maps n sold" } | ||
]; | ||
|
||
sliders.forEach(function(slider) { | ||
var input = document.createElement("input"); | ||
input.type = "range"; | ||
input.min = slider.min; | ||
input.max = slider.max; | ||
input.value = slider.value; | ||
input.step = slider.step; | ||
input.id = slider.id; | ||
input.oninput = function() { | ||
document.getElementById(slider.id + "_value").textContent = this.value; | ||
func(parseInt(this.value), document.getElementById("truth").checked); | ||
}; | ||
input.classList.add("slider"); | ||
|
||
var label = document.createElement("label"); | ||
label.innerHTML = slider.description; | ||
label.setAttribute("for", slider.id); | ||
label.style.textAlign = "right"; | ||
|
||
var valueDisplay = document.createElement("span"); // Create a span element for value display | ||
valueDisplay.id = slider.id + "_value"; // Set the id for value display | ||
valueDisplay.textContent = slider.value; // Set the initial value | ||
|
||
sliderContainer.appendChild(label); | ||
sliderContainer.appendChild(input); | ||
sliderContainer.appendChild(valueDisplay); // Append the value display element | ||
}); | ||
|
||
var truthCheckbox = document.createElement("input"); | ||
truthCheckbox.type = "checkbox"; | ||
truthCheckbox.id = "truth"; | ||
truthCheckbox.checked = false; | ||
truthCheckbox.onchange = function() { | ||
func(parseInt(document.getElementById("n").value), this.checked); | ||
}; | ||
|
||
var truthLabel = document.createElement("label"); | ||
truthLabel.innerHTML = "Show objective function"; | ||
truthLabel.setAttribute("for", "truth"); | ||
truthLabel.style.textAlign = "right"; | ||
|
||
sliderContainer.appendChild(truthLabel); | ||
sliderContainer.appendChild(truthCheckbox); | ||
|
||
var outputContainer = document.getElementById("outputContainer"); | ||
outputContainer.style.height = "400px"; | ||
|
||
// Call func with initial values | ||
func(parseInt(document.getElementById("n").value), document.getElementById("truth").checked); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.