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.
Table of Contents
Quick Start
Get started in seconds. Copy and paste this into your terminal to calculate 25% of 200:
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:
{
"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
POSTwith 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/v1All 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.
| Header | Description |
|---|---|
| X-RateLimit-Limit | Maximum requests per window (60) |
| X-RateLimit-Remaining | Requests remaining in current window |
| X-RateLimit-Reset | Unix timestamp (seconds) when the window resets |
| Retry-After | Seconds to wait before retrying (only on 429 responses) |
Request Format
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
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| a | number | Yes | First value (percentage for "of" mode, value for "is" mode, original for "change" mode) |
| b | number | Yes | Second value (number for "of" mode, total for "is" mode, new value for "change" mode) |
| mode | string | No | "of" | "is" | "change" | "difference" | "reverse" (default: "of") |
Example: What is 25% of 200?
curl
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
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"]) # 50JavaScript
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); // 50Sample Response
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| num1 | integer | Yes | Numerator of first fraction |
| den1 | integer | Yes | Denominator of first fraction (cannot be 0) |
| num2 | integer | No | Numerator of second fraction (not needed for "simplify") |
| den2 | integer | No | Denominator of second fraction (not needed for "simplify", cannot be 0) |
| operation | string | No | "add" | "subtract" | "multiply" | "divide" | "simplify" (default: "add") |
Example: Add 1/3 + 1/6
curl
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
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
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
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| expression | string | Yes | Mathematical expression (e.g. "x^3 + 2*x^2 - 5*x"). Max 500 characters. |
| variable | string | No | Variable to differentiate with respect to (default: "x") |
| order | integer | No | Derivative order, 1-10 (default: 1) |
Example: Derivative of x^3 + 2*x^2 - 5*x
curl
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
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
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
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| a | number | Yes | Coefficient of x-squared (must not be 0) |
| b | number | Yes | Coefficient of x |
| c | number | Yes | Constant term |
Example: Solve x² - 5x + 6 = 0
curl
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
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 = 2JavaScript
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
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| values | string | number[] | Yes | Comma-separated numbers (e.g. "10,20,30") or array (e.g. [10,20,30]). Minimum 2 values. |
| type | string | No | "population" | "sample" (default: "population") |
Example: Population standard deviation of [10, 20, 30, 40, 50]
curl
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
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.142135624JavaScript
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.142135624Sample Response
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| x1 | number | Yes | x-coordinate of first point |
| y1 | number | Yes | y-coordinate of first point |
| x2 | number | Yes | x-coordinate of second point |
| y2 | number | Yes | y-coordinate of second point |
Example: Slope between (1, 2) and (4, 8)
curl
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
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
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
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| a | number | Yes | Length of side a (must be positive) |
| b | number | Yes | Length of side b (must be positive) |
| c | number | Yes | Length of side c (must be positive) |
Example: Triangle with sides 3, 4, 5
curl
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
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"]) # 12JavaScript
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); // 12Sample Response
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| matrixA | number[][] | Yes | Matrix as 2D array of numbers (e.g. [[1,2],[3,4]]). Max 5x5. |
| operation | string | No | "determinant" | "transpose" | "inverse" (default: "determinant") |
Example: Determinant of a 2x2 matrix
curl
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
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"]) # -2JavaScript
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); // -2Sample Response
{
"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
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
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
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
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| value | number | Yes | The observed value (x) |
| mean | number | Yes | Population mean (mu) |
| stddev | number | Yes | Population standard deviation (sigma, must be positive) |
Example: Z-score for value 85, mean 70, stddev 10
curl
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
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.32JavaScript
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.32Sample Response
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| n | integer | Yes | Number of trials (0-170) |
| k | integer | Yes | Number of successes (0 to n) |
| p | number | Yes | Probability of success per trial (0 to 1) |
Example: P(X = 3) for n=10 trials, p=0.5
curl
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
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.171875JavaScript
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.171875Sample Response
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| mean | number | Yes | Mean of the distribution (mu) |
| stddev | number | Yes | Standard deviation (sigma, must be positive) |
| x | number | Yes | Point at which to evaluate |
Example: PDF and CDF for x=75, mean=70, stddev=10
curl
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
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.6914624613JavaScript
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.6914624613Sample Response
{
"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.
| Parameter | Type | Required | Description |
|---|---|---|---|
| xValues | number[] | Yes | Array of x-values (at least 2, max 1000) |
| yValues | number[] | Yes | Array of y-values (same length as xValues) |
Example: Correlation between [1,2,3,4,5] and [2,4,5,4,5]
curl
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
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.6JavaScript
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.6Sample Response
{
"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.
| Status | Meaning | When |
|---|---|---|
| 400 | Bad Request | Invalid JSON, missing fields, validation errors, unsupported type |
| 429 | Too Many Requests | Rate limit exceeded (60 req/min per IP) |
400 Bad Request -- Missing type
// Request: POST /api/v1/calculate { "params": { "a": 1 } }
{ "error": "Missing required field \"type\"." }400 Bad Request -- Unsupported type
// 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
// Request: { "type": "percentage", "params": { "a": "abc", "b": 100 } }
{ "error": "Parameters \"a\" and \"b\" must be valid numbers." }400 Bad Request -- Invalid JSON
// Request body is not valid JSON
{ "error": "Invalid JSON body." }429 Rate Limit Exceeded
// 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.