I want to include a probability density of a Weibull distribution as a part of my document as an equation. Essentially the same basic density on the wikipedia page of Weibull distributions (https://en.wikipedia.org/wiki/Weibull_distribution). This is my attempt to code the equation I want.


f_X(x; \lambda, k) = \left\{ \begin{array}{cl}
    \frac{k}{\lambda}(\frac{x}{k})^{k-1} e^{-(x/\lambda)^k} & \ ; \ x \geq 0 \\
    0 & \ ; \ x < 0 \end{array} \right. \


This generates the correct form of equation, but I get a missing $ inserted error from this code. I read up on the error and think that some of the symbols I'm using inside the mathmode of \equation may not be appropriate although I'm not sure how to find out.

  • 3
    Just remove the empty lines after \begin{equation} and before \end{equation}.
    – user121799
    Mar 9 '18 at 16:36
  • Welcome to TeX.Stackexchange! Mar 9 '18 at 16:36
  • Thank you! That has indeed solved it, I didn't know the \equation{} environment was so sensitive to empty lines. Mar 9 '18 at 16:49
  • 2
    Empty lines in (La)TeX denote the end of a paragraph.
    – Bernard
    Mar 9 '18 at 16:57

In addition to getting rid of the blank lines inside the equation environment to take care of the immediate problem, you may want to enhance the overall look of the equation, mainly by replacing the generic array environment with the specialized dcases environment, which was designed for cases (pun intended) such as yours.

enter image description here

\usepackage{mathtools} % for 'dcases' env.
f_X(x; \lambda, k) = 
\frac{k}{\lambda}\Bigl(\frac{x}{k}\Bigr)^{k-1} \exp\bigl(-(x/\lambda)^k\bigr) & x \geq 0 \\[1ex]
0 & x < 0 
  • Upvote your answer. But I'm curious to understand the difference between cases and dcases.
    – Sebastiano
    Mar 10 '18 at 9:02
  • @Sebastiano - Thanks! The main difference between the two environments is that dcases typesets its contents in \displaystyle math mode.
    – Mico
    Mar 10 '18 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.