home *** CD-ROM | disk | FTP | other *** search
- (* MATRICES *)
-
- tciadj2[m_,i_,j_] :=
- Det[Delete[Transpose[Delete[m,i] ],j]]*(-1)^(i+j)
-
- tciadjoint[m_] :=
- If[ !(MatrixQ[m] && Dimensions[m][[1]]==Dimensions[m][[2]]),
- Return["ERROR: selection must be a square matrix"],
- Module[{ ggg },
- ggg[i_,j_]:= tciadj2[m,i,j];
- Transpose[Array[ggg, Dimensions[m]]]
- ]
- ]
-
- tcicat[a_,b_] :=
- Transpose[Join[Transpose[a],Transpose[b]]]
-
- tcipermanent[m_] :=
- If[ !(MatrixQ[m] && Dimensions[m][[1]]==Dimensions[m][[2]]),
- Return["ERROR: selection must be a square matrix"],
- Module[{ perm=0, n=Dimensions[m][[1]], mm=m, pp, jj, kk, ppp },
- pp = Permutations[Table[i,{i,n-1}]];
- For[jj=1, jj <= Length[pp], jj++,
- ppp = pp[[jj]];
- For[kk=1, kk<n, kk++, mm[[kk]] = RotateRight[m[[kk]],ppp[[kk]] ] ];
- perm += Apply[Plus,Apply[Times,mm]];
- ];
- Return[perm]
- ]
- ]
-
- tceigen[m_] :=
- Transpose[Eigenvectors[m]]
-
- tcitrace[m_] :=
- Sum[m[[i,i]],{i,Length[m]}]
-
- tcicharpoly[m_,v_:0] :=
- If[v===0,
- If[MemberQ[Variables[m],X],
- Return["needvars"],
- Det[X*IdentityMatrix[Length[m]]-m]
- ],
- Det[v*IdentityMatrix[Length[m]]-m]
- ]
-
- tcicompanion[p_,v_:0] :=
- Module[{tt, vv, len, ss, aa, bb, var},
- If[v===0,
- vv = Variables[p]; If[Length[vv]==1,var=vv[[1]],Return["needvars"]],
- var=v];
- tt = CoefficientList[p,var];
- len = Length[tt];
- ss = tt/tt[[len]];
- ss = Delete[ss,-1];
- aa = IdentityMatrix[len-1];
- bb = Join[Delete[aa,1],{-ss}];
- Transpose[bb]
- ]
-
- tcihtranspose[m_] :=
- ComplexExpand[Conjugate[Transpose[m]]]
-
- tcinorm[a_,t_:2] :=
- Which[
- VectorQ[a], Which[
- NumberQ[t], Apply[Plus,Abs[a]^t]^(1/t),
- t===Infinity, Max[Abs[a]],
- True, Return["ERROR: Norm type not recognized"]
- ],
- MatrixQ[a], Which[
- t===1, Max[Apply[Plus,Abs[a]]],
- t===2, Max[SingularValues[N[a]][[2]]],
- t===Infinity, Max[Apply[Plus,Abs[Transpose[a]]]],
- t===F, Apply[Plus,Flatten[a]^2]^(1/2),
- True, Return["ERROR: Norm type not recognized"]
- ],
- True, Return["ERROR: Selection must be a vector or matrix"]
- ]
-
- tcicondnum[m_] :=
- If[ !(MatrixQ[m] && Dimensions[m][[1]]==Dimensions[m][[2]]),
- Return["ERROR: selection must be a square matrix"],
- tcinorm[m]*tcinorm[Inverse[m]]
- ]
-
- tciSVD[m_] :=
- Module[{mm, uu, dd},
- mm = SingularValues[N[m]];
- uu = Transpose[mm[[1]]];
- dd = DiagonalMatrix[mm[[2]]];
- {uu,dd,mm[[3]]}
- ]
-
- tcisvals[m_] := SingularValues[N[m]][[2]];
-
- tciQR[m_] :=
- Module[{mm,qq},
- mm = QRDecomposition[N[m]];
- qq = Conjugate[Transpose[mm[[1]]]];
- {qq,mm[[2]]}
- ]
-
- lufactor[m_] := LinearAlgebra`GaussianElimination`LUFactor[m];
- tciLUfactor[m_] :=
- Module[{mm, ll, pp, uu, nr, nc, xx, yy},
- If[!MatrixQ[m], Return["ERROR: Input not matrix"] ];
- nr = Dimensions[m][[1]]; nc = Dimensions[m][[2]];
- If[nr!=nc, Return["ERROR: Input not square matrix"] ];
- mm = lufactor[m];
- xx = mm[[1]];
- yy = mm[[2]];
- uu = Table[If[j<i,0,xx[[yy[[i]],j]] ],{i,nr},{j,nc}];
- ll = Table[Which[j>i,0,j==i,1,j<i,xx[[yy[[i]],j]] ],{i,nr},{j,nc}];
- pp = Table[If[i==yy[[j]],1,0],{i,nr},{j,nc}];
- {pp, ll, uu}
- ]
-
- tciBand[x_,m_,n_] :=
- With[{ k = Length[x], p = Ceiling[Length[x]/2]},
- ff[i_,j_] := Which[j-i+p<1,0, j-i+p>k,0, True,x[[j-i+p]] ];
- Array[ff,{m,n}] ]
-
- (* GENERAL *)
-
- tcimpy2[a_,b_] :=
- If[ (MatrixQ[a]||VectorQ[a])&&(MatrixQ[b]||VectorQ[b]), a.b, a*b]
-
- tcimpy[m_:ListQ] :=
- Module[{ t = m[[1]]},
- Do[ t = tcimpy2[t,m[[i]]], {i,2,Length[m]} ] ;
- t
- ]
-
- squarematrix[a_] := MatrixQ[a] && Dimensions[a][[1]]==Dimensions[a][[2]]
-
- tciadd[a_,b_] :=
- Module[{c},
- If[ squarematrix[a] && NumberQ[b],
- c = IdentityMatrix[Dimensions[a][[1]] ];
- Return[a+b*c] ];
- If[ squarematrix[b] && NumberQ[a],
- c = IdentityMatrix[Dimensions[b][[1]] ];
- Return[b+a*c] ];
- a+b
- ]
-
- tcipwr[x_,n_,m_:0] :=
- Module[{ w={}, v={}, r=x, nn=n},
- If[ MatrixQ[n],
- If[ Dimensions[n][[1]] == 1, v = n[[1]]];
- If[ Dimensions[n][[2]] == 1, v = Transpose[n][[1]]]
- ];
- If[ MatrixQ[x] && IntegerQ[n],
- If[ Dimensions[x][[1]] == Dimensions[x][[2]],
- If[m===0,
- Return[MatrixPower[x,n]],
- If[ !PrimeQ[m], Return["ERROR: modulus must be prime"] ];
- If[n < 0, nn=-n; r=Inverse[x, Modulus->m]];
- Return[MatrixPower[r,nn]]
- ],
- Return[x^n]
- ]
- ];
- If[ MatrixQ[x] && (n===H || n===T || n===C),
- If[m===0,
- If[n===T, Return[Transpose[x]] ];
- If[n===C, Return[ComplexExpand[Conjugate[x]]] ];
- If[n===H, Return[ComplexExpand[Conjugate[Transpose[x]]]]],
- Return["ERROR: cannot have modulus"];
- ]
- ];
- If[ MatrixQ[x],
- If[ Dimensions[x][[1]] == 1, w = x[[1]]];
- If[ Dimensions[x][[2]] == 1, w = Transpose[x][[1]]]
- ];
- If[ (Length[v] > 1) && (Length[w] > 1),
- Return[ Outer[Power,w,v]],
- Return[x^n]
- ]
- ]
-
- tcifactor2[x_,m_:0] :=
- Module[{ yy },
- If[ IntegerQ[x],
- yy = Apply[pow, FactorInteger[x], 2]; Apply[Times,yy],
- If[m===0, Factor[x,Trig->True],Factor[x,Modulus->m]]
- ]
- ]
-
- tcifactor[x_,m_:0] :=
- Which[ MatrixQ[x], Map[tcifactor2[#,m]&,x,2],
- ListQ[x], Map[tcifactor2[#,m]&,x],
- True, tcifactor2[x,m]
- ]
- (*
- tcigetvars[m_] :=
- Module[{ qqv = {}},
- Do[ qqv = Union[qqv, Variables[m[[i,1]]], Variables[m[[i,2]]] ],
- {i,1,Length[m]} ] ;
- Return[qqv]
- ]
- *)
-
- tcigetvars[x_Symbol] := {x}
-
- tcigetvars[x_] := Union @ Cases[Level[x, -1], _Symbol?(Context[#]==="Global`"&)]
-
- tcisolve[m_,v_:0] :=
- If[v===0,
- Module[ {qqvars = tcigetvars[m]},
- If[ Length[qqvars] == Length[m],
- Simplify[Solve[m, qqvars]],
- Return["needvars"]
- ]
- ],
- Simplify[Solve[m, v]]
- ]
-
- tcigcd2[a_,b_] :=
- If[ IntegerQ[a] && IntegerQ[b], GCD[a,b], PolynomialGCD[a,b] ]
-
- tcigcd[a_] :=
- Module[{ t = a[[1]]},
- Do[ t = tcigcd2[t,a[[i]]], {i,2,Length[a]}] ;
- Return[t] ]
-
- tcilcm2[a_,b_] :=
- If[ IntegerQ[a] && IntegerQ[b], LCM[a,b], PolynomialLCM[a,b] ]
-
- tcilcm[a_] :=
- Module[{ t = a[[1]]},
- Do[ t = tcilcm2[t,a[[i]]], {i,2,Length[a]}] ;
- Return[t] ]
-
- tcimixnum[x_] :=
- Module[ {quo, rem, a = Abs[x]},
- quo = Floor[a]; rem = a - quo; quo = Sign[x]*quo;
- If[ quo == 0, Return[rem], Return[mixnum[quo,rem]] ]
- ]
-
- tciseries[e_,d_] :=
- Module[ {pow, bb = Series[e,d]},
- pow = bb[[5]]/bb[[6]];
- Return[{Normal[bb] + order[(bb[[1]]-bb[[2]])^pow]} ]
- ]
-
- tciODEseries[eqns_, idata_, Y_, x_, x0_, power_] :=
- Module[{ sol, k, vars, U=Y, ee=eqns, id=idata, bb },
- Do[
- U = D[U,x];
- vars = U/.x->x0;
- sol = Solve[(ee/.x->x0)/.id, vars];
- id = Union[ id, sol[[1]] ];
- ee = D[ee, x ],
- {k, 1, power-1}
- ];
- bb = Normal[Series[Y, {x,x0,power-1}]/.id] + order[(x-x0)^power];
- MapThread[#1 == #2 & ,{Y,bb}]
- ]
-
- tcifindroot[e_,d_:0] :=
- Module[ {len, ok, var, cc, qq, inf, vlist=tcigetvars[e]},
- If[d===0,
- len = Length[vlist];
- ok = ListQ[e] && Length[e]==len;
- If[!ok, Return["ERROR: system inconsistent"] ];
- If[len==1, FindRoot[e, Append[vlist, 10.*Random[]] ],
- cc = Transpose[{vlist,Table[10.*Random[],{len}]}];
- Apply[FindRoot[e,##]&,cc]
- ],
- ok = ListQ[e] && MatrixQ[d];
- If[!ok, Return["ERROR: data inconsistent"] ];
- ok = Length[e]==Length[d];
- If[!ok, Return["ERROR: constrain all variables or none"] ];
- inf = MemberQ[Flatten[d],Infinity] || MemberQ[Flatten[d],-Infinity];
- If[inf, Return["ERROR: infinite ranges not allowed"] ];
- len = Length[e];
- If[len==1, cc=d; cc[[1,2]]=.5*(cc[[1,3]]+cc[[1,4]]),
- qq = Transpose[d]; qq[[2]]=.5*(qq[[3]]+qq[[4]]);
- cc = Transpose[Take[qq,2]]
- ];
- Apply[FindRoot[e,##]&,cc]
- ]
- ]
-
- (* SIMPLEX *)
-
- tciminimize[m_,c_] :=
- Module[ { vars },
- vars = Union[Variables[m],tcigetvars[c]];
- ConstrainedMin[m, c, vars]
- ]
-
- tcimaximize[m_,c_] :=
- Module[ { vars },
- vars = Union[Variables[m],tcigetvars[c]];
- ConstrainedMax[m, c, vars]
- ]
-
- (* POLYNOMIALS *)
-
- tcireverse[a_] :=
- Reverse[Apply[List,a]]
-
- tcipolydiv[p_,d_,v_:0] :=
- Module[{var},
- If[v===0,
- vv = Variables[p];
- If[Length[vv]==1,var=vv[[1]],Return["needvars"]],
- var=v];
- PolynomialQuotient[p,d,var]+PolynomialRemainder[p,d,var]/d
- ]
-
- tciroot[p_,v_:0] :=
- Module[{var,vv,zz},
- If[v===0,
- vv = Variables[p];
- If[Length[vv]==1,var=vv[[1]],Return["needvars"]],
- var=v];
- zz = Roots[p==0,var];
- If[Head[zz]===Roots,
- NSolve[p==0,var],
- Roots[p==0,var] /. lhs_ == rhs_ :> lhs == ComplexExpand[rhs]
- ]
- ]
-
- (* CALCULUS *)
- tciapart[p_,v_:0] :=
- Module[{var},
- If[v===0,
- vv = Variables[p];
- If[Length[vv]==1,var=vv[[1]],Return["needvars"]],
- var=v];
- Apart[p,var]
- ]
-
- tcisum[e_,v_:0,lim_:0] :=
- Module[ {var, f, ans, vlist=Take[Join[{n},tcigetvars[e]],-1]},
- If[v===0, var=vlist[[1]], var=v, ul];
- If[lim===0, lim={1,var}];
- f = e /. var->xx;
- ans = Sum[f, Evaluate[Join[{xx},lim]] ];
- Simplify[ ans /. xx->var ]
- ]
-
- tciprod[e_,v_:0,lim_:0] :=
- Module[ {var, f, ans, vlist=Take[Join[{n},tcigetvars[e]],-1]},
- If[v===0, var=vlist[[1]], var=v];
- If[lim===0, lim={1,var}];
- f = e /. var->xx;
- ans = Product[f, Evaluate[Join[{xx},lim]] ];
- Simplify[ ans /. xx->var ]
- ]
-
- tciint[e_,v_:0,lim_:0] :=
- Module[ {var, f, ans, vlist=Take[Join[{x},tcigetvars[e]],-1]},
- If[v===0, var=vlist[[1]], var=v];
- If[lim===0, Return[ Integrate[e,var] ] ];
- f = e /. var->xx;
- ans = Integrate[f, Join[{xx},lim] ];
- Simplify[ ans /. xx->var ]
- ]
-
- tcintparts[e_,v_,d_] :=
- Module[ {bb = Simplify[e/d], cc, dd, up, low },
- If[ListQ[v], var = v[[1]], var = v];
- cc =Integrate[bb,var];
- dd =D[d,var ];
- If[ListQ[v],
- up = cc*d /.var->v[[3]];
- low = cc*d /.var->v[[2]];
- Return[up - low - int[cc*dd, v]],
- Return[cc*d - int[cc*dd,var ]]
- ]
- ]
-
- tciNDSolve[e_,f_,a_,sol_,v_] :=
- Module[ { },
- Clear /@ a;
- sol = NDSolve[e,f,v];
- MapThread[(#1[x_] := Evaluate[#2[x] /. sol])&, {a, f}];
- a
- ]
-
-
- tcichangevar[d_,e_,v_] :=
- Module[ {bb , cc, dd, var, newvar=d[[1]], up, low },
- If[ListQ[v], var = v[[1]], var = v];
- dd =d[[2]];
- bb = D[dd,var];
- cc = e/bb /.Solve[d,var];
- If[ListQ[cc], cc = Last[cc]];
- If[ListQ[v],
- up = dd /.var->v[[3]];
- low = dd /.var->v[[2]];
- Return[int[cc, {newvar,low,up}]],
- Return[int[cc, newvar]]
- ]
- ]
-
- (* VECTORS *)
-
- curl[x_] := Calculus`VectorAnalysis`Curl[x]
-
- div[x_] := Calculus`VectorAnalysis`Div[x]
-
- xprod[x_,y_] := Calculus`VectorAnalysis`CrossProduct[x,y]
-
- tcidprod[a_,b_] :=
- If[ VectorQ[a] && VectorQ[b], a.b, a*b]
-
- tcixprod[a_,b_] :=
- If[ VectorQ[a] && VectorQ[b], xprod[a,b], a*b]
-
- tcihessian[e_] :=
- Module[ {vars = Variables[e]},
- Array[D[e,vars[[#1]],vars[[#2]]]&,{Length[vars],Length[vars]}]
- ]
-
- tcijacobian[a_,v_:0] :=
- Module[{aa, vars, gg},
- If[MatrixQ[a],
- If[Dimensions[a][[2]]==1, aa = Transpose[a][[1]],
- If[Dimensions[a][[1]]==1, aa = a[[1]],
- Return[ERROR: not row or column matrix] ]
- ], aa = a
- ];
- If[v===0, vars = Variables[aa];
- If[ Length[vars] != Length[aa], Return["needvars"]],
- vars = v
- ];
- gg[i_,j_] := D[aa[[i]],vars[[j]]];
- Array[gg,{Length[vars],Length[vars]}]
- ]
-
- tcipotential[a_,v_:0] :=
- Module[{aa, ff, gg, hh, vars, ans, c },
- If[MatrixQ[a],
- If[Dimensions[a][[2]]==1, aa = Transpose[a][[1]],
- If[Dimensions[a][[1]]==1, aa = a[[1]],
- Return[ERROR: not a row or column matrix] ]
- ], aa = a
- ];
- If[v===0, vars = Variables[aa];
- If[ Length[aa] != 3, Return["ERROR: not a 3D vector field"]];
- If[ Length[vars] != 3, Return["needvars"]],
- vars = v
- ];
- If[tcicurl[aa,vars]!={0,0,0}, Return[0]];
- ans = Integrate[aa[[1]], vars[[1]]];
- Print[ans];
- ans += Integrate[aa[[2]]-D[ans,vars[[2]]], vars[[2]]];
- Print[ans];
- ans += Integrate[aa[[3]]-D[ans,vars[[3]]], vars[[3]]]
- ]
-
- tcicurl[a_] :=
- Module[{aa, bb, cc, dd, v },
- If[MatrixQ[a],
- If[Dimensions[a][[2]]==1, aa = Transpose[a][[1]],
- If[Dimensions[a][[1]]==1, aa = a[[1]],
- Return[ERROR: not a row or column matrix] ]
- ], aa = a
- ];
- curl[aa]
- ]
-
- tcidiverge[a_] :=
- Module[{aa},
- If[MatrixQ[a],
- If[Dimensions[a][[2]]==1, aa = Transpose[a][[1]],
- If[Dimensions[a][[1]]==1, aa = a[[1]],
- Return[ERROR: not a row or column matrix] ]
- ], aa = a
- ];
- div[aa]
- ]
-
- (* STATISTICS *)
-
- mean[x_] := Statistics`DescriptiveStatistics`Mean[x]
-
- median[x_] := Statistics`DescriptiveStatistics`Median[x]
-
- mode[x_] := Statistics`DescriptiveStatistics`Mode[x]
-
- stddev[x_] := Statistics`DescriptiveStatistics`StandardDeviation[x]
-
- meandev[x_] := Statistics`DescriptiveStatistics`MeanDeviation[x]
-
- variance[x_] := Statistics`DescriptiveStatistics`Variance[x]
-
- tcimean[m_] :=
- If[ MatrixQ[m],
- If[ NumberQ[ m[[1,1]] ],
- Map[mean,Transpose[m]],
- Map[mean,Transpose[Drop[m,1]] ]
- ],
- mean[m]
- ]
-
- tcimedian[m_] :=
- If[ MatrixQ[m],
- If[ NumberQ[ m[[1,1]] ],
- Map[median,Transpose[m]],
- Map[median,Transpose[Drop[m,1]] ]
- ],
- median[m]
- ]
-
- tcimode[m_] :=
- If[ MatrixQ[m],
- If[ NumberQ[ m[[1,1]] ],
- Map[mode,Transpose[m]],
- Map[mode,Transpose[Drop[m,1]] ]
- ],
- mode[m]
- ]
-
- tcistddev[m_] :=
- If[ MatrixQ[m],
- If[ NumberQ[ m[[1,1]] ],
- Map[stddev,Transpose[m]],
- Map[stddev,Transpose[Drop[m,1]] ]
- ],
- stddev[m]
- ]
-
-
- tcimeandev[m_] :=
- If[ MatrixQ[m],
- If[ NumberQ[ m[[1,1]] ],
- Map[meandev,Transpose[m]],
- Map[meandev,Transpose[Drop[m,1]] ]
- ],
- meandev[m]
- ]
-
- tcivariance[m_] :=
- If[ MatrixQ[m],
- If[ NumberQ[ m[[1,1]] ],
- Map[variance,Transpose[m]],
- Map[variance,Transpose[Drop[m,1]] ]
- ],
- variance[m]
- ]
-
- (* Stat functions that don't need the Descriptive Stat package *)
-
- tcicorr[m_] :=
- If[ !MatrixQ[m],
- Return["ERROR: selection must be a matrix"],
- Module[ {nrows, xx, tt, oo, mm = N[m]},
- If[ !NumberQ[ m[[1,1]] ], mm = Drop[m,1], _];
- nrows = Dimensions[mm][[1]];
- tt = Transpose[mm];
- oo = Outer[Times,Table[1,{i,nrows}],Map[mean,tt]];
- xx = (mm - oo).DiagonalMatrix[1/Map[stddev,tt]];
- (Transpose[xx].xx)/(nrows-1)
- ]
- ]
-
- tcicovar[m_] :=
- If[ !MatrixQ[m],
- Return["ERROR: selection must be a matrix"],
- Module[ {nrows, dd, mm = N[m]},
- If[ !NumberQ[ m[[1,1]] ], mm = Drop[m,1]];
- nrows = Dimensions[mm][[1]];
- dd = Map[mean,Transpose[mm]];
- (Transpose[mm].mm)/nrows - Outer[Times,dd,dd]
- ]
- ]
-
- tcimoment[m_,p_,a_] :=
- Module[ {nr, nc, bb, cc, mm},
- If[MatrixQ[m], mm=m;
- If[ !NumberQ[ m[[1,1]] ], mm = Drop[m,1]];
- nr = Dimensions[mm][[1]]; nc = Dimensions[mm][[2]];
- If[a===M, bb=Map[mean,Transpose[mm]], bb=Table[a,{nc}]];
- cc = (mm-Outer[Times,Table[1,{nr}],bb])^p;
- Return[(Transpose[cc] . Table[1,{nr}])/nr],
- nr = Length[m];
- If[a===M, bb=Table[mean[m],{nr}], bb=Table[a,{nr}]];
- Apply[Plus, ((m-bb)^p)]/nr
- ]
- ]
-
- tciquantile[m_,q_] :=
- If[ ((q>1) || (q<0)),
- Return["ERROR: quantile must lie on [0,1]."],
- If[ MatrixQ[m],
- If[ NumberQ[ m[[1,1]] ],
- Return[{q,Map[tciquan2[#,q]&,Transpose[m]]}],
- Return[{q,Map[tciquan2[#,q]&,Transpose[Drop[m,1]]]} ]
- ],
- {q,tciquan2[m,q]}
- ]
- ]
-
- tciquan2[m_,q_] :=
- If[ !VectorQ[m,NumberQ], Return["ERROR: Bad data."],
- Module[ {n = Length[m], ii, ss, mm = Sort[m] },
- ii = Floor[n*q+.5];
- ss = n*q+.5-ii;
- If[ii<1, Return[ mm[[1]] ]];
- If[ii>n, Return[ mm[[n]] ]];
- Return[ mm[[ii]]*(1-ss) + mm[[ii+1]]*ss ]
- ]
- ]
-
- tcipolyfit[a_,n_,c_] :=
- If[ !(MatrixQ[a] && Dimensions[a][[2]]==2),
- Return["ERROR: selection must be a 2 column matrix"],
- Module[{ var, var1, aa = a },
- If[ c===0, aa=Transpose[RotateRight[Transpose[a],1]] ];
- var = aa[[1,1]]; var1 = aa[[1,2]];
- If[ NumberQ[ var ],
- Return[{y,"=",Fit[a,Table[x^i,{i,0,n}],x] }],
- Return[{var1, "=", Fit[Drop[aa,1],Table[ var^i,{i,0,n}],var] }]
- ]
- ]
- ]
-
- tcimregress[a_,n_,c_] :=
- If[ !MatrixQ[a], Return["ERROR: selection must be a matrix"],
- If[ NumberQ[ a[[1,1]] ], Return["ERROR: columns must be labelled"],
- Module[ {vars, var1, key, aa = a},
- If[c===0, aa=Transpose[RotateLeft[Transpose[a],1]] ];
- vars = Drop[aa[[1]],-1]; var1 = Take[aa[[1]],-1];
- If[n===0, key=vars, key=Join[vars,{1}] ];
- Return[ {var1,"=", Fit[Drop[aa,1],key,vars]} ]
- ]
- ]
- ]
-
- (* PLOTS *)
-
- tciview[r_,theta_,phi_] :=
- Module[ {x, y, z},
- x = N[r*Cos[theta*Pi/180.]*Sin[phi*Pi/180.]];
- y = N[r*Sin[theta*Pi/180.]*Sin[phi*Pi/180.]];
- z = N[r*Cos[phi*Pi/180.]];
- {x,y,z}
- ]
-
- tciviewlimits[plotlist_]:=
- Module[{outlist={},inlist={},newlist,m,p,j,k,n,approx},
- n=Length[plotlist];
- newlist=Flatten[FullOptions[plotlist,PlotRange]];
- If[Length[newlist]/n==4,m=4,m=6];
- Do[outlist=Append[outlist,Min[Part[newlist,Table[m*(k-1)+p,{k,n}]]]];
- outlist=Append[outlist,Max[Part[newlist,Table[m*(k-1)+p+1,{k,n}]]]],
- {p,1,m-1,2}];
- If[m==4,outlist=Join[outlist,{0,0}]];
- outlist
- ]