JavaScript
// Enable MathJax for all JSXGraph elements!
// Use '\\( ... \\)' or '\\[ ... \\]` for LaTeX math text
JXG.Options.text.useMathJax = true;
function decay_half_life(divID){
const board = JXG.JSXGraph.initBoard(divID, {
boundingbox: [-12, 120, 200, -20],
axis: true,
showCopyright: false,
keepaspectratio: true,
showNavigation: false,
defaultAxes: {
x: { name:"\\(x\\)", withLabel:"true", label: {position: 'rt', offset: [-15, 10], anchorX: 'right'}, ticks: { visible: true, majorHeight: 5 } },
y: { withLabel: true, name: '\\(y\\)', label: { position: 'rt', offset: [20, -15], anchorX: "right", anchorY: 'top' }, ticks: { visible: true, majorHeight: 5 } }
},
pan: { enabled: true }, // Disable pan for 3D view
zoom: { enabled: true } // Disable zoom for 3D view
});
const zero = board.create('point', [0, 0], { name: 'O', size: 3, color: 'black', visible: false });
const positivey = board.create('segment', [[0, 0], [0, 120]], {visible: false });
const positivex = board.create('segment', [[0, 0], [100, 0]], {visible: false });
const pointa = board.create('glider', [0, 60,positivey], { name: "\\(N_0\\)", size: 3, color: 'red', showInfobox: false});
const pointb = board.create('glider', [30, 0,positivex], { name: '\\(T\\)', size: 3, color: 'red', showInfobox: false});
let lambda=()=>Math.log(2)/pointb.X();
const decay = board.create("functiongraph",[(x)=>pointa.Y()*Math.exp(-lambda()*x),0,200], {strokeColor:'black', strokeWidth:2, name:()=>"\\(N(t)="+pointa.Y().toFixed(2)+"\\ e^{-"+lambda().toFixed(3)+"t}\\)", withLabel:true,
label: {
//anchorX: 'middle',
//anchorY: 'middle',
offset: [30, 30],
fontSize: 14,
distance: 0.5,
position: '60% right'
}
});
}
decay_half_life('jxgbox');