Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
A = SparseArray[{Band[{1, 2}] -> 1, Band[{2, 1}] -> -1}, {n, n}]/(2*Δx);

B = SparseArray[{Band[{1, 1}] -> -2, Band[{1, 2}] -> 1, Band[{2, 1}] -> 1}, {n, n}]/(Δx^2);

R = SparseArray[{Band[{1, 1}] -> 1}, {n, n}];

pde = -D[V[S, t], t] == ((r - 0.5 σ^2).A + (0.5 σ^2).B - r.R)V

Having constructed my matrices A, B and R, how do I get Mathematica to solve for a single matrix? I need to replace it in the above equation. I've tried the above codes but failed. I need every element in each matrix be multiplied by the respective scalar. 

share|improve this question
    
Having constructed my matrices A,B and R, how do i solve in mathematica to get a single matrix? I need to replace it in the above equation. I've tried the above codes but failed. I need every element in each matrix be multiplied to the respective scalar. Please help. Thanking you. I should get a linear system, ie, dV/dt = X V, where X is the single matrix and V a vector matrix. Please help. –  aria01 Nov 14 '12 at 14:56
    
What's the shape of $r$, is it a scalar or a vector? If it's a scalar, do you want the expression to look like: (((r - 0.5 \[Sigma]^2)*A + (0.5 \[Sigma]^2)*B - r*R) // Normal // TableForm ).V –  ssch Nov 14 '12 at 15:08
    
Sorry i forgot values, r = 0.03 and sigma = 0.2. Only V which is a vector matrix here. @ssch –  aria01 Nov 14 '12 at 15:29
    
@ssch thanks,i've tried the command but unfortunately the scalar is remaining outside the matrix. I need it to be solved into a single matrix. Could anyone help me. –  aria01 Nov 14 '12 at 20:19
2  
You might want -D[V[s, t], t] == ((r - 0.5 \[Sigma]^2) A + (0.5 \[Sigma]^2) B - r R).V[s, t] Point being, you seem to have reversed Dot and (element-wise) Times. –  Daniel Lichtblau Feb 12 '13 at 22:46

1 Answer 1

((r - 0.5 \[Sigma]^2)*A + (0.5 \[Sigma]^2)*B - r*R).Table[
   V[s, t][[i]], {i, 1, n}] 

So Mathematica sees the different dimensions of V.

It behaves like this:

IdentityMatrix[3].y
(* {{1,0,0},{0,1,0},{0,0,1}}.y *)

IdentityMatrix[3].{y[1], y[2], y[3]}
(* {y[1],y[2],y[3]} *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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