I thought about this problem a while ago when I was taking GR. I came up with what I think is a reasonable solution, although it may be more complicated then you might like. I will give a brief overview of my approach below, and then provide the code at the end. I am in agreement with some of the other posters that modifying Power is not a good solution. On the other hand, I didn't want to change the standard notation used for tensors. This means that one has to go into the guts of MakeExpression to change the way Mathematica handles SuperscriptBoxes before Mathematica turns them in to powers. The problem then is to come up with a way to have SuperscriptBoxes turn into tensors when we want them to, and have them turn into powers otherwise. I solved this problem by defining a list of what objects are tensors, that is, what are the symbols s that when given a superscript should be a tensor. The next problem that arises is the internal representation of a tensor. I made the decision that a tensor is represented by a Tensor[] object, where the first argument is the tensor symbol, and the remaining arguments are the indices. With this approach, we need a different way to indicate that an index is contravariant or covariant. My approach was to attach a symbol to each index representing what kind of index it is. So, with ui (upper index) denoting a contravariant index and li (lower index) denoting a covariant index, a tensor T_{mu nu}^lambda (in latex notation) would be internally represented as Tensor[T, li[mu,nu], ui[lambda] ] Now for the code, with some remarks. The code needs more work, and ought to be put into a package. When I looked at this problem, I also wanted to be able to define a tensor as a matrix, and to extract from the matrix the value corresponding to the indices when they were integers. For this reason I gave Tensor the HoldFirst attribute. Clear[Tensor] SetAttributes[Tensor,HoldFirst] We want to override the default handling of superscripts when the base object is a tensor. For this purpose we need to first define which symbols are tensors. This is what the functions ClearTensor and MakeTensor do. Since we need to be able to check for tensors before the default Power code happens, we need to know whether an object is a tensor during the MakeExpression phase. Hence, we store the tensors as strings and not symbols. The TensorQ function is used during the MakeExpression phase, so it does not need to hold any arguments. ClearAll[ClearTensor,MakeTensor] SetAttributes[ClearTensor,HoldAll] SetAttributes[MakeTensor,HoldAll] ClearTensor[]:=Module[{}, tensors={}; ] ClearTensor[a__Symbol]:=Module[{}, tensors=Complement[tensors,List@@ToString/@Unevaluated/@Hold[a]];] MakeTensor[a__Symbol]:=Module[{}, tensors=Union[tensors,List@@ToString/@Unevaluated/@Hold[a]]; ] tensors={}; TensorQ[f_?(MemberQ[tensors,#]&)]:=True TensorQ[SuperscriptBox[f_,_]]:=TensorQ[f] TensorQ[SubscriptBox[f_,_]]:=TensorQ[f] Here we define the rules for handling SuperscriptBoxes and SubscriptBoxes during the MakeExpression phase when a tensor is involved. Basically, we strip out the superscripts and subscripts, replacing them with ui[] and li[] as appropriate. Note that I made the decision that indices are separated by a single space, so that commas and semicolons can be interpreted as derivatives in the usual way. I have not included derivatives below, but it is straightforward to do so. Finally, when a subscript follows a superscript, Mathematica automatically inserts a parenthesis around the superscripted tensor. This must be because superscripts have a different precedence than subscripts. My code does not handle this situation properly. There are several solutions. First, every time Mathematica puts in a spurious parenthesis, delete it. This was the solution I followed. If this is too cumbersome, then you will need to include additional code below to handle these parentheses, or you will need to figure out how Mathematica inserts the parenthesis and change that behaviour. Including code to handle the parentheses shouldn't be too difficult. Changing Mathematica's behavior is more difficult, if not impossible, and while I believe that it is possible to change, I never spent the time trying to figure it out. Clear[MakeExpression] MakeExpression[SuperscriptBox[f_?(TensorQ[#]&),h_],g_]:=Module[{}, MakeExpression[ RowBox[{Tensor[,Stripscript[f],,,ToIndices[ui[,h],]}],g]] MakeExpression[SubscriptBox[f_?(TensorQ[#]&),h_],g_]:=Module[{}, MakeExpression[ RowBox[{Tensor[,Stripscript[f],,,ToIndices[li[,h],]}],g]] Clear[Stripscript] Stripscript[SubscriptBox[f_,h_]]:= Sequence[Stripscript[f],,,ToIndices[li[,h]] Stripscript[SuperscriptBox[f_,h_]]:= Sequence[Stripscript[f],,,ToIndices[ui[,h]] Stripscript[f_]:=f Clear[ToIndices,MoreIndices] ToIndices[s_,a_]:=RowBox[{s,a,]}]; ToIndices[s_,RowBox[{a_, ,b__}]]:= RowBox[{s,a,,,MoreIndices[b],]}] MoreIndices[a_, ,b__]:=Sequence[a,,,MoreIndices[b]] MoreIndices[a_]:=a Finally, we need to provide rules to MakeBoxes, so as to convert the internal form of a tensor into the standard representation with raised and lowered indices. Clear[MakeBoxes] MakeBoxes[Tensor[a__,b_li],f_]:= SubscriptBox[MakeBoxes[Tensor[a],f],MakeBoxes[b,f]] MakeBoxes[Tensor[a__,b_ui],f_]:= SuperscriptBox[MakeBoxes[Tensor[a],f],MakeBoxes[b,f]] MakeBoxes[Tensor[a_],f_]:=MakeBoxes[a,f] MakeBoxes[ui[a__],f_]:=RowBox[{a}] MakeBoxes[li[a__],f_]:=RowBox[{a}] Some examples: In[36]:= !((T^2)_3^1 // FullForm) Out[36]//FullForm= Tensor[T,ui[2],li[3],ui[1]] In[37]:= Tensor[T, ui[a], li[b], ui[c]] Out[37]= !((T^a)_b^c) If the above looks like an approach you want to check out, I would be happy to to help out further. Carl Woll Physics Dept U of Washington I've been trying to assign values to superscripted variable, ex, > a^i = 5 > but I get a message that Tag Power is protected. > I can > Unprotect[Power] > first and then it works fine. > However after a few more expressions, Power somehow gets reprotected! > Does anyone know what causes this? > How can I keep Power unprotected for the remainder of the session? Dave Snead > ==== I just tried a friend's Mathematica 4.0.0.0: Solve[{A == S + Q, Q == 2*S}, A] => {A->3*S} Solve[{A == S + Q, Q == 2*S}, S] => {} Can somebody explain this to me? (ie. bug,you stupid) Marco ==== > I am using the Mathematic 4.2. You don't use 4.2 -- 4.1 is the actual version ! > Could you tell me some information about data > files: (1) If I want to save data to files in fixed format. If can't be mor specific you should look what $ExportFormats know >(2) If I want to > read data from two different files and save to one new file. Look at $ImportFormats >(3) plot a curve > reading data from a file. Read data format .xyz and say ListPlot[], ListPlot3D[], ... ? Jens ==== I don't think two hours is too long... you might want to check out variance-reduction techniques and the use of pseudp-random numbers to make your simulations converge faster > Dear Friends, I began to use Mathematica some monthes ago. And already I have small > problems. I make about 250x10000 Monte-Carlo Simulations. My programme > calculates it about 2 hours. Is it really so long? Maybe it's a > mistake of my programm. Und there are some tricks to make a > calculation more quick? > Andrei Rogatchev ==== > > Dear Friends, > > I began to use Mathematica some monthes ago. And already I have small > problems. I make about 250x10000 Monte-Carlo Simulations. My programme > calculates it about 2 hours. Is it really so long? Maybe it's a > mistake of my programm. Und there are some tricks to make a > calculation more quick? > > > Andrei Rogatchev maybe the Mathematica Function 'Compile' will help you, Yours, Alexander Dreyer -- / Alexander Dreyer, Dipl.-Math. - Abteilung Adaptive Systeme / Fraunhofer Institut fuer Techno- und Wirtschaftsmathematik (ITWM) Gottlieb-Daimler-Strasse, Geb. 7^2=49/313 D-67663 Kaiserslautern / http://www.itwm.fhg.de Tel.:(0631)205-2851 Fax:(0631)205-4139 / ==== > Dear Friends, > > I began to use Mathematica some monthes ago. And already I have small > problems. I make about 250x10000 Monte-Carlo Simulations. My programme > calculates it about 2 hours. Is it really so long? Maybe it's a > mistake of my programm. Und there are some tricks to make a > calculation more quick? > > > Andrei Rogatchev > Have you tried to make a graph of the calc time vs # of simulations for samller #s and extrapolate to see if the 2 hours make sense? -- If it is growing in a non linear way, can you simplify the algorithm to get back to linearity? Dick Palmer ==== > I began to use Mathematica some monthes ago. And already I have small > problems. I make about 250x10000 Monte-Carlo Simulations. My programme > calculates it about 2 hours. Is it really so long? Maybe it's a > mistake of my programm. Und there are some tricks to make a > calculation more quick? No one will know unless you post either the entire code, or just an excerpt which isolates the bottleneck. Generally, you should be staying away from Do[...], For[...] and other favourites, employing Map[...] and similar functions wherever possible. That said, it might be that you're better off with F90/C++/ than Mathematica for certain parts of your calculations. Dave. -------------------------------------------------------- Dr. David Annetts EM Modelling Analyst Tel: (+612) 9490 5416 CSIRO DEM, North Ryde Fax: (+612) 9490 5467 David.Annetts@csiro.au Include usual_disclaimers -------------------------------------------------------- ==== Just noticed that in the Help Browser under Getting Started/Demos : Demos > Programming Sampler, there a very nice example of Mandlebrot and Julia sets. -Selwyn ==== Sorry for the typo. That should be section1counter = 1; numeqcounter = 0; Export[file.html, nb, HTML, ConversionOptions -> {MarkupRules -> { Section1 :> {

