easiest way to construct the following determinantDefining a big matrix for iterative algorithmSolving determinant of a Kronecker product of matrices gives a numerical error - why?construct matrix by applying derivatives to another matrixStrange determinant resultCalculation of a matrix determinant for general matrix sizeDeterminant of the symbolic matrix is giving very large expressionDeterminant of matrix with asymptotic expansion
Why is weak Kőnig's lemma weaker than Kőnig's lemma?
Can abstractions and good code practice in embedded C++ eliminate the need for the debugger?
An outdated version of bash was detected on your system! when updating sdkman
Feasibility of keeping an Electrical Bike in poor (wet) storage conditions
FIDE Laws of Chess pre-2017
How to wire for AC mains voltage relay, when printer board is connected to AC-charging laptop computer?
Why is the Duration of Time spent in the Dayside greater than that of the Night side of the Moon for Chandrayaan-2 Orbiter?
Why do we worry about overfitting even if "all models are wrong"?
Energy cost of C−N rotation in hydroxamate group
Is there a way to download the box art for games?
Single word for delaying an unpleasant task
Making recursion optional: Bad practice?
Mechanics to keep mobs and environment alive without using tons of memory?
Did Catherine the Great really call for the abolition of serfdom?
Why is it “Cat in the Hat”?
Is it possible to see mercury transit "clearly" by the naked eye?
The correct capital G and J in cursive
Will being an emotionally numb 14 year-old prevent me from eventually being a pilot?
Should plywood be missing on my roof?
Is it usual for a US president to make specific comments about a UK Prime Minister's suitability during a general election?
A concrete example of the deficiency of triangulated categories?
(Re-)entering UK academic system after a long time abroad
What happens if a country signs mutual defense treaties with several countries who later go to war with each other?
Are the graphical depictions in docs drawed in manual labour?
easiest way to construct the following determinant
Defining a big matrix for iterative algorithmSolving determinant of a Kronecker product of matrices gives a numerical error - why?construct matrix by applying derivatives to another matrixStrange determinant resultCalculation of a matrix determinant for general matrix sizeDeterminant of the symbolic matrix is giving very large expressionDeterminant of matrix with asymptotic expansion
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
.everyonelovesstackoverflowposition:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;
$begingroup$
What is the easiest way to construct the following determinant?]
p
is variable, I want to vary value of p each time and get the appropriate determinant.
matrix
$endgroup$
add a comment
|
$begingroup$
What is the easiest way to construct the following determinant?]
p
is variable, I want to vary value of p each time and get the appropriate determinant.
matrix
$endgroup$
add a comment
|
$begingroup$
What is the easiest way to construct the following determinant?]
p
is variable, I want to vary value of p each time and get the appropriate determinant.
matrix
$endgroup$
What is the easiest way to construct the following determinant?]
p
is variable, I want to vary value of p each time and get the appropriate determinant.
matrix
matrix
asked Oct 15 at 5:06
WisdomWisdom
948 bronze badges
948 bronze badges
add a comment
|
add a comment
|
3 Answers
3
active
oldest
votes
$begingroup$
One way to do it would be
mat[p_] := SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
Det@mat[p]
For example
With[p = 2,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
]
Det@%
$left(
beginarrayccc
B(0) & textCC(1) & 0 \
A(0) & B(1) & textCC(2) \
0 & A(1) & B(2) \
endarray
right)$
B[0] B[1] B[2] - A[0] B[2] CC[1] - A[1] B[0] CC[2]
But the computation time quickly increases with p
since the elements are symbolic. For example, with p = 17
,
With[p = 17,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
] // Det // RepeatedTiming // First
2.7
But, if the elements are numeric quantities,
SeedRandom[1234]
With[p = 17,
SparseArray[
i_, i_ :> RandomReal[],
i_, j_ /; i == j + 1 :> RandomReal[],
i_, j_ /; i == j - 1 :> RandomReal[]
,
p + 1
]
] // Det // RepeatedTiming // First
0.0020
the calculation is no problem.
$endgroup$
$begingroup$
thanks a lot. In fact A,B and C are some functions which become determined by initial values.
$endgroup$
– Wisdom
Oct 15 at 6:14
add a comment
|
$begingroup$
Since you indicate you're interested only in the determinant, a recursive procedure is faster:
ClearAll[det];
det[0] = 1;
det[1] = b[0];
mem : det[p_] := mem = b[p - 1] det[p - 1] - a[p - 2] c[p - 1] det[p - 2];
d1 = det[15]; // AbsoluteTiming
d2 = Det@sa[15]; // AbsoluteTiming (* sa[p] = SparseArray solution (I used @kglr's) *)
d1 - d2 // Simplify
(*
0.000188, Null
0.391194, Null
0
*)
The results are memoized, so that if you need to compute the determinant for another value of p
, the new result is built on top of any previous computations. As long as storing the results is not a problem (in terms of RAM), it should make things faster.
$endgroup$
$begingroup$
You'd think this method would be built into M somewhere, but I can't find it.
$endgroup$
– Michael E2
Oct 15 at 21:30
add a comment
|
$begingroup$
An alternative, and faster, way to construct the SparseArray
using Band
:
sa[n_] := SparseArray[
Band[1, 1] -> Array[b, n, 0],
Band[2, 1] -> Array[a, n - 1, 0],
Band[1, 2] -> Array[c, n - 1],
n, n]
sa[10] // MatrixForm // TeXForm
$left(
beginarraycccccccccc
b(0) & c(1) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
a(0) & b(1) & c(2) & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
0 & a(1) & b(2) & c(3) & 0 & 0 & 0 & 0 & 0 & 0 \
0 & 0 & a(2) & b(3) & c(4) & 0 & 0 & 0 & 0 & 0 \
0 & 0 & 0 & a(3) & b(4) & c(5) & 0 & 0 & 0 & 0 \
0 & 0 & 0 & 0 & a(4) & b(5) & c(6) & 0 & 0 & 0 \
0 & 0 & 0 & 0 & 0 & a(5) & b(6) & c(7) & 0 & 0 \
0 & 0 & 0 & 0 & 0 & 0 & a(6) & b(7) & c(8) & 0 \
0 & 0 & 0 & 0 & 0 & 0 & 0 & a(7) & b(8) & c(9) \
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a(8) & b(9) \
endarray
right)$
$endgroup$
1
$begingroup$
Originally I thought to use yourBand
method (from the other very similar question recently), but didn't think to create the element vectors.
$endgroup$
– That Gravity Guy
Oct 15 at 21:21
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f207905%2feasiest-way-to-construct-the-following-determinant%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
One way to do it would be
mat[p_] := SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
Det@mat[p]
For example
With[p = 2,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
]
Det@%
$left(
beginarrayccc
B(0) & textCC(1) & 0 \
A(0) & B(1) & textCC(2) \
0 & A(1) & B(2) \
endarray
right)$
B[0] B[1] B[2] - A[0] B[2] CC[1] - A[1] B[0] CC[2]
But the computation time quickly increases with p
since the elements are symbolic. For example, with p = 17
,
With[p = 17,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
] // Det // RepeatedTiming // First
2.7
But, if the elements are numeric quantities,
SeedRandom[1234]
With[p = 17,
SparseArray[
i_, i_ :> RandomReal[],
i_, j_ /; i == j + 1 :> RandomReal[],
i_, j_ /; i == j - 1 :> RandomReal[]
,
p + 1
]
] // Det // RepeatedTiming // First
0.0020
the calculation is no problem.
$endgroup$
$begingroup$
thanks a lot. In fact A,B and C are some functions which become determined by initial values.
$endgroup$
– Wisdom
Oct 15 at 6:14
add a comment
|
$begingroup$
One way to do it would be
mat[p_] := SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
Det@mat[p]
For example
With[p = 2,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
]
Det@%
$left(
beginarrayccc
B(0) & textCC(1) & 0 \
A(0) & B(1) & textCC(2) \
0 & A(1) & B(2) \
endarray
right)$
B[0] B[1] B[2] - A[0] B[2] CC[1] - A[1] B[0] CC[2]
But the computation time quickly increases with p
since the elements are symbolic. For example, with p = 17
,
With[p = 17,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
] // Det // RepeatedTiming // First
2.7
But, if the elements are numeric quantities,
SeedRandom[1234]
With[p = 17,
SparseArray[
i_, i_ :> RandomReal[],
i_, j_ /; i == j + 1 :> RandomReal[],
i_, j_ /; i == j - 1 :> RandomReal[]
,
p + 1
]
] // Det // RepeatedTiming // First
0.0020
the calculation is no problem.
$endgroup$
$begingroup$
thanks a lot. In fact A,B and C are some functions which become determined by initial values.
$endgroup$
– Wisdom
Oct 15 at 6:14
add a comment
|
$begingroup$
One way to do it would be
mat[p_] := SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
Det@mat[p]
For example
With[p = 2,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
]
Det@%
$left(
beginarrayccc
B(0) & textCC(1) & 0 \
A(0) & B(1) & textCC(2) \
0 & A(1) & B(2) \
endarray
right)$
B[0] B[1] B[2] - A[0] B[2] CC[1] - A[1] B[0] CC[2]
But the computation time quickly increases with p
since the elements are symbolic. For example, with p = 17
,
With[p = 17,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
] // Det // RepeatedTiming // First
2.7
But, if the elements are numeric quantities,
SeedRandom[1234]
With[p = 17,
SparseArray[
i_, i_ :> RandomReal[],
i_, j_ /; i == j + 1 :> RandomReal[],
i_, j_ /; i == j - 1 :> RandomReal[]
,
p + 1
]
] // Det // RepeatedTiming // First
0.0020
the calculation is no problem.
$endgroup$
One way to do it would be
mat[p_] := SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
Det@mat[p]
For example
With[p = 2,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
]
Det@%
$left(
beginarrayccc
B(0) & textCC(1) & 0 \
A(0) & B(1) & textCC(2) \
0 & A(1) & B(2) \
endarray
right)$
B[0] B[1] B[2] - A[0] B[2] CC[1] - A[1] B[0] CC[2]
But the computation time quickly increases with p
since the elements are symbolic. For example, with p = 17
,
With[p = 17,
SparseArray[
i_, i_ :> B[i - 1],
i_, j_ /; i == j + 1 :> A[j - 1],
i_, j_ /; i == j - 1 :> CC[j - 1]
,
p + 1
]
] // Det // RepeatedTiming // First
2.7
But, if the elements are numeric quantities,
SeedRandom[1234]
With[p = 17,
SparseArray[
i_, i_ :> RandomReal[],
i_, j_ /; i == j + 1 :> RandomReal[],
i_, j_ /; i == j - 1 :> RandomReal[]
,
p + 1
]
] // Det // RepeatedTiming // First
0.0020
the calculation is no problem.
answered Oct 15 at 5:51
That Gravity GuyThat Gravity Guy
3,0411 gold badge6 silver badges17 bronze badges
3,0411 gold badge6 silver badges17 bronze badges
$begingroup$
thanks a lot. In fact A,B and C are some functions which become determined by initial values.
$endgroup$
– Wisdom
Oct 15 at 6:14
add a comment
|
$begingroup$
thanks a lot. In fact A,B and C are some functions which become determined by initial values.
$endgroup$
– Wisdom
Oct 15 at 6:14
$begingroup$
thanks a lot. In fact A,B and C are some functions which become determined by initial values.
$endgroup$
– Wisdom
Oct 15 at 6:14
$begingroup$
thanks a lot. In fact A,B and C are some functions which become determined by initial values.
$endgroup$
– Wisdom
Oct 15 at 6:14
add a comment
|
$begingroup$
Since you indicate you're interested only in the determinant, a recursive procedure is faster:
ClearAll[det];
det[0] = 1;
det[1] = b[0];
mem : det[p_] := mem = b[p - 1] det[p - 1] - a[p - 2] c[p - 1] det[p - 2];
d1 = det[15]; // AbsoluteTiming
d2 = Det@sa[15]; // AbsoluteTiming (* sa[p] = SparseArray solution (I used @kglr's) *)
d1 - d2 // Simplify
(*
0.000188, Null
0.391194, Null
0
*)
The results are memoized, so that if you need to compute the determinant for another value of p
, the new result is built on top of any previous computations. As long as storing the results is not a problem (in terms of RAM), it should make things faster.
$endgroup$
$begingroup$
You'd think this method would be built into M somewhere, but I can't find it.
$endgroup$
– Michael E2
Oct 15 at 21:30
add a comment
|
$begingroup$
Since you indicate you're interested only in the determinant, a recursive procedure is faster:
ClearAll[det];
det[0] = 1;
det[1] = b[0];
mem : det[p_] := mem = b[p - 1] det[p - 1] - a[p - 2] c[p - 1] det[p - 2];
d1 = det[15]; // AbsoluteTiming
d2 = Det@sa[15]; // AbsoluteTiming (* sa[p] = SparseArray solution (I used @kglr's) *)
d1 - d2 // Simplify
(*
0.000188, Null
0.391194, Null
0
*)
The results are memoized, so that if you need to compute the determinant for another value of p
, the new result is built on top of any previous computations. As long as storing the results is not a problem (in terms of RAM), it should make things faster.
$endgroup$
$begingroup$
You'd think this method would be built into M somewhere, but I can't find it.
$endgroup$
– Michael E2
Oct 15 at 21:30
add a comment
|
$begingroup$
Since you indicate you're interested only in the determinant, a recursive procedure is faster:
ClearAll[det];
det[0] = 1;
det[1] = b[0];
mem : det[p_] := mem = b[p - 1] det[p - 1] - a[p - 2] c[p - 1] det[p - 2];
d1 = det[15]; // AbsoluteTiming
d2 = Det@sa[15]; // AbsoluteTiming (* sa[p] = SparseArray solution (I used @kglr's) *)
d1 - d2 // Simplify
(*
0.000188, Null
0.391194, Null
0
*)
The results are memoized, so that if you need to compute the determinant for another value of p
, the new result is built on top of any previous computations. As long as storing the results is not a problem (in terms of RAM), it should make things faster.
$endgroup$
Since you indicate you're interested only in the determinant, a recursive procedure is faster:
ClearAll[det];
det[0] = 1;
det[1] = b[0];
mem : det[p_] := mem = b[p - 1] det[p - 1] - a[p - 2] c[p - 1] det[p - 2];
d1 = det[15]; // AbsoluteTiming
d2 = Det@sa[15]; // AbsoluteTiming (* sa[p] = SparseArray solution (I used @kglr's) *)
d1 - d2 // Simplify
(*
0.000188, Null
0.391194, Null
0
*)
The results are memoized, so that if you need to compute the determinant for another value of p
, the new result is built on top of any previous computations. As long as storing the results is not a problem (in terms of RAM), it should make things faster.
answered Oct 15 at 21:24
Michael E2Michael E2
160k13 gold badges219 silver badges519 bronze badges
160k13 gold badges219 silver badges519 bronze badges
$begingroup$
You'd think this method would be built into M somewhere, but I can't find it.
$endgroup$
– Michael E2
Oct 15 at 21:30
add a comment
|
$begingroup$
You'd think this method would be built into M somewhere, but I can't find it.
$endgroup$
– Michael E2
Oct 15 at 21:30
$begingroup$
You'd think this method would be built into M somewhere, but I can't find it.
$endgroup$
– Michael E2
Oct 15 at 21:30
$begingroup$
You'd think this method would be built into M somewhere, but I can't find it.
$endgroup$
– Michael E2
Oct 15 at 21:30
add a comment
|
$begingroup$
An alternative, and faster, way to construct the SparseArray
using Band
:
sa[n_] := SparseArray[
Band[1, 1] -> Array[b, n, 0],
Band[2, 1] -> Array[a, n - 1, 0],
Band[1, 2] -> Array[c, n - 1],
n, n]
sa[10] // MatrixForm // TeXForm
$left(
beginarraycccccccccc
b(0) & c(1) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
a(0) & b(1) & c(2) & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
0 & a(1) & b(2) & c(3) & 0 & 0 & 0 & 0 & 0 & 0 \
0 & 0 & a(2) & b(3) & c(4) & 0 & 0 & 0 & 0 & 0 \
0 & 0 & 0 & a(3) & b(4) & c(5) & 0 & 0 & 0 & 0 \
0 & 0 & 0 & 0 & a(4) & b(5) & c(6) & 0 & 0 & 0 \
0 & 0 & 0 & 0 & 0 & a(5) & b(6) & c(7) & 0 & 0 \
0 & 0 & 0 & 0 & 0 & 0 & a(6) & b(7) & c(8) & 0 \
0 & 0 & 0 & 0 & 0 & 0 & 0 & a(7) & b(8) & c(9) \
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a(8) & b(9) \
endarray
right)$
$endgroup$
1
$begingroup$
Originally I thought to use yourBand
method (from the other very similar question recently), but didn't think to create the element vectors.
$endgroup$
– That Gravity Guy
Oct 15 at 21:21
add a comment
|
$begingroup$
An alternative, and faster, way to construct the SparseArray
using Band
:
sa[n_] := SparseArray[
Band[1, 1] -> Array[b, n, 0],
Band[2, 1] -> Array[a, n - 1, 0],
Band[1, 2] -> Array[c, n - 1],
n, n]
sa[10] // MatrixForm // TeXForm
$left(
beginarraycccccccccc
b(0) & c(1) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
a(0) & b(1) & c(2) & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
0 & a(1) & b(2) & c(3) & 0 & 0 & 0 & 0 & 0 & 0 \
0 & 0 & a(2) & b(3) & c(4) & 0 & 0 & 0 & 0 & 0 \
0 & 0 & 0 & a(3) & b(4) & c(5) & 0 & 0 & 0 & 0 \
0 & 0 & 0 & 0 & a(4) & b(5) & c(6) & 0 & 0 & 0 \
0 & 0 & 0 & 0 & 0 & a(5) & b(6) & c(7) & 0 & 0 \
0 & 0 & 0 & 0 & 0 & 0 & a(6) & b(7) & c(8) & 0 \
0 & 0 & 0 & 0 & 0 & 0 & 0 & a(7) & b(8) & c(9) \
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a(8) & b(9) \
endarray
right)$
$endgroup$
1
$begingroup$
Originally I thought to use yourBand
method (from the other very similar question recently), but didn't think to create the element vectors.
$endgroup$
– That Gravity Guy
Oct 15 at 21:21
add a comment
|
$begingroup$
An alternative, and faster, way to construct the SparseArray
using Band
:
sa[n_] := SparseArray[
Band[1, 1] -> Array[b, n, 0],
Band[2, 1] -> Array[a, n - 1, 0],
Band[1, 2] -> Array[c, n - 1],
n, n]
sa[10] // MatrixForm // TeXForm
$left(
beginarraycccccccccc
b(0) & c(1) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
a(0) & b(1) & c(2) & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
0 & a(1) & b(2) & c(3) & 0 & 0 & 0 & 0 & 0 & 0 \
0 & 0 & a(2) & b(3) & c(4) & 0 & 0 & 0 & 0 & 0 \
0 & 0 & 0 & a(3) & b(4) & c(5) & 0 & 0 & 0 & 0 \
0 & 0 & 0 & 0 & a(4) & b(5) & c(6) & 0 & 0 & 0 \
0 & 0 & 0 & 0 & 0 & a(5) & b(6) & c(7) & 0 & 0 \
0 & 0 & 0 & 0 & 0 & 0 & a(6) & b(7) & c(8) & 0 \
0 & 0 & 0 & 0 & 0 & 0 & 0 & a(7) & b(8) & c(9) \
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a(8) & b(9) \
endarray
right)$
$endgroup$
An alternative, and faster, way to construct the SparseArray
using Band
:
sa[n_] := SparseArray[
Band[1, 1] -> Array[b, n, 0],
Band[2, 1] -> Array[a, n - 1, 0],
Band[1, 2] -> Array[c, n - 1],
n, n]
sa[10] // MatrixForm // TeXForm
$left(
beginarraycccccccccc
b(0) & c(1) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
a(0) & b(1) & c(2) & 0 & 0 & 0 & 0 & 0 & 0 & 0 \
0 & a(1) & b(2) & c(3) & 0 & 0 & 0 & 0 & 0 & 0 \
0 & 0 & a(2) & b(3) & c(4) & 0 & 0 & 0 & 0 & 0 \
0 & 0 & 0 & a(3) & b(4) & c(5) & 0 & 0 & 0 & 0 \
0 & 0 & 0 & 0 & a(4) & b(5) & c(6) & 0 & 0 & 0 \
0 & 0 & 0 & 0 & 0 & a(5) & b(6) & c(7) & 0 & 0 \
0 & 0 & 0 & 0 & 0 & 0 & a(6) & b(7) & c(8) & 0 \
0 & 0 & 0 & 0 & 0 & 0 & 0 & a(7) & b(8) & c(9) \
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a(8) & b(9) \
endarray
right)$
answered Oct 15 at 20:54
kglrkglr
225k10 gold badges254 silver badges511 bronze badges
225k10 gold badges254 silver badges511 bronze badges
1
$begingroup$
Originally I thought to use yourBand
method (from the other very similar question recently), but didn't think to create the element vectors.
$endgroup$
– That Gravity Guy
Oct 15 at 21:21
add a comment
|
1
$begingroup$
Originally I thought to use yourBand
method (from the other very similar question recently), but didn't think to create the element vectors.
$endgroup$
– That Gravity Guy
Oct 15 at 21:21
1
1
$begingroup$
Originally I thought to use your
Band
method (from the other very similar question recently), but didn't think to create the element vectors.$endgroup$
– That Gravity Guy
Oct 15 at 21:21
$begingroup$
Originally I thought to use your
Band
method (from the other very similar question recently), but didn't think to create the element vectors.$endgroup$
– That Gravity Guy
Oct 15 at 21:21
add a comment
|
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f207905%2feasiest-way-to-construct-the-following-determinant%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown