Math Calculator API

A free, public REST API for computing percentages, fractions, derivatives, quadratic equations, standard deviation, slope, triangles, matrices, z-scores, binomial probability, normal distribution, and correlation. Returns structured JSON with step-by-step solutions and LaTeX notation.

v1CORS EnabledNo Auth RequiredRate Limited

Table of Contents

Quick Start

Get started in seconds. Copy and paste this into your terminal to calculate 25% of 200:

bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "percentage", "params": { "a": 25, "b": 200, "mode": "of" } }'

Response:

json
{
  "result": { "value": 50, "label": "25% of 200" },
  "steps": [
    "Convert percentage to decimal: 25 / 100 = 0.25",
    "Multiply by the number: 0.25 * 200 = 50"
  ],
  "latex": "\\frac{25}{100} \\times 200 = 50"
}

Key points:

  • All requests use POST with a JSON body
  • No authentication or API key required
  • CORS is enabled for browser-based requests
  • Rate limit: 60 requests per minute per IP
  • Every response includes step-by-step solutions and LaTeX notation

Base URL

https://mathcalculator.org/api/v1

All requests are made via POST to /api/v1/calculate with a JSON body. Machine-readable documentation is available at GET /api/v1/docs.

Rate Limiting

The API enforces a rate limit of 60 requests per minute per IP address using a sliding window. Exceeding the limit returns a 429 Too Many Requests response.

HeaderDescription
X-RateLimit-LimitMaximum requests per window (60)
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetUnix timestamp (seconds) when the window resets
Retry-AfterSeconds to wait before retrying (only on 429 responses)

Request Format

json
POST /api/v1/calculate
Content-Type: application/json

{
  "type": "percentage | fraction | derivative | quadratic | standard-deviation | slope | triangle | matrix | z-score | binomial | normal-distribution | correlation",
  "params": { ... }
}

type (string, required) -- the calculator to use. One of 12 supported types.

params (object, required) -- parameters for the calculation. Shape varies by type (see sections below).

Response Format

json
{
  "result": { ... },
  "steps": ["Step 1", "Step 2", "..."],
  "latex": "\\frac{25}{100} \\times 200 = 50"
}

result -- the computed answer (shape depends on calculator type).

steps -- array of human-readable step-by-step explanations.

latex -- LaTeX string for rendering the solution.

Percentage Calculator

Five modes: of, is, change, difference, reverse.

ParameterTypeRequiredDescription
anumberYesFirst value (percentage for "of" mode, value for "is" mode, original for "change" mode)
bnumberYesSecond value (number for "of" mode, total for "is" mode, new value for "change" mode)
modestringNo"of" | "is" | "change" | "difference" | "reverse" (default: "of")

Example: What is 25% of 200?

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "percentage", "params": { "a": 25, "b": 200, "mode": "of" } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "percentage",
    "params": { "a": 25, "b": 200, "mode": "of" }
})
data = response.json()
print(data["result"]["value"])  # 50
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "percentage",
    params: { a: 25, b: 200, mode: "of" }
  })
});
const data = await response.json();
console.log(data.result.value); // 50

Sample Response

json
{
  "result": { "value": 50, "label": "25% of 200" },
  "steps": [
    "Convert percentage to decimal: 25 / 100 = 0.25",
    "Multiply by the number: 0.25 * 200 = 50"
  ],
  "latex": "\\frac{25}{100} \\times 200 = 50"
}

Fraction Calculator

Operations: add, subtract, multiply, divide, simplify. Results are always returned in simplest form.

ParameterTypeRequiredDescription
num1integerYesNumerator of first fraction
den1integerYesDenominator of first fraction (cannot be 0)
num2integerNoNumerator of second fraction (not needed for "simplify")
den2integerNoDenominator of second fraction (not needed for "simplify", cannot be 0)
operationstringNo"add" | "subtract" | "multiply" | "divide" | "simplify" (default: "add")