<>ToString[section1counter++]<>.,

}, NumberedEquation :> {setnumeq[numeqcounter++];

,

} }}]; SetOptions[$FrontEnd, CounterAssignments -> {}] >In[3]:= >section1counter=1; >numeqcounter=0; >Export[file.html,nb, > ConversionOptions->{MarkupRules->{ > Section1:>{

<>ToString[section1counter++]<>.

}, > NumberedEquation:>{setnumeq[numeqcounter++];

,

} >}}]; >SetOptions[$FrontEnd, CounterAssignments->{}] -Dale ==== a 2d point {x,y} has the homogen coordinates ph={x,y,1} a translation is T.ph with T={{1,0,tx}, {0,1,ty}, {0,0,1}} a rotation is R.ph with R={{Cos[phi],Sin[phi],0}, {-Sin[phi,Cos[phi],0}, {0,0,1}} a scaling ist S.ph with S={{sx,0,0}, {0,sy,0}, {0,0,1}} To combine all transformations multiply T.R.S=M and compute M.ph finaly return to normal coordinates and strip the last component. Jens > > Dear Mathematica experts, > > I am very new Mathematica user and have one problem > which is for me impossible to solve. > I must define geometric shape by set of points in XY plane and than rotate > that shape (points) in steps of 1 deg around Z axis for 3 or 4 revolutions, > at the same time that > shape must be resized (magnified) by sale fator R for 1 deg reolution > step, and translated downward Z axis by translation factor T for 1 deg > revolution step. > All three transforations must be done at the same time. > That will generate shape similat to snail shell. > At the end must read all coordinate points generated. > I do not want to render or draw generated shape but only > to have coordinates of all the points generaded from the > initial points. > > I do not know is it possible to do something like that with Mathematica. > I will appreciate any help. > > Hrvoje Posilovic > 10000 Zagreb > Croatia > hposilovic@inet.hr > > coordinates > -- > Hrvoje > > hposilovic@inet.hr ==== On Thu, 16 May 2002 09:32:32 +0000 (UTC), Hrvoje Posilovic >Dear Mathematica experts, I am very new Mathematica user and have one problem >which is for me impossible to solve. >I must define geometric shape by set of points in XY plane and than rotate >that shape (points) in steps of 1 deg around Z axis for 3 or 4 revolutions, >at the same time that >shape must be resized (magnified) by sale fator R for 1 deg reolution >step, and translated downward Z axis by translation factor T for 1 deg >revolution step. There are actually many ways to do this in Mathematica. IMO using Shapes package seems most elegant. Here's an example... use [Alpha]/° to get 1 deg step. << Graphics`Shapes` !(myTransform[g_, [Alpha]_, k_, z_, steps_] := [IndentingNewLine]Table[[IndentingNewLine]RotateShape[ [IndentingNewLine]TranslateShape[[IndentingNewLine]AffineShape[ [IndentingNewLine]g, {1 + i ((k - 1)), 1 + i ((k - 1)), 1}[IndentingNewLine]], {0, 0, z i}[IndentingNewLine]], [Alpha] i, 0, 0[IndentingNewLine]], {i, 0. , 1. , 1. /steps}]) g = Polygon[{{1., 0., 0.}, {0., 1., 0.}, {1., 1., 0.}}]; Show[Graphics3D[myTransform[g, 8.[Pi], 7, -7., 55.]]] g = Point[{1., 1., 0}]; myTransform[g, 8.[Pi], 7, -7., 55.] Show[Graphics3D[%]] If you really need only points here's the syntax for stripping procedure... Level[myTransform[g, 2[Pi], 1., -1., 2[Pi]/ °], {2}] // TableForm ==== Hrvoje, Here is a method for creating your snail patterns. This will rotate counterclockwise about the z axis by t radians. rotate[t_] := {{Cos[t], -Sin[t], 0}, {Sin[t], Cos[t], 0}, {0, 0, 1}} This will scale all points from the origin by a factor of r. expand[r_] := {{r, 0, 0}, {0, r, 0}, {0, 0, r}} Here, we apply these two matrices to a point {x,y,z} and then shift in the z direction by dz. (rotate[t].expand[r]).{x, y, z} + {0, 0, dz} {r x Cos[t] - r y Sin[t], r y Cos[t] + r x Sin[t], dz + r z} Now, create a one step transform function which applies itself to the list of point coordinates. (This is probably a little difficult for a new user because I am using a pure function, actually a nested pure function. So you have to look up and see how pure functions work. They are very useful!) transform[t_, r_, dz_] = Function[{x, y, z}, {r x Cos[t] - r y Sin[t], r y Cos[t] + r x Sin[t], dz + r z}] @@ # &; This tries our transform function on a test point. testpoint = {1, 0, 0}; transform[1 Degree, 1.1, -0.01][testpoint] {1.09983, 0.0191976, -0.01} Here is an initial list of points, the corners of a square in the xy-plane. points0 = {{-1, -1, 0}, {1, -1, 0}, {1, 1, 0}, {-1, 1, 0}}; We can generate successive sets of points by using NestList. (I used a pure function again! It maps our transformation onto each successive list of points.) This generates 201 sets of our points, starting with the initial set of points. (Try this statement without the semicolon, replacing 200 by 3, say, to see how it works.) outpoints = NestList[transform[5 Degree, 1.05, -0.05] /@ # &, points0, 200]; Now, we can plot all of our points, converting the point lists into graphical Points. Show[Graphics3D[outpoints /. {x_, y_, z_} -> Point[{x, y, z}]], PlotRange -> All, ImageSize -> 500]; Even more fun is: << RealTime3D` Show[Graphics3D[outpoints /. {x_, y_, z_} -> Point[{x, y, z}]], ImageSize -> 500]; << Default3D` Happy snail hunting! David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ > -----Original Message----- > Sent: Thursday, May 16, 2002 5:09 AM > Dear Mathematica experts, I am very new Mathematica user and have one problem > which is for me impossible to solve. > I must define geometric shape by set of points in XY plane and > than rotate > that shape (points) in steps of 1 deg around Z axis for 3 or 4 > revolutions, > at the same time that > shape must be resized (magnified) by sale fator R for 1 deg reolution > step, and translated downward Z axis by translation factor T for 1 deg > revolution step. > All three transforations must be done at the same time. > That will generate shape similat to snail shell. > At the end must read all coordinate points generated. > I do not want to render or draw generated shape but only > to have coordinates of all the points generaded from the > initial points. I do not know is it possible to do something like that with Mathematica. > I will appreciate any help. Hrvoje Posilovic > 10000 Zagreb > Croatia > hposilovic@inet.hr coordinates > -- > Hrvoje hposilovic@inet.hr > ==== Greeting to neighbooring Croatia, Your taks involves defining points in 3D, that is XYZ. Make a Polygon object. Use package < Dear Mathematica experts, I am very new Mathematica user and have one problem > which is for me impossible to solve. > I must define geometric shape by set of points in XY plane and than rotate > that shape (points) in steps of 1 deg around Z axis for 3 or 4 revolutions, > at the same time that > shape must be resized (magnified) by sale fator R for 1 deg reolution > step, and translated downward Z axis by translation factor T for 1 deg > revolution step. > All three transforations must be done at the same time. > That will generate shape similat to snail shell. > At the end must read all coordinate points generated. > I do not want to render or draw generated shape but only > to have coordinates of all the points generaded from the > initial points. I do not know is it possible to do something like that with Mathematica. > I will appreciate any help. Hrvoje Posilovic > 10000 Zagreb > Croatia > hposilovic@inet.hr coordinates > -- > Hrvoje hposilovic@inet.hr > ==== Is there anyone using this? I'd like to get some user reports on this facility. I suspect it can only be used by persons willing to spend considerable time to become experts. The relatively simple syntax extension that works by a_ b_ := foo[a,b] seems easy to use, at least for simple things. If you don't know what I'm talking about, look at demos/new notation. RJF fateman@cs.berkeley.edu ==== I have been having trouble getting functions to work in Packages that I have created. I have had this problem on a number of occasions, some of which I have fixed (usually I have no idea why it worked when I fixed it, but I don't complain). I have included an excerpt from a package below with a particularly troublesome function that I haven't been able to fix. The package loads fine, but when I call the function I get the following error: ________________________________________________________________________ data2=MSCorrect[data]; MyPackages`gliba`Private`BestFitParameters Part::partd: Part specification MyPackages`gliba`Private`BestFitParameters[[1]] is longer than depth of object. Part::partd: Part specification MyPackages`gliba`Private`BestFitParameters[[2]] is longer than depth of object. _______________________________________________________________________ I put the packages in the Applications directory in a folder called MyPackages. The function takes a rectangular matrix of real values. If I copy the function into a notebook and compile it there it works fine. Aaron Here is the excerpt from the package. It contains alot more functions than this, most of which work fine. I get the same error when I use this reduced package. _______________________________________________________________________ BeginPackage[`gliba`] GLiba::usage = GLib is a package that serves as a chemometric toolbox for analysis of real data sets. MSCorrect::usage = Begin[`Private`] Needs[Statistics`DataManipulation`] Needs[Statistics`DescriptiveStatistics`] Needs[Statistics`LinearRegression`] MSCorrect[tnspec_List]:= Module[{norows,nocols,temp,i,coeff,x,output,outspec}, {norows, nocols} = Dimensions[tnspec]; temp = Table[0, {2}, {nocols}]; outspec = Table[0, {norows}, {nocols}]; temp[[1]] = Mean[tnspec]; For[i = 1, i < norows + 1, ++i, temp[[2]] = tnspec[[i]]; output = Regress[Transpose[temp], {x},{x}, RegressionReport->{BestFitParameters}]; coeff = BestFitParameters /. output; Print[coeff]; outspec[[i]] = (tnspec[[i]] - coeff[[1]])/coeff[[2]]; ]; Return[outspec] ]; End[ ] EndPackage[ ] ==== ParametricPlot3D[{ Cos[phi]*Sin[th], Sin[phi]*Sin[th], Cos[th], EdgeForm[]}, {th, 0, Pi}, {phi, 0, 3Pi/2}] ? Jens > > > I would like to make a ParametricPlot3D, but without black lines that show > parameter traces. > > With Plot3D the effect I need can be achieved with Mesh->False. > > Is it possible with ParametricPlot3D? How? > > Thank you very much, > > -- > Maciej Sobczak > http://www.maciejsobczak.com/ ==== >I would like to make a ParametricPlot3D, but without black lines that show >parameter traces. With Plot3D the effect I need can be achieved with Mesh->False. Is it possible with ParametricPlot3D? How? ParametricPlot3D[ {Cos[u] Cos[v], Sin[u] Cos[v], Sin[v], EdgeForm[]}, {u, 0, 2Pi},{v, -Pi/2, Pi/2}]; Bob Hanlon Chantilly, VA USA ==== Maciej, In Graphics3D the outlines of the polygons are controlled with the directive EdgeForm and not by the Mesh option (which applies only to SurfaceGraphics). EdgeForm[] specifies that the edges not be rendered. The only problem is how to sneak in the EdgeForm[] directive. The standard Mathematica method is a bit unnatural. But here is the method. Let's work with a parametrization for a sphere. sphere = {Cos[t]Cos[p], Sin[t]Cos[p], Sin[p]}; This generates the plot without display. plot1 = ParametricPlot3D[sphere // Evaluate, {p, -Pi/2, Pi/2}, {t, 0, 2Pi}, DisplayFunction -> Identity]; This puts in EdgeForm[] and displays the sphere without the mesh. Show[Graphics3D[EdgeForm[]], plot1]; A second method is to use the form of ParametricPlot3D where a fourth argument is added to the parametrization. The Help says that this is a way to specify a color, but you can put any 3D directives there, including EdgeForm. sphere2 = Join[sphere, {EdgeForm[]}] {Cos[p] Cos[t], Cos[p] Sin[t], Sin[p], EdgeForm[]} Then, the following produces the desired plot. ParametricPlot3D[sphere2 // Evaluate, {p, -Pi/2, Pi/2}, {t, 0, 2Pi}]; Are either of these two methods a very natural or intuitive way to obtain the result? I don't think so and that is why this is such a frequent question on MathGroup. In the DrawGraphics package, available at my web site, you just put the directives you want followed by the graphics objects that use those directives. It would be done this way. Needs[DrawGraphics`DrawingMaster`] Draw3DItems[ {EdgeForm[], ParametricDraw3D[sphere // Evaluate, {p, -Pi/2, Pi/2}, {t, 0, 2Pi}]}]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I would like to make a ParametricPlot3D, but without black lines that show > parameter traces. With Plot3D the effect I need can be achieved with Mesh->False. Is it possible with ParametricPlot3D? How? Thank you very much, -- > Maciej Sobczak > http://www.maciejsobczak.com/ ==== With this procedure i plot a randomwalk RandomWalk[n_]:=NetList[#+(-1)^Random[Integer ])&,0,n] ListPlot [RandomWalk[200],PlotJoined-->True] How can i plot for example 100 random walk on the same plot?? Thankyou ==== I have two questions: (1) I have an equation: eqn = A'[t] = S - (ln(2)/hl)*A[t] and I am trying to find the time at which the discontinuity occurs (t1 and t2) and I have sampled at time t. The constraints for the system are: S(t)=S if t1 In[1]:= > Simplify[a == 1, {a == 1 || a == 2, a != 2}] // InputForm Out[1]//InputForm= > a == 1 In[2]:= > Simplify[a == 1, {a == 1 || a == 2, a != 2, > a [Element] Integers}] // InputForm Out[2]//InputForm= > True In[4]:= > Simplify[a == 2, {a > 1, a < 3, a [Element] Integers}] // InputForm Out[4]//InputForm= > a == 2 In[5]:= > Simplify[a < 3, {a == 1 || a == 2, a [Element] Reals}] Out[5]= > True For starters, I don't see why telling mathematica that something that is > 1 or 2 is an Integer or a Real helps... but ultimately I need something > that will handle linear inequalities in the very least (with multiple > variables), and will be able to work out things like In[4] here. The > problem is co-NP complete (if I've understood things correctly), so I > guess it can't be that fast no matter what. Is this a case of write it yourself? Martin > Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ ==== x[[i]] is not a indexd symbol it is the *part* of an existing expression. you mean Solve[Sum[Subscript[x, i], {i, 1, 5}] == 0, Subscript[x, 2]] Jens > > > I'm somewhat new to mathematica, at least in the world of vectors, and > I'm having trouble getting it to solve an equation for me. > > I basically want to solve: > > sum_{i=1}^n x_i = 0 > > for x_k > > I tried: > > Solve[Sum[x[[i]],{i,1,5}] == 0, x[[2]]] > > as an example, but mathematica complains: > > In[118]:= Solve[Sum[w[[i]],{i=1,5}] == 0, w[[1]]] > > Sum::write: Tag Set in i = 1 is Protected. > > Part::partd: Part specification w[[1]] is longer than depth of object. > > Part::partd: Part specification w[[1]] is longer than depth of object. > > Part::partd: Part specification w[[1]] is longer than depth of object. > > General::stop: Further output of Part::partd > will be suppressed during this calculation. > > Out[118]= {{w[[1]] -> 0}} > > I'm not exactly sure what this means. > > I could write it out: > > In[119]:= Solve[w1+w2+w3+w4+w5==0, w1] > > Out[119]= {{w1 -> -w2 - w3 - w4 - w5}} > > But this isn't very helpful in my situation (my equations are huge*), and > doesn't reflect the vector quality of the situation. > > If such a thing is possible, I'd appreciate some pointers (I read the > mathematica docs on the wolfram site, but couldn't find anything talking > about this). > > > - Hal > > * the equation i'm working with is something like: > > sum_{C,x,y,y'} (wx . wy) (wx . wy') (|wx * wy'| (wx . wy) - |wx * wy| (wx > . wy')) / (|wx|^4 |wy|^2 |wy'|^2) == 0 > > where > > . is dot product > * is cross product > |x| is magnitude of x > and > for vectors w=, x=, > wx = > -- > Hal Daume III > > Computer science is no more about computers | hdaume@isi.edu > than astronomy is about telescopes. -Dijkstra | www.isi.edu/~hdaume ==== Hal, I would say, from the general tenor of your question, that you might save some time in the long run if you worked through as much of Part I of The Mathematica Book as seems relevant. It is difficult to attack specific problems without a knowledge of how Mathematica represents various objects. When you take a Part of an expression, such as w[[3]] say, then w must be a expression that has a 3'rd part. That means you have to make an assignment for w. So you could write: w = {w1, w2, w3, w4, w5}; eqn = Sum[w[[i]], {i, 1, 5}] == 0; sol = Solve[eqn, w[[2]]] {{w2 -> -w1 - w3 - w4 - w5}} This is the standard form of output when Mathematica solves equations. It is a replacement rule, which says that w2 is replaced by the right hand side. It is in brackets because you might be solving for more than one variable, and there might be multiple solutions. The rule is better than an equation because you can use it to make substitutions in expressions. For example, you can check the solution in the equation. eqn /. sol {True} Another, and maybe better, method might be not to use Parts. Just use w[i]. Clear[w]; Solve[Sum[w[i], {i, 1, 5}] == 0, w[2]] {{w[2] -> -w[1] - w[3] - w[4] - w[5]}} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ > -----Original Message----- > Sent: Thursday, May 16, 2002 5:09 AM I'm somewhat new to mathematica, at least in the world of vectors, and > I'm having trouble getting it to solve an equation for me. I basically want to solve: sum_{i=1}^n x_i = 0 for x_k I tried: Solve[Sum[x[[i]],{i,1,5}] == 0, x[[2]]] as an example, but mathematica complains: In[118]:= Solve[Sum[w[[i]],{i=1,5}] == 0, w[[1]]] Sum::write: Tag Set in i = 1 is Protected. Part::partd: Part specification w[[1]] is longer than depth of object. Part::partd: Part specification w[[1]] is longer than depth of object. Part::partd: Part specification w[[1]] is longer than depth of object. General::stop: Further output of Part::partd > will be suppressed during this calculation. Out[118]= {{w[[1]] -> 0}} I'm not exactly sure what this means. I could write it out: In[119]:= Solve[w1+w2+w3+w4+w5==0, w1] Out[119]= {{w1 -> -w2 - w3 - w4 - w5}} But this isn't very helpful in my situation (my equations are huge*), and > doesn't reflect the vector quality of the situation. If such a thing is possible, I'd appreciate some pointers (I read the > mathematica docs on the wolfram site, but couldn't find anything talking > about this). > - Hal * the equation i'm working with is something like: sum_{C,x,y,y'} (wx . wy) (wx . wy') (|wx * wy'| (wx . wy) - |wx * wy| (wx > . wy')) / (|wx|^4 |wy|^2 |wy'|^2) == 0 where . is dot product > * is cross product > |x| is magnitude of x > and > for vectors w=, x=, > wx = Hal Daume III Computer science is no more about computers | hdaume@isi.edu > than astronomy is about telescopes. -Dijkstra | www.isi.edu/~hdaume ==== I have two stochastic processes defined as dI = a*(mu1(t)-Ln(I))+sigma1*dZ1 dP=b*(mu2(t)-Ln(P))+sigma2*dZ2 where mu1(t) denotes a deterministic function of time, a and b are constants, sigma1 and sigma2 denotes two constant standard deviations and dZ1 and dZ2 are two brownian motions. Thus, I have two mean-reverting processes of the Ln-values of two variables. The problem is that I want to multiply the two processes (one is a volume process, the other a price process) and compute the stochastic derivative of the resulting expression. I got the ItosLemma notebook off the web, but cannot figure out how (if) this can be done. Anyone ? Cheers, Narve ==== Here's a more direct method: Position[DownValues[a], HoldPattern[a[#]]] != {} & /@ {1, 2} {True,False} This is what I'd have expected ValueQ to do, if I hadn't seen the examples and read the fine print. Bobby -----Original Message----- > I#m searching for a simple workaround of the following behaviour. > > For the symbol 'a' I've defined > > In[1]:= > a[1] = 2; > > When I evaluate ValueQ for a defined and for not a defined expression I > get what I expect: > > In[3]:= > ValueQ[a[1]] > Out[3]= > True > > In[4]:= > ValueQ[a[2]] > Out[4]= > False > > But when I evaluate ValueQ e. g. within a Table I always get True: > > In[5]:= > Table[ValueQ[a[i]], {i, 1, 2}] > Out[5]= > {True, True} > > The 2nd 'True' is because 'a[i]' is not equal to 'a[2]'. A first > solution to get the expected result is > > In[6]:= > Table[ToExpression@(ValueQ[a[ <> ToString[i] <> ]]), {i, 1, 2}] > Out[6]= > {True, False} > > Does anybody know something better? > > Rainer Gruber > JOHANNES KEPLER UNIVERSITY LINZ > Institute of Experimental Physics > Atomic Physics and Surface Science ==== Steve, What notebook style are you using? It sounds like you are using one that centers text. For people who are relatively new to Mathematica my personal recommendation is to stay with the Default style until they are reasonably familiar with Mathematica. Style notebooks are a whole little subject on to themselves. Otherwise, you can modify style notebooks, and save them under new names, to give you the behavior you want. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ > When I'm typing into a Text cell, Mathematica will randomly insert > newlines before I'm anywhere near the right edge. This > usually screws up the format I am trying to use. Normal > editing steps do not fix this. How do I prevent these > undesired Enters or remove them? ====