Guest User

Untitled

a guest
Oct 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. A[dim_] := SparseArray[{Band[{1,1}]->1, Band[{1,2}]->-1}, {dim-1, dim}]
  2. M[dim_] := Transpose[A[dim]] . A[dim]
  3.  
  4. mins[x_] := With[{dim = Length[x]},
  5. LinearSolve[IdentityMatrix[dim, SparseArray] + dim M[dim], x]
  6. ]
  7.  
  8. SeedRandom[1]
  9. x = RandomReal[1, 5]
  10. s = mins[x]
  11.  
  12. 1/5 (x - s) . (x - s) + s . M[5] . s
  13.  
  14. SeedRandom[2]
  15. x = RandomReal[1, 100];
  16. s = mins[x]; //AbsoluteTiming
  17.  
  18. 1/100 (x - s) . (x - s) + s . M[100] . s
Add Comment
Please, Sign In to add comment