Example: Add 1/3 + 1/6

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "fraction", "params": { "num1": 1, "den1": 3, "num2": 1, "den2": 6, "operation": "add" } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "fraction",
    "params": {
        "num1": 1, "den1": 3,
        "num2": 1, "den2": 6,
        "operation": "add"
    }
})
data = response.json()
print(data["result"]["display"])  # "1/2"
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "fraction",
    params: { num1: 1, den1: 3, num2: 1, den2: 6, operation: "add" }
  })
});
const data = await response.json();
console.log(data.result.display); // "1/2"

Sample Response

json
{
  "result": { "numerator": 1, "denominator": 2, "display": "1/2" },
  "steps": [
    "Find the LCD of 3 and 6: LCD = 6",
    "Convert: 1*2/6 + 1*1/6 = 2/6 + 1/6",
    "Add numerators: (2 + 1) / 6 = 3/6",
    "Simplify by dividing by GCD (3): 1/2"
  ],
  "latex": "\\frac{1}{3} + \\frac{1}{6} = \\frac{1}{2}"
}

Derivative Calculator

Symbolic differentiation powered by mathjs. Supports higher-order derivatives up to 10th order.

ParameterTypeRequiredDescription
expressionstringYesMathematical expression (e.g. "x^3 + 2*x^2 - 5*x"). Max 500 characters.
variablestringNoVariable to differentiate with respect to (default: "x")
orderintegerNoDerivative order, 1-10 (default: 1)

Example: Derivative of x^3 + 2*x^2 - 5*x

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "derivative", "params": { "expression": "x^3 + 2*x^2 - 5*x", "variable": "x" } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "derivative",
    "params": {
        "expression": "x^3 + 2*x^2 - 5*x",
        "variable": "x"
    }
})
data = response.json()
print(data["result"]["derivative"])  # "3 * x ^ 2 + 4 * x - 5"
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "derivative",
    params: { expression: "x^3 + 2*x^2 - 5*x", variable: "x" }
  })
});
const data = await response.json();
console.log(data.result.derivative); // "3 * x ^ 2 + 4 * x - 5"

Sample Response

json
{
  "result": {
    "derivative": "3 * x ^ 2 + 4 * x - 5",
    "order": 1
  },
  "steps": [
    "1st derivative: 3 * x ^ 2 + 4 * x - 5"
  ],
  "latex": "\\frac{d}{dx}\\left[x^3 + 2*x^2 - 5*x\\right] = 3 * x ^ 2 + 4 * x - 5"
}

Quadratic Equation Solver

Solves ax² + bx + c = 0. Returns roots (real or complex), discriminant, vertex, and axis of symmetry.

ParameterTypeRequiredDescription
anumberYesCoefficient of x-squared (must not be 0)
bnumberYesCoefficient of x
cnumberYesConstant term

Example: Solve x² - 5x + 6 = 0

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "quadratic", "params": { "a": 1, "b": -5, "c": 6 } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "quadratic",
    "params": { "a": 1, "b": -5, "c": 6 }
})
data = response.json()
roots = data["result"]["roots"]
print(f"x1 = {roots['x1']}, x2 = {roots['x2']}")  # x1 = 3, x2 = 2
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "quadratic",
    params: { a: 1, b: -5, c: 6 }
  })
});
const data = await response.json();
console.log(data.result.roots); // { x1: 3, x2: 2, type: "two-real" }

Sample Response

json
{
  "result": {
    "roots": { "x1": 3, "x2": 2, "type": "two-real" },
    "discriminant": 1,
    "vertex": { "x": 2.5, "y": -0.25 },
    "axisOfSymmetry": 2.5
  },
  "steps": [
    "Standard form: 1x^2 + -5x + 6 = 0",
    "Discriminant: b^2 - 4ac = -5^2 - 4*1*6 = 1",
    "sqrt(discriminant) = 1",
    "x1 = (--5 + 1) / (2 * 1) = 3",
    "x2 = (--5 - 1) / (2 * 1) = 2",
    "Vertex: (2.5, -0.25)"
  ],
  "latex": "x = \\frac{--5 \\pm \\sqrt{1}}{2}"
}

