Public
Edited
Dec 16
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function generateWeibullPdfPlot(k, b) {
const xMin = 0;
const xMax = b * 3;
const numPoints = 200;
const step = (xMax - xMin) / numPoints;

const weibullPDF = (x, k, b) => {
// k (shape), b (scale)
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;
}
Insert cell
function generateWeibullCdfPlot(k, b) {
const xMin = 0;
const xMax = b * 3;
const numPoints = 200;
const step = (xMax - xMin) / numPoints;

const weibullCDF = (x, k, b) => {
// k (shape), b (scale)
if (x < 0) return 0;

return 1 - Math.exp(-Math.pow(x / b, k));
};

const data = Array.from({ length: numPoints }, (_, i) => {
const x = xMin + i * step;
return {
x: x,
y: weibullCDF(x, k, b)
};
});

const plot = Plot.plot({
width: 800,
height: 500,
x: {
label: "x",
nice: true
},
y: {
label: "Cumulative Probability",
domain: [0, 1],
nice: true
},
marks: [
Plot.line(data, {
x: "x",
y: "y",
stroke: "royalblue",
strokeWidth: 2
}),
Plot.ruleY([0, 1]),
Plot.ruleX([0])
],
title: `Weibull Distribution CDF (k=${k}, b=${b})`
});

return plot;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more