Linear combination calculator
Multiply each vector by its coefficient and add the results component by component: 2 times (1, 0) plus 3 times (0, 1) gives (2, 3). Up to 64 vectors of one shared dimension, for span checks, colour mixing or force resultants. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Coefficients
- 2, 3
- Result
- 2, 3
- Dimension
- 2
- Term count
- 2
A linear combination of vectors is the single vector you get by scaling each input vector by a matching scalar coefficient and then adding those scaled copies component by component. This calculator takes a list of coefficients and a list of vectors of the same count, multiplies each vector by its coefficient, and returns the resulting vector. Teachers use that identity to check span, basis, and barycentric homework; graphics and physics code use it to mix displacements, RGB colours, and force resultants. All vectors must share one dimension.
What a linear combination of vectors means
For k real vectors v1 through vk that share one dimension n, and k real scalars c1 through ck, the linear combination is the unique vector c1 v1 plus c2 v2 plus through ck vk. Component i of that result is the ordinary sum c1 times the i-th entry of v1 plus c2 times the i-th entry of v2 plus through ck times the i-th entry of vk.
In two dimensions that is a weighted mix of arrows in the plane; in three dimensions the same recipe mixes x, y, and z together; in n dimensions you scale every matching coordinate and stop. Geometrically each coefficient stretches or reverses its vector, and the sum is the parallelogram (or polygon) law applied to those scaled copies. Algebra and geometry agree only when every vector has the same length and every coefficient has a partner.
A list of three weights against two vectors is not a linear combination in elementary linear algebra; inventing a missing one or a missing zero would silently change the result and hide a shape bug in calling code. The same hard error applies when the vectors themselves have mixed dimensions. Linear combinations are the language of span, bases, barycentric coordinates, colour mixing, and force resultants: every vector in a subspace is some weighted sum of generating vectors.
Teachers use the component form to check homework; graphics and physics engines use it because it is a tight loop of multiply-adds. Different counts or dimensions are a hard error because the weighted parallelogram is only defined when every term is complete.
Practical tips, limits, and related searches
Keep the coefficient list the same length as the vector list before you call; if your source data sometimes drops a trailing weight, fix the shape upstream rather than relying on silent padding. Near-zero floating leftovers may still land slightly off zero after rounding—if you need an exact origin for tests, use integers such as coefficients [1, minus 1] with vectors [[1, 0], [1, 0]].
Pair classic cases when teaching: two coefficients against the standard basis of the plane for a textbook walk-through; mixed-sign three-dimensional terms for a worksheet that actually uses subtraction; a single coefficient against a single vector to show that scaling is the one-term special case; and deliberately different counts such as [1, 2] versus one vector for the error path. This landing targets people searching for a linear combination of vectors, a linear combination calculator, or a weighted sum of vector components.
It is not a two-vector addition tool (which takes exactly two unweighted lists), not a dot-product tool (which returns a scalar), not a cross-product tool, and not a matrix multiplication service. Prefer this capability when you already have numeric coefficients and coordinate lists and need c1 v1 plus through ck vk; if your source is a word problem, extract the weights and the coordinate lists first.
What you can do with it
Weighted resultants in data pipelines
Jobs validate equal term counts, form a weighted mix of displacements, colours, or force vectors, then pass the resulting vector to the next stage.
FAQ
How do you compute a linear combination of vectors?
Scale each vector by its matching coefficient and add the scaled copies component by component.
What happens if the coefficient count differs from the number of vectors?
A linear combination is only defined when every vector has a partner coefficient; nothing is padded or truncated.
Can the vectors have different dimensions?
No. Every inner vector must share one dimension.
Is a single scaled vector a linear combination?
Yes. One coefficient and one vector is the one-term case: the result is that coefficient times that vector. Two or more terms add the scaled copies.
What does the linear combination calculator cost?
The browser tool is free and runs locally.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/linear-combination \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"coefficients":[2,3],"vectors":[[1,0],[0,1]]}'const res = await fetch("https://api.kit.forhosting.com/math/linear-combination", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"coefficients": [
2,
3
],
"vectors": [
[
1,
0
],
[
0,
1
]
]
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/linear-combination",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"coefficients": [
2,
3
],
"vectors": [
[
1,
0
],
[
0,
1
]
]
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/linear-combination", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"coefficients":[2,3],"vectors":[[1,0],[0,1]]}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"coefficients":[2,3],"vectors":[[1,0],[0,1]]}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/linear-combination", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"coefficients": [
2,
3
],
"vectors": [
[
1,
0
],
[
0,
1
]
]
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.linear_combination",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_terms | 64 |
max_dim | 256 |
max_abs | 1000000000000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
If the coefficient count differs from the number of vectors the tool returns invalid_input instead of inventing a missing weight, so a dropped scalar cannot hide as a wrong arrow.
What a linear combination of vectors means
This calculator therefore treats a coefficient count that differs from the number of vectors as invalid_input, not as a padded success.
How to call the API and what comes back
Coefficients must be a non-empty array of finite numbers, or a string that parses as a bracketed or comma-or-space-separated list of finite numbers. Example: coefficients [2, 3] with vectors [[1, 0], [0, 1]] yields result [2, 3] and dimension 2. Example: coefficients [1, minus 1, 2] with vectors [[1, 2, 3], [4, 5, 6], [0, 1, minus 1]] yields result [minus 3, minus 1, minus 5]. Send a JSON body with two required fields: coefficients (aliases coeffs, scalars, weights, c) and vectors (aliases vs, vecs, v). Vectors must be a non-empty nested array of equal-dimension numeric lists, or a JSON string of that shape. The coefficient count must equal the number of vectors exactly; each inner vector must share one dimension of at most two hundred fifty-six components; at most sixty-four terms are accepted; each absolute coefficient or component must stay within one trillion so intermediate products remain finite in IEEE double precision. On success the response echoes rounded coefficients and vectors, sets result to the weighted component-wise sum, dimension to the shared length, term_count to k, formula to the defining identity string, and steps to an ordered array of substitution lines you can show in a worksheet or assert in tests. Failed validation—missing fields, empty lists, a coefficient count that differs from the number of vectors, mixed inner dimensions, non-finite values, values outside absolute limits, or a size above the published maximum—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item. Pair a deliberate count mismatch such as two coefficients against one vector when you want the invalid_input path.
Practical tips, limits, and related searches
Prefer numeric arrays over pre-formatted strings when you control the client; string forms are accepted only when every token matches a strict finite numeric pattern for coefficients, or a JSON array of arrays for vectors. Failed tasks that return invalid_input do not consume prepaid balance, which keeps exploratory scripts cheap when learners deliberately send mismatched counts. Round-trip checks are easy: recompute each scaled component by hand and confirm that dimension equals the inner length you sent and term_count equals the number of pairs.
Integration use cases
Homework checks for span and bases
Students enter coefficients and generating vectors from textbook exercises and compare the handwritten linear combination against a deterministic JSON result before submitting.
Unit tests for graphics and physics code
Generate known-good two-dimensional and three-dimensional weighted sums plus deliberate count-mismatch rejections for expected values in engines, shaders, and solvers.