Re: Please help in creating/installing my package
- To: mathgroup at smc.vnet.net
- Subject: [mg79420] Re: [mg79304] Please help in creating/installing my package
- From: John Fultz <jfultz at wolfram.com>
- Date: Thu, 26 Jul 2007 05:35:23 -0400 (EDT)
- Reply-to: jfultz at wolfram.com
The principle thing I can think of is that maybe the cells aren't either initialization cells or using the Code style. An input cell is only exposed to be package code if it's an initialization cell (Cell->Cell Properties->Initialization Cell). All cells of style "Code" (Command+8 in the default stylesheet) are initialization cells. If you created the document by using New->Package, then any cell you begin by simply typing will, by default, be a "Code" style cell. I'm guessing a bit that this is the nature of your problem, but perhaps it's something else. Feel free to email me directly your package file as an attachment and I can take a look at it to see if I can discern anything else, should nothing I've said so far help you. Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc. On Tue, 24 Jul 2007 06:02:34 -0400 (EDT), jeremito wrote: > I have searched through this list and on the web, but haven't yet been > able to find an explanation of how to write/install my own packages in > Mathematica. > > I have a few functions that I want to be able to access from any > Mathematica document. I created my package "Arnoldi.m" (copied below) > and put it into my ~/Library/Mathematica/Applications directory. When > I do > > <<Arnoldi.m > > There are no errors, but I can't use any of the functions I wrote. > Can someone please help me learn how to write my own packages. > Thanks, > Jeremy > > BeginPackage["Arnoldi`"] > > arnoldi::usage = "{Q, H} = Arnoldi[A,q,iters]\nwhere A is a matrix, q > \ > is the starting vector with same size as A, and iters is the number \ > of Arnoldi Iterations. Arnoldi returns: orthonormal basis vectors, \ > columsn of Q; upper Hessenberg matrix, H." > > ArnoldiVectors::usage = > "Vectors = ArnoldiVectors[Q, vecs]\nwhere Q comes an Arnoldi process > \ > and vecs are the eigenvectors of H from the same Arnoldi process." > > Begin["Arnoldi`"] > > arnoldi[A_, v_, iters_] := ( > (* *) > invariant = False; > m = Length[A]; > If[iters > m, > Print["Iterations cannot be greater than size of matrix."]; > iterations = m; > , iterations = iters]; > (*Print["Iterations = ",iterations]*); > > H = ConstantArray[0, {iterations + 1, iterations}]; > Subscript[q, 1] = v/Norm[v]; > > For[k = 1, k <= iterations, k++, > (*Print["k = ", k];*) > Subscript[q, k + 1] = A.Subscript[q, k]; > (*Orthogonalize*) > For[j = 1, j <= k, j++, > (*Print["j = ",j];*) > > H[[j, k]] = Subscript[q, k + 1].Subscript[q, j]; > Subscript[q, k + 1] = > Subscript[q, k + 1] - H[[j, k]] Subscript[q, j]; > ]; > (*Normalize*) > H[[k + 1, k]] = Norm[Subscript[q, k + 1]]; > > If[H[[k + 1, k]] < 10^-10, > Print["I am invariant!"]; > invariant = True; > Break[], > Subscript[q, k + 1] = Subscript[q, k + 1]/H[[k + 1, k]]; > ]; > ]; > If[invariant, iterations = k;, iterations = k - 1]; > H = H[[1 ;; iterations + 1, 1 ;; iterations]]; > Q = Table[Subscript[q, i], {i, iterations + 1}]; > Q = Transpose[Q]; > (*vals = Eigenvalues[H[[1;;k-1,1;;k-1]]];*) > {Q, H} > ) > > ArnoldiVectors[Q_, vecs_] := ( > For[j = 1, j <= Length[vecs], j++, > Subscript[v, j] = ConstantArray[0, Length[vecs[[1]]]]; > For[i = 1, i <= Length[vecs[[j]]], i++, > Subscript[v, j] = Subscript[v, j] + Q[[All, i]]*vecs[[j, i]]; > ]; > ]; > V1 = Table[Subscript[v, i], {i, Length[vecs]}]; > {V1} > ) > > End[] > > EndPackage[]