Standard Deviation Calculator

Calculate mean, variance, and standard deviation for a data set. Supports both population and sample standard deviation.

ParameterTypeRequiredDescription
valuesstring | number[]YesComma-separated numbers (e.g. "10,20,30") or array (e.g. [10,20,30]). Minimum 2 values.
typestringNo"population" | "sample" (default: "population")

Example: Population standard deviation of [10, 20, 30, 40, 50]

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "standard-deviation", "params": { "values": [10, 20, 30, 40, 50], "type": "population" } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "standard-deviation",
    "params": {
        "values": [10, 20, 30, 40, 50],
        "type": "population"
    }
})
data = response.json()
print(data["result"]["standardDeviation"])  # 14.142135624
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "standard-deviation",
    params: { values: [10, 20, 30, 40, 50], type: "population" }
  })
});
const data = await response.json();
console.log(data.result.standardDeviation); // 14.142135624

Sample Response

json
{
  "result": {
    "mean": 30,
    "variance": 200,
    "standardDeviation": 14.142135624,
    "count": 5,
    "type": "population"
  },
  "steps": [
    "Values: [10, 20, 30, 40, 50] (n = 5)",
    "Mean: (10 + 20 + 30 + 40 + 50) / 5 = 30",
    "Squared differences from mean: [400, 100, 0, 100, 400]",
    "Sum of squared differences: 1000",
    "Population variance: 1000 / 5 = 200",
    "Standard deviation: sqrt(200) = 14.142135624"
  ],
  "latex": "\\sigma = \\sqrt{\\frac{\\sum(x_i - \\bar{x})^2}{N}} = 14.142135624"
}

Slope Calculator

Calculate slope, y-intercept, distance, and line equation from two points.

ParameterTypeRequiredDescription
x1numberYesx-coordinate of first point
y1numberYesy-coordinate of first point
x2numberYesx-coordinate of second point
y2numberYesy-coordinate of second point

Example: Slope between (1, 2) and (4, 8)

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "slope", "params": { "x1": 1, "y1": 2, "x2": 4, "y2": 8 } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "slope",
    "params": { "x1": 1, "y1": 2, "x2": 4, "y2": 8 }
})
data = response.json()
print(data["result"]["slope"])     # 2
print(data["result"]["equation"])  # "y = 2x + 0"
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "slope",
    params: { x1: 1, y1: 2, x2: 4, y2: 8 }
  })
});
const data = await response.json();
console.log(data.result.slope);    // 2
console.log(data.result.equation); // "y = 2x + 0"

Sample Response

json
{
  "result": {
    "slope": 2,
    "yIntercept": 0,
    "distance": 6.708203933,
    "equation": "y = 2x + 0"
  },
  "steps": [
    "Point 1: (1, 2)",
    "Point 2: (4, 8)",
    "Rise: 6, Run: 3",
    "Slope (m): 6 / 3 = 2",
    "y-intercept (b): 2 - 2 * 1 = 0",
    "Equation: y = 2x + 0",
    "Distance: sqrt(3^2 + 6^2) = 6.708203933"
  ],
  "latex": "m = \\frac{y_2 - y_1}{x_2 - x_1} = \\frac{6}{3} = 2"
}

Triangle Calculator

Calculate area (Heron's formula), perimeter, and angles of a triangle given three side lengths.

ParameterTypeRequiredDescription
anumberYesLength of side a (must be positive)
bnumberYesLength of side b (must be positive)
cnumberYesLength of side c (must be positive)

Example: Triangle with sides 3, 4, 5

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "triangle", "params": { "a": 3, "b": 4, "c": 5 } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "triangle",
    "params": { "a": 3, "b": 4, "c": 5 }
})
data = response.json()
print(data["result"]["area"])       # 6
print(data["result"]["perimeter"])  # 12
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "triangle",
    params: { a: 3, b: 4, c: 5 }
  })
});
const data = await response.json();
console.log(data.result.area);      // 6
console.log(data.result.perimeter); // 12

Sample Response

json
{
  "result": {
    "area": 6,
    "perimeter": 12,
    "semiPerimeter": 6,
    "angles": { "A": 36.8698976, "B": 53.1301024, "C": 90 }
  },
  "steps": [
    "Sides: a = 3, b = 4, c = 5",
    "Perimeter: 3 + 4 + 5 = 12",
    "Semi-perimeter (s): 12 / 2 = 6",
    "Area (Heron's formula): sqrt(6 * 3 * 2 * 1) = 6",
    "Angle A: 36.87 degrees",
    "Angle B: 53.13 degrees",
    "Angle C: 90 degrees"
  ],
  "latex": "A = \\sqrt{s(s-a)(s-b)(s-c)} = 6"
}

Matrix Calculator

Matrix operations: determinant, transpose, or inverse. Supports matrices up to 5x5.

ParameterTypeRequiredDescription
matrixAnumber[][]YesMatrix as 2D array of numbers (e.g. [[1,2],[3,4]]). Max 5x5.
operationstringNo"determinant" | "transpose" | "inverse" (default: "determinant")

Example: Determinant of a 2x2 matrix

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "matrix", "params": { "matrixA": [[1, 2], [3, 4]], "operation": "determinant" } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "matrix",
    "params": {
        "matrixA": [[1, 2], [3, 4]],
        "operation": "determinant"
    }
})
data = response.json()
print(data["result"]["determinant"])  # -2
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "matrix",
    params: { matrixA: [[1, 2], [3, 4]], operation: "determinant" }
  })
});
const data = await response.json();
console.log(data.result.determinant); // -2

Sample Response

json
{
  "result": { "determinant": -2, "operation": "determinant" },
  "steps": [
    "Input matrix (2x2): [[1, 2], [3, 4]]",
    "det = (1 * 4) - (2 * 3)",
    "det = 4 - 6 = -2"
  ],
  "latex": "\\det(A) = -2"
}

Example: Inverse of a 2x2 matrix

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "matrix", "params": { "matrixA": [[4, 7], [2, 6]], "operation": "inverse" } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "matrix",
    "params": {
        "matrixA": [[4, 7], [2, 6]],
        "operation": "inverse"
    }
})
data = response.json()
print(data["result"]["matrix"])  # [[0.6, -0.7], [-0.2, 0.4]]
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "matrix",
    params: { matrixA: [[4, 7], [2, 6]], operation: "inverse" }
  })
});
const data = await response.json();
console.log(data.result.matrix); // [[0.6, -0.7], [-0.2, 0.4]]

Sample Response

json
{
  "result": { "matrix": [[0.6, -0.7], [-0.2, 0.4]], "operation": "inverse" },
  "steps": [
    "Input matrix (2x2): [[4, 7], [2, 6]]",
    "Determinant = 10",
    "For 2x2: A^(-1) = (1/det) * [[d, -b], [-c, a]]",
    "A^(-1) = (1/10) * [[6, -7], [-2, 4]]",
    "Result: [[0.6, -0.7], [-0.2, 0.4]]"
  ],
  "latex": "A^{-1} = \\begin{pmatrix} 0.6 & -0.7 \\\\ -0.2 & 0.4 \\end{pmatrix}"
}

Z-Score Calculator

Calculate the z-score (standard score) and approximate percentile for a value given a mean and standard deviation.

ParameterTypeRequiredDescription
valuenumberYesThe observed value (x)
meannumberYesPopulation mean (mu)
stddevnumberYesPopulation standard deviation (sigma, must be positive)

Example: Z-score for value 85, mean 70, stddev 10

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "z-score", "params": { "value": 85, "mean": 70, "stddev": 10 } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "z-score",
    "params": { "value": 85, "mean": 70, "stddev": 10 }
})
data = response.json()
print(data["result"]["zScore"])      # 1.5
print(data["result"]["percentile"])  # 93.32
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "z-score",
    params: { value: 85, mean: 70, stddev: 10 }
  })
});
const data = await response.json();
console.log(data.result.zScore);     // 1.5
console.log(data.result.percentile); // 93.32

Sample Response

json
{
  "result": {
    "zScore": 1.5,
    "percentile": 93.319279891,
    "value": 85,
    "mean": 70,
    "stddev": 10
  },
  "steps": [
    "Value (x): 85",
    "Mean (mu): 70",
    "Standard deviation (sigma): 10",
    "Z-score: (x - mu) / sigma = (85 - 70) / 10 = 1.5",
    "Percentile (approx): 93.32%"
  ],
  "latex": "z = \\frac{x - \\mu}{\\sigma} = \\frac{85 - 70}{10} = 1.5"
}

Binomial Probability Calculator

Calculate the probability of exactly k successes in n independent Bernoulli trials, plus cumulative probability P(X <= k), expected value, and variance.

ParameterTypeRequiredDescription
nintegerYesNumber of trials (0-170)
kintegerYesNumber of successes (0 to n)
pnumberYesProbability of success per trial (0 to 1)

Example: P(X = 3) for n=10 trials, p=0.5

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "binomial", "params": { "n": 10, "k": 3, "p": 0.5 } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "binomial",
    "params": { "n": 10, "k": 3, "p": 0.5 }
})
data = response.json()
print(data["result"]["probability"])  # 0.1171875
print(data["result"]["cumulative"])   # 0.171875
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "binomial",
    params: { n: 10, k: 3, p: 0.5 }
  })
});
const data = await response.json();
console.log(data.result.probability); // 0.1171875
console.log(data.result.cumulative);  // 0.171875

Sample Response

json
{
  "result": {
    "probability": 0.1171875,
    "cumulative": 0.171875,
    "expectedValue": 5,
    "variance": 2.5,
    "stddev": 1.5811388301,
    "n": 10, "k": 3, "p": 0.5
  },
  "steps": [
    "n (trials): 10, k (successes): 3, p (probability): 0.5",
    "C(n,k) = C(10,3) = 120",
    "P(X = 3) = C(10,3) * 0.5^3 * 0.5^7 = 0.1171875",
    "P(X <= 3) = 0.171875",
    "Expected value: n * p = 10 * 0.5 = 5",
    "Variance: n * p * (1 - p) = 2.5",
    "Standard deviation: sqrt(variance) = 1.5811388301"
  ],
  "latex": "P(X = 3) = \\binom{10}{3} \\cdot 0.5^{3} \\cdot 0.5^{7} = 0.1171875"
}

Normal Distribution Calculator

Evaluate the probability density function (PDF) and cumulative distribution function (CDF) for a normal distribution at a given point.

ParameterTypeRequiredDescription
meannumberYesMean of the distribution (mu)
stddevnumberYesStandard deviation (sigma, must be positive)
xnumberYesPoint at which to evaluate

Example: PDF and CDF for x=75, mean=70, stddev=10

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "normal-distribution", "params": { "mean": 70, "stddev": 10, "x": 75 } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "normal-distribution",
    "params": { "mean": 70, "stddev": 10, "x": 75 }
})
data = response.json()
print(data["result"]["pdf"])  # 0.0352065327
print(data["result"]["cdf"])  # 0.6914624613
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "normal-distribution",
    params: { mean: 70, stddev: 10, x: 75 }
  })
});
const data = await response.json();
console.log(data.result.pdf); // 0.0352065327
console.log(data.result.cdf); // 0.6914624613

Sample Response

json
{
  "result": {
    "pdf": 0.0352065327,
    "cdf": 0.6914624613,
    "zScore": 0.5,
    "mean": 70,
    "stddev": 10,
    "x": 75
  },
  "steps": [
    "Mean (mu): 70",
    "Standard deviation (sigma): 10",
    "Value (x): 75",
    "Z-score: (75 - 70) / 10 = 0.5",
    "PDF: f(x) = (1 / (sigma * sqrt(2*pi))) * e^(-z^2/2) = 0.0352065327",
    "CDF: P(X <= 75) = 0.6914624613"
  ],
  "latex": "f(x) = \\frac{1}{10\\sqrt{2\\pi}} e^{-\\frac{1}{2}\\left(\\frac{75 - 70}{10}\\right)^2} = 0.0352065327"
}

