MonopBase

by Javier Puértolas

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jsxgraph/1.8.0/jsxgraphcore.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsxgraph/1.8.0/jsxgraphcore.css">
<div id="divid" class="jxgbox" style="width:480px; height:550px">
document.getElementById(divid).classList.remove("jxgbox"); /* Remove the default style. */
document.getElementById(divid).innerHTML = "<table style='width:100vw;height:100vh;'>"
+ "<tr><td><div id='box1'> </div></td></tr> <tr><td><div id='box2'> </div></td></tr>"
+ "</table>";


</div>

JavaScript

for(var i = 1; i <=2; i++) {
 var el = document.getElementById("box"+i);
 el.classList.add('jxgbox');
 /* You will have to do some random tuning of the margins and sizes as the default iframe might not have enough space. 
 el.style.width="48vw";
 el.style.height="96vh"; */
 el.style.width="460px";
 el.style.height="260px"; 
}

/* qale de [10, 11, 12, 14, 15, 16, 18, 20, 21, 22
pted [1/2, 2/3, 3/4, 1, 5/4, 3/2, 4/3, 5/3, 2]] */

/* valores que vienen de STACK, aleatorios  */
   
/* Para la demanda */   
   var qale = 12;
    var pted = 5/4;
    
/* Para los costes  */  
    var cflin = 20;
    var blin = 5;
    
    var cfcuad = cflin/2;
    var bcuad = blin/10;
 /* Definición de funciones  */   
    var ctotlin = function(q){return cflin + blin * q};
    var cmglin =function(q){return blin};
    var cmelin = function(q){return ctotlin(q)/q};
    
    var ctotcuad = function(q){return cfcuad + bcuad * q*q};
    var cmgcuad =function(q){return 2*bcuad * q};
    var cmecuad = function(q){return ctotcuad(q)/q};
    
    var deminv = function(q){return (qale *pted + blin) - pted * q};
   
    var demcv = qale *pted + blin;
     var dem = function(p){return (demcv-p)/pted};
    var  demch = dem(0);
    
    var itot = function(q){return q * deminv(q)};
    var img = function(q){return (qale *pted + blin) - 2 * pted * q};
    var beneflin = function(q){return q * deminv(q)- ctotlin(q)};
    var benefcuad = function(q){return q * deminv(q)- ctotcuad(q)};
    
    /* Dimensiones de las figuras  */
    var th = (1.7+Math.random()/3)*demch;
    var tv =(1.2+Math.random()/3) *demcv;
    var tv2 =(1.1+Math.random()/3) *itot(demch/2);
    
    
    JXG.Options.axis.ticks.minorTicks = 0;
    
/* Primera figura. Funciones unitarias  */ 

    var board = JXG.JSXGraph.initBoard('box1', {boundingbox: [-0.1*th,tv,th,-0.15*tv] ,
    axis: false,
    grid: false,
    showNavigation: false,
    showCopyright:false,
    pan: {enabled: false},
    zoom: {enabled: false}});

    var xaxis...