Skip to content

Instantly share code, notes, and snippets.

@shohei
Created July 26, 2020 06:50
Show Gist options
  • Save shohei/d6656886deb696b091400b6229fc498a to your computer and use it in GitHub Desktop.
Save shohei/d6656886deb696b091400b6229fc498a to your computer and use it in GitHub Desktop.
Bathtub curve and Weibull distribution
clear all; close all;
f = @(m,eta,g,t) m/eta^m*(t-g).^(m-1);
t=0.1:0.1:2;
m=0.5; eta=3; g = 0;
lambda = f(m,eta,g,t);
subplot(311);
plot(t,lambda);
hold on;
t=2:0.1:6;
m=1; eta=5; g = 1;
lambda = f(m,eta,g,t);
plot(t,lambda);
t=6:0.1:10;
m=3.5; eta=7; g = 1;
lambda = f(m,eta,g,t);
plot(t,lambda);
syms x;
f = @(m,eta,g) m/eta^m*(x-g).^(m-1);
t=0.1:0.1:2;
m=0.5; eta=3; g = 0;
R(x) = exp(-int(f(m,eta,g),0,x));
subplot(312);
plot(t,R(t));hold on;
subplot(313);
pdf(x)=-diff(R);
plot(t,pdf(t));hold on;
t=2:0.1:6;
m=1; eta=5; g = 1;
R(x) = exp(-int(f(m,eta,g),0,x));
subplot(312);
plot(t,R(t));
subplot(313);
pdf(x)=-diff(R);
plot(t,pdf(t));
m=3.5; eta=7.071067812; g = 1;
t=6:0.1:10;
f = @(m,eta,g) m/eta^m*(x-g).^(m-1);
R(x) = exp(-int(f(m,eta,g),0,x));
subplot(312);
plot(t,R(t));
subplot(313);
pdf(x)=-diff(R);
plot(t,pdf(t));
subplot(311);title('Failure rate lambda');
subplot(312);title('Reliability R(t)');
subplot(313);title('Failure PDF f(t)');
sgtitle('Bathtub curve')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment