function generateWeibullPdfPlot(k, b) {
const xMin = 0;
const xMax = b * 3;
const numPoints = 200;
const step = (xMax - xMin) / numPoints;
const weibullPDF = (x, k, b) => {
if (x < 0) return 0;
const term1 = k / b;
const term2 = Math.pow(x / b, k - 1);
const term3 = Math.exp(-Math.pow(x / b, k));
return term1 * term2 * term3;
};
const data = Array.from({ length: numPoints }, (_, i) => {
const x = xMin + i * step;
return {
x: x,
y: weibullPDF(x, k, b)
};
});
const plot = Plot.plot({
width: 800,
height: 500,
x: {
label: "x",
nice: true
},
y: {
label: "Probability Density",
nice: true
},
marks: [
Plot.line(data, {
x: "x",
y: "y",
stroke: "hotpink",
strokeWidth: 2
}),
Plot.ruleY([0])
],
title: `Weibull Distribution PDF (k=${k}, b=${b})`
});
return plot;
}