Correlation Calculator

Compute Pearson correlation coefficient (r), R-squared, and linear regression line (slope and intercept) for paired data sets.

ParameterTypeRequiredDescription
xValuesnumber[]YesArray of x-values (at least 2, max 1000)
yValuesnumber[]YesArray of y-values (same length as xValues)

Example: Correlation between [1,2,3,4,5] and [2,4,5,4,5]

curl
bash
curl -X POST https://mathcalculator.org/api/v1/calculate \
  -H "Content-Type: application/json" \
  -d '{ "type": "correlation", "params": { "xValues": [1,2,3,4,5], "yValues": [2,4,5,4,5] } }'
Python
python
import requests

response = requests.post("https://mathcalculator.org/api/v1/calculate", json={
    "type": "correlation",
    "params": {
        "xValues": [1, 2, 3, 4, 5],
        "yValues": [2, 4, 5, 4, 5]
    }
})
data = response.json()
print(data["result"]["r"])         # 0.7745966692
print(data["result"]["rSquared"])  # 0.6
JavaScript
javascript
const response = await fetch("https://mathcalculator.org/api/v1/calculate", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    type: "correlation",
    params: { xValues: [1, 2, 3, 4, 5], yValues: [2, 4, 5, 4, 5] }
  })
});
const data = await response.json();
console.log(data.result.r);        // 0.7745966692
console.log(data.result.rSquared); // 0.6

Sample Response

json
{
  "result": {
    "r": 0.7745966692,
    "rSquared": 0.6,
    "slope": 0.6,
    "intercept": 2.2,
    "n": 5,
    "meanX": 3,
    "meanY": 4
  },
  "steps": [
    "n = 5",
    "Mean of x: 3, Mean of y: 4",
    "SS_xx = 10, SS_yy = 6, SS_xy = 6",
    "Pearson r = 6 / sqrt(60) = 0.7745966692",
    "R-squared = 0.6",
    "Regression slope (b) = 0.6",
    "Regression intercept (a) = 2.2",
    "Regression line: y = 0.6x + 2.2"
  ],
  "latex": "r = \\frac{\\sum(x_i - \\bar{x})(y_i - \\bar{y})}{\\sqrt{\\sum(x_i - \\bar{x})^2 \\cdot \\sum(y_i - \\bar{y})^2}} = 0.7745966692"
}

Error Handling

Errors return a JSON object with an error field and an appropriate HTTP status code.

StatusMeaningWhen
400Bad RequestInvalid JSON, missing fields, validation errors, unsupported type
429Too Many RequestsRate limit exceeded (60 req/min per IP)

400 Bad Request -- Missing type

json
// Request: POST /api/v1/calculate  { "params": { "a": 1 } }

{ "error": "Missing required field \"type\"." }

400 Bad Request -- Unsupported type

json
// Request: { "type": "integral", "params": {} }

{
  "error": "Unsupported calculator type \"integral\". Supported types: percentage, fraction, derivative, quadratic, standard-deviation, slope, triangle, matrix, z-score, binomial, normal-distribution, correlation."
}

400 Bad Request -- Validation error

json
// Request: { "type": "percentage", "params": { "a": "abc", "b": 100 } }

{ "error": "Parameters \"a\" and \"b\" must be valid numbers." }

400 Bad Request -- Invalid JSON

json
// Request body is not valid JSON

{ "error": "Invalid JSON body." }

429 Rate Limit Exceeded

json
// Headers: Retry-After: 23

{ "error": "Too many requests. Please try again later." }

Tip: Always check for the error field in the response body. When rate-limited, use the Retry-After header to determine when to retry.

© 2026 Math Calculator. Free to use.

mathcalculator.org