D-115 === Subject: Re: Machine-precision Exp[] function answering my own question: MachinePrecisionExp = Compile[{{x, _Complex}}, Exp[x]] Any thoughts on this? Roman. === Subject: Re: Machine-precision Exp[] function It is what I would have suggested to look at. You need to decide whether that is a good solution for your case anyway. Some things to consider: - With _Complex you will get spurios imaginary parts in the results which may or may not cause problems or slowdowns later. - Maybe there are larger parts of formulas that you want to compile, probably even whole parts of your code. You should consider that if you are after very fast code. Since unfortunatly Compiles aren't efficient when beeing nested (they cause callbacks to the evaluator), you should try to Compile as large junks of code as managable. hth, albert === Subject: Re: Plot descending x- Values You could label the axes yourself like this: maxX = 10; minX = 0; fun[x_] := x + 2; Plot[fun[maxX - x], {x, minX, maxX}, === Subject: Re: DSolve and assuming: wrong solution found by Mathematica 6. A \ bug I'm not sure about this, but I don't think DSolve uses assumptions. The manual has the following about DSolve and symbolic parameters (tutorial/DSolveSymbolicAndInexactQuantities): In summary, the ability to solve differential equations with symbolic parameters is a powerful and essential feature of any symbolic solver such as DSolve. However, the following points should be noted. - The solution might be complicated, and such calculations often require significant time and memory. - The answer might not be valid for certain exceptional values of the parameters. - The solution might be easy to verify symbolically for some special values of the parameters, but in the general case a numerical verification method is preferable. === Subject: Re: Basic programming First we extract some financial data and get the minimum and maximum \ values: djidata = Part[#, 2] & /@ FinancialData[\^DJI\, {\Jun. 26, 2008\, \Nov. 14, 2008\}]; {Min[djidata], Max[djidata]} {8175.77,11782.4} Next we calculate the 10 day trailing standard deviation: dji10daystd = StandardDeviation /@ Partition[djidata, 10, 1]; {Min[dji10daystd], Max[dji10daystd]} {95.562,878.838} Finally we calculate the cumulative standard deviation: djicumstd = Table[StandardDeviation[Take[djidata, {1, i}]], {i, 2, 100}]; {Min[djicumstd], Max[djicumstd]} {49.5963,1134.97} Then I use the Presentations package to plot these all in one plot with a special scale for the standard deviation curves on the right. Needs[\Presentations`Master`\] Draw2D[ {ListDraw[djidata], Red, ListDraw[Rescale[#, {0, 1200}, {8000, 12000}] & /@ dji10daystd, ListDraw[Rescale[#, {0, 1200}, {8000, 12000}] & /@ djicumstd, Black, Text[\10 Day\, {82, 9500}, {-1, 0}], Text[\Cumulative\, {86, 11000}, {-1, 0}]}, CustomTicks[ Rescale[#, {0, 1200}, {8000, 12000}] &, {0, 1200, 200, 5}, Automatic}}, None}}, Peter Lindsay at the Mathematical Institute in the University of St Andrews [ www.mcs.st-and.ac.uk ] has kindly undertaken to maintain an archive that provides downloadable notebooks and PDF files for various Presentations solutions that have appeared on MathGroup. http://blackbook.mcs.st-and.ac.uk/~Peter/djmpark/html/ David Park djmpark@comcast.net http://home.comcast.net/~djmpark Hey I'm a beginner in mathematica and I'm trying to code a little something but can't seem to be able to make it work... I know its pretty basic and that's exactly my problem since the mathematica help is a bit overkill for what I need. I have daily stock prices for a stock on a 100 day period, I want to \ compute the standard deviation for a rolling 10 days period for the whole list of data. So basically, I would like to do something like this : stdev(1;;10) then stdev(2;;11) until stdev(91;;100) and get the results in a list Id also like to get it another way, by starting with only one observation and building my standard deviation calculation until I have my whole \ rolling period built up, for example : stdev(1) stdev(1,2) stdev(1,2,3) until stdev(1;;10) then same as before, roll the period until the end of dataset and produce a list of the results. try to explain it in more details! === Subject: Re: Basic programming If I understand what you want correctly, then StandardDeviation/@Partition[data, 10, 1] will create the list you want Partition with the syntax above creates sublists of length 10 with offsets of 1 for the starting element of each sublist. The rest simply maps StandardDeviation to each sublist to create a list of standard deviations === Subject: Re: Fourier Transform my 2 cents on this good question is the following: Using FourierTransform and using the equivlant integeration command is not always the same. ------------------- In[6]:= func = Cos[w0 t]; Integrate[func* Exp[(-I)*w*t], {t, -Infinity, Infinity}] Integrate::idiv: Integral of E^(-I t w) Cos[t w0] does not converge on {-\\[Infinity],\\[Infinity]}. FourierTransform[func, t, w] Sqrt[Pi/2] DiracDelta[w-w0]+Sqrt[Pi/2] DiracDelta[w+w0] ------------------------ Cos[] is not square integrable (its average power is not zero, the average power of cos[] is 1/2) So, Cos[] does not have a FourierTransform (one of the conditions to have FourierTransform is for the function to be square integrable). So, for non-square integrable functions, FourierTransform does not exist. Yet, you see that FourierTransform does generate a FourierTransform for the \ Cos[]. Since there are many useful functions which have infinite energy, but we want to find its fourier transform, a more generalized definition is used for the integral which uses a dirac delta function to allow one to integrate \ such functions, and that is why sometimes FourierTransform gives different answer than direct use of the Intgeration function. reference Delta Functions: An Introduction to Generalised Functions by R. F. Hoskins Nasser === Subject: Creating a Banner for presentation I'm trying to make a powerpoint like presentation using Mathematica 6, but \ i can't find any explaination in documentation on how to create banners for my presentation. Nice example can be found at: http://library.wolfram.com/infocenter/Conferences/7002/. jetro === Subject: Re: Creating a Banner for presentation Just a small (but important) update to my previous post on this. here is a more useful template for how to go about this since it includes the slide navigation elements: SetOptions[EvaluationNotebook[], \SlideshowToolbar\], Best, David t i com/infocenter/Conferences/7002/. === Subject: Re: Creating a Banner for presentation In the notebook in question execute something like Banner\,\Title\]}] You will, of course have to design the DockedCell to your liking... Hope this helps, David A WorkLife FrameWork: Extending Mathematica's Reach http://scientificArts.com/worklife t i com/infocenter/Conferences/7002/. === Subject: Re: Basic programming Use Partition to form the rolling windows. For example data1 = {a, b, c, d, e, f, g}; Partition[data1, 3, 1] {{a, b, c}, {b, c, d}, {c, d, e}, {d, e, f}, {e, f, g}} Then map StandardDeviation onto the resulting windows data2 = 100 + RandomReal[{0, 10}, {100}]; stdDev2 = StandardDeviation /@ Partition[data2, 10, 1]; The argument to StandardDeviation must have at least two elements data3 = {a, b, c, d} {a,b,c,d} FoldList[Append, Take[data3, 2], Drop[data3, 2]] {{a,b},{a,b,c},{a,b,c,d}} stdDev = Map[StandardDeviation, FoldList[Append, Take[#, 2], Drop[#, 2]] & /@ Partition[data2, 10, 1], {2}]; stdDev[[All, 9]] == stdDev2 True ListLinePlot[stdDev2] ListLinePlot[Flatten[stdDev, 1], Point[Thread[{Range[9, 9*Length[stdDev2], 9], stdDev2}]]}, Bob Hanlon Hey I'm a beginner in mathematica and I'm trying to code a little something \ but can't seem to be able to make it work... I know its pretty basic and \ that's exactly my problem since the mathematica help is a bit overkill for \ what I need. I have daily stock prices for a stock on a 100 day period, I want to compute \ the standard deviation for a rolling 10 days period for the whole list of \ data. So basically, I would like to do something like this : stdev(1;;10) then stdev(2;;11) until stdev(91;;100) and get the results in a list Id also like to get it another way, by starting with only one observation \ and building my standard deviation calculation until I have my whole rolling \ period built up, for example : stdev(1) stdev(1,2) stdev(1,2,3) until stdev(1;;10) then same as before, roll the period until the end of dataset and produce a \ list of the results. -- Bob Hanlon === Subject: Re: Basic programming As always, there will be a multitude of possible solutions. A functional programming style solution would be: Map[ StandardDeviation, Partition[yourData, 10, 1] ] or, in a more procedural or imperative programming style: Table[ StandardDeviation[ Take[yourData, {i, i + 9}] ], {i, 1, Length[yourData] - 9} ] or even more procedural (and ugly): result = {}; Do[ b = StandardDeviation[ yourData[[i ;; i + 9]] ]; result = Append[result, b];, {i, 1, Length[yourData] - 9} ] result yourData should be an array with your data set, e.g. yourData={2.2, 3.7, -1.3, 4.5, 9.0, 2.2, 2.4, 5.6, 9.8, 12.3,3.8} ; With respect to your second question: are you sure you want to calculate the standard deviation of a single data point? Doesn't make much sense to me. Anyway, to do this, the first example can be modified thus: Map[ StandardDeviation, Partition[yourData, 10, 1, {-1, 1}, {}] ] The others are easy to modify as well, but will become even more ugly in the process. ng but can't seem to be able to make it work... I know its pretty basic \ and= that's exactly my problem since the mathematica help is a bit overkill \ for= what I need. ute the standard deviation for a rolling 10 days period for the whole list \ = of data. and building my standard deviation calculation until I have my whole \ rolli= ng period built up, for example : a list of the results. try to explain it in more details! === Subject: Re: Basic programming Here's a bit of data: data = RandomReal[{0, 1}, 100]; Here's the moving standard deviation, 10 elements at a time: StandardDeviation /@ Partition[data, 10, 1] (results omitted) and here's the StandardDeviation applied to 1,2, .... ,100 elements: Clear[stdev] stdev[dat_List][n_] /; n < 2 = 0; stdev[dat_List][n_] /; n <= Length@dat := StandardDeviation@Take[dat, n] Array[stdev[data], 100] (results omitted) Bobby -- DrMajorBob@longhorns.com === Subject: Re: Basic programming I'm betting that you'll get many useful answers. Here's one solution that I hope will help you. One starting point to give you the rolling std. deviation is to create a function that outputs three values: {the location of the 1st element used to calculate the std. dev., the location of the last element used to calculate the std. dev., the std. dev.} lst = {1,20,3,40,5,60,7,80,9,100,11,120,5,7,90}; (* You might want to look up SetPrecision in the Documentation Center *) out[i_]:={i,i+9,SetPrecision[StandardDeviation[lst[[i;;i+9]]],4]} Then, evaluate the function for several ranges of elements in your list. out[1] {1,10,35.90} out[2] {2,11,35.06} out[3] {3,12,43.92} Now that you see how it works, here's the concise method: Table[out[i],{i,1,6}] {{1,10,35.90},{2,11,35.06},{3,12,43.92},{4,13,43.72},{5,14,45.25},{6,15,45.8\ 4}} HTH, Richard Hofler ________________________________ === Subject: Basic programming Hey I'm a beginner in mathematica and I'm trying to code a little something but can't seem to be able to make it work... I know its pretty basic and that's exactly my problem since the mathematica help is a bit overkill for what I need. I have daily stock prices for a stock on a 100 day period, I want to compute the standard deviation for a rolling 10 days period for the whole list of data. So basically, I would like to do something like this : stdev(1;;10) then stdev(2;;11) until stdev(91;;100) and get the results in a list Id also like to get it another way, by starting with only one observation and building my standard deviation calculation until I have my whole rolling period built up, for example : stdev(1) stdev(1,2) stdev(1,2,3) until stdev(1;;10) then same as before, roll the period until the end of dataset and produce a list of the results. Ill try to explain it in more details! === Subject: Re: Basic programming list=RandomReal[1, {100}]; StandardDeviation /@ Partition[list, 10, 1] should do this. StandardDeviation /@ Partition[list, 10, 1, {-2, -1}, {}] should do this. Note that the above starts with a standard deviation of the first 2 elements, and not of just the first element, since the standard deviation of a single element list is not defined. Carl Woll Wolfram Research === Subject: Re: Complement ... Hi Ignacio, I've checked a few of the 10 numbers and it seems that they the line they're on has a space character at the end in myList_1.txt and no space in myList_2.txt. Hence, the strings are really different (but not visually!), and Mathematica is therefore right. iles/163412702/myData.zip.html === Subject: Re: Visulizing the content of a variable It works for me... Perhaps you should post your code straight from mathematica. There appears to be a problem with line breaks. === It seems to depend on which string format you choose. Definitely a bug. You should send a bug report to the Wolfram support guys. === Subject: Re: Gluing file together Hi Giacomo, The first thing to ask your self is why you're appending each iteration. str=OpenAppend[\out.txt\]; For[ file=1, file<=fileNUmber, file++, tmp=Import[fileList[[file]],\xxx\]; Write[str,tmp]; ] Close[str]; is probably more like what you're after. Dave. === Subject: Gluing file together Hello !! I have some text file to glue together; I have been experimenting with following code (where xxx is for Lines, Text, Binary ...,) for a lot of time but it each and every time it mess up the output file (splitting lines and adding unwanted characters). Please, can you explain the reason why ? SetDirectory[NotebookDirectory[]] fileList=FileNames[\*.txt\]; fileNumber=Length[fileList]; For[ file=1, file<=fileNUmber, file++, tmp=Import[fileList[[file]],\xxx\]; str=OpenAppend[\out.txt\]; Write[str,tmp]; Close[str]; ] Giacomo De Gerolamo (Italy) === Subject: Re: Gluing file together and Export[\c:/temp/out.txt\, StringJoin @@ (Import[#, \Text\] & /@ FileNames[\*.txt\, {\c:\\\\MyTextFiles\}]), \Text\] ?? Sorry I dropped your nice For[] loop ;-) BTW what does the cat command ?? Jens === Subject: List of Month Names Is there a short Mathematica command to obtain a list of month names or short month names in order, without having to type them all in by hand? And same question for days of the week. David Park djmpark@comcast.net === Subject: Re: LatticeReduce The equations are homogeneous, so I should have used NullSpace instead of LinearSolve. The idea is you can obtain a generating set of solutions to the linear homogeneous equation simply by finding the null space generators. If any are fractional (they are not, but I want to cover all possibilities) then you would need to clear denominators to get integral solutions. {a0, a1, a2} = {1, 2^15, -3^8}; In[50]:= NullSpace[{{a0, a1, a2}}] Out[50]= {{6561, 0, 1}, {-32768, 1, 0}} In[53]:= {a1, a2, a3} = {1, 3^4, 5^4}; NullSpace[{{a1, a2, a3}}] Out[54]= {{-625, 0, 1}, {-81, 1, 0}} Again, whether these are useful (thay are, admittedly, fairly \obvious\ solutions) depends on what you want to do. If you want small solutions you might be beter off with the methods indicated in my prior response. Daniel Lichtblau Wolfram Research === Subject: Re: LatticeReduce ExtendedGCD and HermiteDecomposition. What do you mean LinearSolve ? Could you give me one equation exercise (related to my) and solvng them by LinearSolve? Best wishes Artur danl@wolfram.com pisze: === Subject: Re: LatticeReduce You are misunderstanding what lattice reduction means. It has no underlying understanding of any equations to solve, it simply reduces lattices. As far as I can tell, it is doing just that in your examples. If you want to get solutions to your equations, there are various approaches. One is to use Reduce or FindInstance (you will need restrictions to avoid the zero solution for that latter, since the equation is homogeneous). You might use Minimize, imposing an objective function, as below. {a0, a1, a2} = {1, 2^15, -3^8}; (Or just minimize x, maybe.) If you seek reasonably small solutions, you might use LatticeReduce as follows. Weight your lattice in such a way as to push the last column coordinates toward zero, in the hope of getting solutions. Here is an example. {a1, a2, a3} = 10*{1, 3^4, 5^4}; a = {{1, 0, 0, -a1}, {0, 1, 0, -a2}, {0, 0, 1, -a3}}; b = LatticeReduce[a] {{1, 0, 0, -10}, {23, -8, 1, 0}, {-12, -23, 3, 0}} Now you see those \small\ solutions that generate the full solution set. There are other approaches, using ExtendedGCD, HermiteDecomposition, or LinearSolve. Which are desireable would depend on what specifically you seek (generating set? small solutions?...). Daniel Lichtblau Wolfram Research === Subject: LatticeReduce I want to find such inetegrs x,y,z that x + y*2^15 + z*3^8 = 0 I'm reading in manual that I can use LatticeReduce {a0, a1, a2} = {1, 2^15, -3^8}; a = {{1, 0, 0, -a0}, {0, 1, 0, -a1}, {0, 0, 1, -a2}}; b = LatticeReduce[a] Out1:{{1, 0, 0, -1}, {18, 1, 5, 19}, {117, -171, -854, 117}} That mean that computer don't find such solution (solution is finded when last number in one of rows should be 0) If I run again: {a0, a1, a2} = {37, 2^15, -3^8}; a = {{1, 0, 0, -a0}, {0, 1, 0, -a1}, {0, 0, 1, -a2}}; b = LatticeReduce[a] Out2:{{1, 1, 5, 0}, {1, 0, 0, -37}, {170, -7, -34, 12}} Now solution is finded by Mathematica OK! k = Transpose[{{37, 2^15, -3^8, anything}}]; b[[1]].k Out3: {0} Is OK! Is another method finding coefficients x, y, z as LatticeReduce and why Mathematica don't reduced {a0, a1, a2} = {1, 2^15, -3^8}; a = {{1, 0, 0, -a0}, {0, 1, 0, -a1}, {0, 0, 1, -a2}}; b = LatticeReduce[a] Best wishes Artur === Subject: Re: LatticeReduce P.S. And for the case: {a1, a2, a3} = {1, 3^4, 5^4}; a = {{1, 0, 0, -a1}, {0, 1, 0, -a2}, {0, 0, 1, -a3}}; b = LatticeReduce[a] Out1:*{{1, 0, 0, -1}, {12, -8, 1, 11}, {-6, -23, 3, -6}} Mathematica should be return 2 solutions: 23 - 8*3^4 + 5^4=0 12 + 23*3^4 - 3*5^4=0 **After good LatticeReduce should begin from : {{23,-8,1,0}, {12, 23,-3,0}, {c, c1,c2, c3}} What is wrong in LatticeReduce or what I'm doing wrong ? Artur * Artur pisze: === Subject: Re: Gluing file together The only reason I can see to use a loop such as the above is when the memory you have installed on your machine is not adequate to read all of the data in from all of the files. Assuming sufficient memory, I would do the following: Export[\out.txt\,Join@@(ReadList[#,String]&/@FileNames@\*txt\),\Lines\\ ] I suspect the difficulty you are having is related to what happens to newline characters when doing the Write operation. Per the documentation Write[channel, expr1, expr2, ...] appends a newline character after every expression. Your variable tmp will be a single expression and probably gets a single newline after it when written. The other newline characters are consumed by the Import operation. If I have identified the problem correctly, changing Write[str, tmp] to Write[str, Sequence@@tmp] should make your code do what you want. === Subject: Re: Machine-precision Expfunction Your original post seemed to start with a number specified to have lower precision than machine precision. All you are doing above is converting the number to machine precision. That is the result you get with your function above should be exactly the equivalent of Exp[x//N] There is an obvious problem with converting a low precision number to a high precision number. The value of the bits added to make the low precision a higher precision number is not well defined. But if the end goal is to obtain a machine precision number, why specify the original number to be other than machine precision in the first place? === Subject: Working with vectors symbolically I need a CAS for working with vectors symbolically. I am accustomed to using Mathematica for my symbolic math work, but it seems that Mathematica is not up for the task. So I am hoping that you can either show me how to do it in Mathematica, or refer me to some other CAS that can handle this. [Do this my email to the author - moderator] What I do are equations relating to electromagnetic fields. I have long equations which are filled with scalar products and cross products of vectors. Right now I have to simplify these equations by hand. I want to be able to simplify them automatically... Also taking limits. Mathematica has trouble taking limits on equations involving vectors. So anyone has any advice to offer? Ram Rachum. === Subject: Complement ... Hi !! (running Mathematica 6.0.0 on an Itel - XP Pro PC) I have two data file myList_1.txt myList_2.txt both having a string on each line. To get strings present in myList_2.txt but not in myList_1.txt I try this SetDirectory[NotebookDirectory[]]; myList1 = Import[\myList_1.txt\, \Lines\]; myList2 = Import[\myList_2.txt\, \Lines\]; comp = Complement[myList2, myList1]; comp // TableForm and something strange happens, because it returns comp as a list of 10 elements. That's impossibile, because myList_2.txt is a subset of myList_1.txt ( I did it to check the metod ). Moreover using a text editor I find the 10 strings clearly present in myList1.txt I am not capable to figure out any reason for that. Do you ? ------------------------------------------------ If you want test it on my data, I have placed myList_1.txt myList_2.txt in 4.2 Mb sized zip file ( myData.zip ) at the url http://rapidshare.com/files/163412702/myData.zip.html They are two simple plain text file no way harmful. ------------------------------------------------ Ignacio === Subject: Re: Analyzing sequences of fractions in Mathematica It can probably be simplified somewhat but here is one form of it: seq[n_] := With[{ a = 1/2 (-1 + Sqrt[17]), b = 1/2 (1 + Sqrt[17]), c = Sqrt[1/17 (-4 + Sqrt[17])], d = Sqrt[1/17 (4 + Sqrt[17])] }, 2^(-n - 2) Piecewise[{ {2^n - a^(n/2)/Sqrt[17] + (I^n b^(n/2))/Sqrt[17], Mod[n, 2] == 0}, {2^n + c a^(n/2) + I^(n + 1) d b^(n/2), Mod[n, 2] == 1} }]] Table[seq[n], {n, 27}] // FullSimplify {1/8, 3/16, 11/32, 17/64, 25/128, 59/256, 147/512, 265/1024, \\ 465/2048, 995/4096, 2171/8192, 4161/16384, 7881/32768, 16203/65536, \\ 33571/131072, 65977/262144, 129025/524288, 260979/1048576, \\ 529547/2097152, 1051505/4194304, 2083705/8388608, 4186715/16777216, \\ 8423091/33554432, 16796521/67108864, 33466161/134217728, \\ 67059203/268435456, 134443931/536870912} % == mysequence True -Eric === Subject: right hand side Hello Everyone! I suppose that my question can be very easy. I will translate it on simple equation, aa = 2*x + 5*y == 1, I need to plot this equation so i take Reduce [aa,y], the result is following y == 1/5 - (2 x)/5. Now I would like to take right side of equation to plot 1/5-(2x)/5. However I do not know how to do it. Magdalena === Subject: Re: right hand side aa = 2 x + 5 y == 1; rightside = Reduce[aa, y][[2]] Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: right hand side Copy into a notebook and evaluate: aa = 2 x + 5 y == 1; ContourPlot[Evaluate[aa], {x, -5, 5}, {y, -5, 5}, An alternative method: Print[\My equation\] aa Print[\Solve the equation for y\] Solve[aa, y] Print[\Extract the solution rule\] Part[%%, 1, 1] Print[\Define a plotting function f[x]\] f[x_] = y /. %% Now plot f[x]. Plot[f[x], {x, -5, 5}, David Park djmpark@comcast.net http://home.comcast.net/~djmpark Hello Everyone! I suppose that my question can be very easy. I will translate it on simple equation, aa = 2*x + 5*y == 1, I need to plot this equation so i take Reduce [aa,y], the result is following y == 1/5 - (2 x)/5. Now I would like to take right side of equation to plot 1/5-(2x)/5. However I do not know how to do it. Magdalena === Subject: Re: right hand side aa = 2*x + 5*y == 1; expr = y /. Solve[aa, y][[1]] Plot[expr, {x, -2, 2}] ?? Jens === Subject: Re: DensityPlot + LogarithmicScale Hi Krazik, What have you tried? What do you mean by Log? Log of the data? Just plot Log[10, data]. Log of ranges? You're in Ticks[] land. Posting an example will almost certainly get more specific answers. Dave. === Subject: Re: How to export a lot of different plots? I don't know are there any me. know how to convert the index to string. And the method you provided works perfectly for me:) Best, Yiping === Subject: Re: How to export a lot of different plots? Hi Yiping, Did you try ( Print[plt = Plot[]]; out = StringJoin[\plot_\, ToString@#, \.jpg\]; Export[out, plt] )& /@ Range@Length@stuff? And PNG's might be better for your purpose than JPG, esp. if you're importing them to PPT. Dave. === Subject: Re: How to export a lot of different plots? If your loop index is i, try Adding 1000 (or even something bigger) to the index prevents the operating system and other apps from reordering your files by putting, say, \filename12.jpg\ before \filename2.jpg\. --Lou Talman Department of Mathematical & Computer Sciences Metropolitan State College of Denver === Subject: Re: Storing and Loading Definitions / Emulating Associative Arrays In case someone else is interested, here are the two functions that I now use for saving and loading of definitions: (* Save and load function definitions *) SaveDefinition[fn_, file_] := (Put[{Function @@ {{fn}, DownValues[Evaluate[fn]]}, Function @@ {{fn}, UpValues[Evaluate[fn]]}}, file];) LoadDefinition[fn_, file_] := Module[{data}, data = Get[file]; Clear[fn]; DownValues[fn] = data[[1]][fn]; UpValues[fn] = data[[2]][fn]; ]; SetAttributes[LoadDefinition, HoldFirst]; LoadDefinition /: Set[f_, LoadDefinition[file_]] := LoadDefinition[f, file] They also save the UpValues and allow a nice syntax: SaveDefinition[data, \file.dat\] newdata = LoadDefinition[\file.dat\] Best, -Nikolaus -- =C2=BBIt is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.=C2=AB -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C === Subject: Re: Storing and Loading Definitions / Emulating Associative Arrays I am not sure this is the most elegant method to achieve this, but suppose you have a function f that you want to save away: In[215]:= f[a_]:=g[a]; f[3]=42; Now suppose you use DumpSave to save tempstuff (tempstuff and tempfun can be private variables in a package when you want to make this really robust). Restoring tempstuff later, the function definition can be transfered to a symbol h thus: In[7]:= ?h Global`h h[3]:=42 h[a_]:=g[a] David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Storing and Loading Definitions / Emulating Associative Arrays have come up with that tricky code anytime soon. Best, -Nikolaus -- =C2=BBIt is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.=C2=AB -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C === Subject: Re: Fourier Transform -\\ orm Of course. But I made sure that my integral is exactly equal to the one used by InverseFourierTransform (according to the Mathematica Help), so this cannot be the reason. But what is the point of that? There is nothing special about the integral in a Fourier transform, so any functionality that helps to evaluate integrals is best added to Integrate[]. -Nikolaus -- =C2=BBIt is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.=C2=AB -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C === Subject: seperate complex number hi all do anyone how to separate the following complex number into real part and imaginary part? 1/2 (Kab + Kba + R2a + R2b - \\[ImaginaryI] \\[CapitalOmega]a - \\[ImaginaryI] \\ \\[CapitalOmega]b + Sqrt[(-Kab - Kba - R2a - R2b + \\[ImaginaryI] \\[CapitalOmega]a + \\[ImaginaryI] \\ \\[CapitalOmega]b)^2 - 4 (Kba R2a + Kab R2b + R2a R2b - \\[ImaginaryI] Kba \\[CapitalOmega]a - \\[ImaginaryI] \\ R2b \\[CapitalOmega]a - \\[ImaginaryI] Kab \\[CapitalOmega]b - \\ \\[ImaginaryI] R2a \\[CapitalOmega]b - \\[CapitalOmega]a \\ \\[CapitalOmega]b)]) === Subject: specify a color for ErrorBar and remove the point in the middle hello, i'd like to specify a color (say Red) for the error bars below, and remove the point in the middle. ErrorListPlot[{{1, 1, 0.2}, {2, 2, 0.2}, {3, 2, 0.2}}] or MultipleListPlot[{{1.0, ErrorBar[0.1]}, {2.0, ErrorBar[0.1]}, {2.0, ErrorBar[0.1]}}] any suggestion appreciated. === Subject: How to export values of an expression as data file? I am new to Mathematica. I am looking for a way to export the values of an evaluated expression (which I can plot in Mathematica successfully) in the form of an ASCII data file. The output should be a two column (X, Y) data, which I can plot later using Xmgrace. The expression is actually an evaluation of the solution of a system of equations within certain range, say {x, 0, 10}. Now the discrete numerical values at certain intervals, say every 0.1 should be exported as the data file as a function of x. Please help. Suman Chakrabarty. === Subject: Re: How to export values of an expression as data file? data = Table[RandomReal[], {10}, {2}]; Export[\c:/temp/test.txt\, data, \Table\] ?? Jens === Subject: Re: Model the surface of an ellipsoid books/Surfaces/Ellipsoid.nb Hi Jens, first ;-) I already download the notebook long ago. I did not understand anything from that it seems to be too much of mathematics to me. In my case i have only 4 unknown parameters ( 1 = Sqrt[r^2/R^2 + d^2/ D^2] ). Typically, also shown in the \ websitehttp://mathworld.wolfram.com/El= lipsoid.html, for a ellipsoidal there must at least three coordinates. But the equation which is i have seems to be different. please tell me if am wrong. Please understand i am using mathematica 5.2. I used an ImplicitPlot like this i get only 2D plot. ImplicitPlot[Sqrt[(x^2/9) + (y^2/4)] == 1, {x, -3, 3}] My question is for 3D it is more complicated? do i need to use much of trigonometry for the angles? May === Subject: Re: Model the surface of an ellipsoid after simple algebra you end up with R^2 == r^2 + R^2*d^2/D^2 and since you have 4 variables, you can fix one of the variables With[{D = 1}, ContourPlot3D[ R^2 == r^2 + R^2*d^2/D^2, {r, -2, 2}, {R, -2, 2}, {d, -2, 2}]] or make an interactive version. Manipulate[ ContourPlot3D[ R^2 == r^2 + R^2*d^2/D^2, {r, -2, 2}, {R, -2, 2}, {d, -2, 2}], {D, -2, 2}] Jens === Subject: prolate spheroidal coordinates - alternative form Hi The 'vector analysis' package lets you change the working coordinate system \ to many alternatives. I want to use prolate spheroidal coordinates to solve a \ two-centre quantum problem. These are described in the Mathworld sheet (which \ has exactly what I want to use) \ http://mathworld.wolfram.com/ProlateSpheroidalCoordinates.html However, SetCoordinates[prolateSpheroidal], produces the standard form given \ in eqns 1-8 in the sheet. I want the form described in eqns 9-21. \ Unfortunately I cannot find how to get SetCoordinates to produce the \ alternative form. Any help gratefully received - Peter === Subject: Re: How do little quickest 8 Gig, on that particular machine. Linux (some Gnome version). Mathematica version not-yet-released. I don't think Mathematica really was improved for 64 bit machines until around version 5.2. Expanded memory for 64 bit addressing spaces remains something of a work in progress for the Mathematica kernel (and progress is being made). I should note that my code handles n=30, but punks out beyond that. That full sieving approach is really a memory hog. I have some ideas for how to improve and might try to code them, time permitting. Daniel === Subject: Re: How do little quickest How much VM do you have? What operating system are you using, and what version of Mathematica? On my 64 bit machine I get: In[1]:= $Version In[2]:= minprods2 = Compile[{{n,_Integer}}, Module[ {fx, len=2^(n-1), pr=3, start=2, logpr, n2, parts, min=100.}, fx = Table[0.,{len}]; While[start<=len, logpr = Log[N[pr]]; Do [fx[[j]] += logpr, {j,start,len,pr}]; While[start<=len && fx[[start]]!=0., start++]; pr = 2*start-1; ]; Round[2*Exp[Table[ n2 = 2^(j-1); min = 100.; Do[min = Min[min,fx[[k]]+fx[[2*n2-k+1]]], {k,n2}]; min , {j,n-1}]]] ]] In[3]:= Timing[minprods2[29]] No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. Scott -- Scott Hemphill hemphill@alumni.caltech.edu \This isn't flying. This is falling, with style.\ -- Buzz Lightyear === Subject: Re: How to export values of an expression as data file? On 11/13/08 at 9:09 PM, chakrabarty.suman@gmail.com (Suman Use Export. It supports most common formats. For example, for a two column ASCII file with tab characters separating the columns do Export[filename, data, \TSV\] === Subject: Re: Stacked Definitions temp[42][3] = 7 SubValues[temp] David Park djmpark@comcast.net http://home.comcast.net/~djmpark If I make a definition of the form temp[42][3] = 7 where is this rule stored? I would have expected it to be in DownValues[temp] or DownValues[temp[42]], but the first list is empty and the second gives a syntax error. Best, -Nikolaus -- =C2=BBIt is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.=C2=AB -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C === Subject: Stacked Definitions If I make a definition of the form temp[42][3] = 7 where is this rule stored? I would have expected it to be in DownValues[temp] or DownValues[temp[42]], but the first list is empty and the second gives a syntax error. Best, -Nikolaus -- =C2=BBIt is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.=C2=AB -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C === Subject: Re: Stacked Definitions It's in SubValues[temp] Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Stacked Definitions looks like a logic followup to your last post :-) The definition is here: SubValues[temp] I just realized that SubValues misses an own homepage in the documentation, but the good old ?SubValues still works... hth, albert === Subject: Re: Stacked Definitions temp[42][3] = 7; SubValues[temp] ?? Jens === Subject: Minimize What Mathematica procedure to use to minimize expotential finction e.g. Minimize[Abs[3^d + 5^f - 2^7], {d, f}] where we can push: d and f are both Integers NMinimize[Abs[3^d + 5^f - 2^7], {d, f}] Mathematica answer is: good answer is: {d,f}={1,3} Best wishes Artur === Subject: Re: specify a color for ErrorBar and remove the point in Needs[\ErrorBarPlots`\] ErrorListPlot[ {{1, 1, 0.2}, {2, 2, 0.2}, {3, 2, 0.2}}, Bob Hanlon hello, i'd like to specify a color (say Red) for the error bars below, and remove the point in the middle. ErrorListPlot[{{1, 1, 0.2}, {2, 2, 0.2}, {3, 2, 0.2}}] or MultipleListPlot[{{1.0, ErrorBar[0.1]}, {2.0, ErrorBar[0.1]}, {2.0, ErrorBar[0.1]}}] any suggestion appreciated. -- Bob Hanlon === Subject: Re: Stacked Definitions temp[42][3] = 7 7 Names[\*Values*\] {DefaultValues,DownValues,DynamicModuleValues,FormatValues,NValues,\\ OwnValues,SingularValues,SubValues,UpValues,ValuesData} SubValues[temp] Bob Hanlon If I make a definition of the form temp[42][3] = 7 where is this rule stored? I would have expected it to be in DownValues[temp] or DownValues[temp[42]], but the first list is empty and the second gives a syntax error. Best, -Nikolaus -- =C2=BBIt is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.=C2=AB -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- Bob Hanlon === Subject: Re: Unacceptable bug in Mathematica But it does give a \valid expression\. v = ToExpression[\Exp[]\] Exp called with 0 arguments; 1 argument is expected. Exp[] True, you get a warning message, but after evaluation you have a valid expression v, and you can use it to build further valid expressions: In[4]:= f = Head[v] Out[4]= Exp In[5]:= f[1] Out[5]= E It's all perfectly valid. Andrzej Kozlowski === Subject: Re: Unacceptable bug in Mathematica There is no room for ambiguity in this sort of thing. Either it is syntactically well formed, or it is not. This one is, in the sense of Mathematica syntax. Just like the variant below. In[1]:= SyntaxQ[\exp[]\] Out[1]= True Maybe you have in mind that Exp, being a built in \function\ (that is, a symbol with DownValues attached to it), should require an \argument\. Well and good, but that's progamming language semantics, not syntax. On a side note, related to another recent post...if you type Exp[] in a version 6 front end, you will see a red arrow between the brackets, indicating that there seems to be something \missing\. So what we refer to as \syntax highlighting\ really knows a bit of the language semantics (and goes well beyond just lexical analysis). Daniel Lichtblau Wolfram Research === Subject: Re: Unacceptable bug in Mathematica This absolutely is valid syntax. Valid syntax is anything that will successfully parse into an unevaluated Mathematica expression. Once it is evaluated it may or may not produce a useful result, but that does not mean it isn't syntactically valid. Consider the following: In[1]:= f[] Out[1]= f[] In[2]:= SyntaxQ[\f[]\] Out[2]= True In[3]:= f[] := 1; In[4]:= f[] Out[4]= 1 In[5]:= SyntaxQ[\f[]\] Out[5]= True In the first case the function \f\ with zero arguments has no definition, but it is still valid syntax. I later give it a definition and it is still valid syntax. It would be crazy to think SyntaxQ[\f[]\] would return a different result depending on whether f [] was defined. -Rob === Subject: Re: Unacceptable bug in Mathematica But it *is* correct syntax. An empty expression with Exp as its head. You didn't expect enough. You see, while Mathematica doesn't define this, you can: In[1]:= Unprotect[Exp] Out[1]= {Exp} In[2]:= Exp[]=E Out[2]= E In[3]:= Exp[] Out[3]= E A consequence, if you like, of the consistent, simple syntax at Mathematica's foundation. -- John Doty, Noqsi Aerospace, Ltd. http://www.noqsi.com/ -- The axiomatic method of mathematics is one of the great achievements of our culture. However, it is only a method. Whereas the facts of mathematics once discovered will never change, the method by which these facts are verified has changed many times in the past, and it would be foolhardy to expect that changes will not occur again at some future date. - Gian-Carlo Rota === Subject: Re: Unacceptable bug in Mathematica But in fact it does give a (syntactically) valid expression. Yes, it also gives a warning message. But that is based on semantic considerations. I should mention that a \syntactically valid expression\ is, by definition, anything that Mathematica will parse. Here is a related example of something that is not syntactically valid. In[3]:= ToExpression[\Exp[)\] ToExpression::sntx: Invalid syntax in or before \Exp[) \. ^ Out[3]= $Failed SyntaxQ tells us, correctly, that we should have expected that one to fail. In[4]:= SyntaxQ[\Exp[)\] Out[4]= False Daniel Lichtblau Wolfram Research === Subject: Re: Unacceptable bug in Mathematica SyntaxQ looks for more basic errors - such as mismatched brackets. A lot of expressions - such as Exp[] are actually valid Mathematica expressions, even though they have usually been entered erroneously. As you might expect, Exp[] evaluates to itself! David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Unacceptable bug in Mathematica Why do you think Exp[] is not syntactically correct? If you want a syntactically incorrect expression you could try Exp[ instead, where the missing ] causes it to be incomplete in a way that makes it syntactically incorrect. Because Exp[] is a syntactically correct Mathematica expression the Mathematica kernel evaluates it, and produces the result Exp[] (i.e. no change), and simultaneously produces a warning message \Exp::argx: Exp called with 0 arguments; 1 argument is expected.\. If you override the default behaviour of Exp[], for instance by using Unprotect[Exp]; Exp[] := myexp[]; Protect[Exp]; then Exp[] will evaluate to myexp[]. -- Stephen Luttrell West Malvern, UK === Subject: Re: Unacceptable bug in Mathematica Actually this is not a bug. Exp is the head of an expression and is a Mathematica symbol. Hence it is syntactically correct or it so stand on its own. For example it can appear as an argument to an appropriate function such as Map as in Map[Exp,{1,2,3,4}] --David === Subject: Re: Unacceptable bug in Mathematica But that is a syntactically correct expression, just like {} or foo[]. You are probably complaining that Exp[] doesn't have any semantics, but this is not what SyntaxQ checks. The warning message that Mathematica generates when you try to evaluate Exp[] is also not a syntax error (what you would get if you enter e.g. Exp][) but a message generated on evaluation (rather than parsing), i.e. when applying substitution rules on the parsed expression. HTH, -Nikolaus -- =C2=BBIt is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.=C2=AB -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C === Subject: Re: Unacceptable bug in Mathematica you say that: \Maybe you have in mind that Exp, being a built in \function\ (that is, \ a symbol with DownValues attached to it), should require an \argument\. \ Well and good, but that's progamming language semantics, not syntax.\ OK I accept this, however then you (Wolfram Research) should remove the following comment from the documentation of SyntaxQ, as it is misleading: \When SyntaxQ gives True, the string can be converted to an expression:\ And definately, \Exp[]\ // ToExpression does not give *a valid expression*... === Subject: Re: Model the surface of an ellipsoid a = 3; b = 2; eqn = x^2/a^2 + y^2/b^2 == 1; soln = y /. Solve[eqn, y] {(-(2/3))*Sqrt[9 - x^2], (2*Sqrt[9 - x^2])/3} a = 3; b = 2; c = 1; eqn = x^2/a^2 + y^2/b^2 + z^2/c^2 == 1; soln = z /. Solve[eqn, z] {(-(1/6))*Sqrt[-4*x^2 - 9*y^2 + 36], (1/6)*Sqrt[-4*x^2 - 9*y^2 + 36]} Plot3D[soln, {x, -a, a}, {y, -b, b}, Bob Hanlon books/Surfaces/Ellipsoid.nb Hi Jens, first ;-) I already download the notebook long ago. I did not understand anything from that it seems to be too much of mathematics to me. In my case i have only 4 unknown parameters ( 1 = Sqrt[r^2/R^2 + d^2/ D^2] ). Typically, also shown in the \ websitehttp://mathworld.wolfram.com/El= lipsoid.html, for a ellipsoidal there must at least three coordinates. But the equation which is i have seems to be different. please tell me if am wrong. Please understand i am using mathematica 5.2. I used an ImplicitPlot like this i get only 2D plot. ImplicitPlot[Sqrt[(x^2/9) + (y^2/4)] == 1, {x, -3, 3}] My question is for 3D it is more complicated? do i need to use much of trigonometry for the angles? May -- Bob Hanlon === Subject: Re: Stacked Definitions It would seem that it is stored in SubValues[temp] David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Machine-precision Exp[] function Hi all, The built-in Exp[] function is a bit too smart for my purposes, since it generates arbitrary-precision results if machine-precision numbers cannot hold the result. For instance, In[1] := Exp[-1`*^6] Out[1] = 3.296831478088558578968907969112477365`9.954589770191001*^-434295 produces a number for which MachineNumberQ[] returns False. Such non- machine-precision numbers massively slow down my program without actually making any difference in accuracy at the end. So I need a function, MachineNumberExp[], which *always* spits out a machine- precision number; underflows would be replaced by zeroes: In[2] := MachinePrecisionExp[-1`*^6] Out[2] = 0. Is such a function already built into Mathematica? I.e., is there a way to switch off the underflow-treatment behavior of calculating arbitrary-precision results? I know I can define 0.] but I'm looking for efficient, built-in, machine-precision procedures since my code is supposed to be blazing fast at the end. Roman. === Subject: Re: Minimize NMinimize[{Abs[3^d + 5^f - 2^7], {d, f} \\[Element] Integers}, {d, f}] Bobby -- DrMajorBob@longhorns.com === Subject: Re: Minimize Add a constraint: In[43]:= NMinimize[{Abs[3^d + 5^f - 2^7], {d, f} \\[Element] Integers}, {d, f}] Carl Woll Wolfram Research === Subject: Re: Minimize One possible approach is to read the documentation. NMinimize[{Abs[3^d + 5^f - 2^7], Element[d | f, Integers]}, {d, f}] Andrzej Kozlowski === Subject: Re: Minimize You can always apply brute force: data = Flatten[Table[{Abs[3^d + 5^f - 2^7], {d, f}}, {d, -5, 5}, {f, -3, \ 3}], 1]; Select[data, #[[1]] == Min[data[[All, 1]]] &] Bob Hanlon What Mathematica procedure to use to minimize expotential finction e.g. Minimize[Abs[3^d + 5^f - 2^7], {d, f}] where we can push: d and f are both Integers NMinimize[Abs[3^d + 5^f - 2^7], {d, f}] Mathematica answer is: good answer is: {d,f}={1,3} Best wishes Artur -- Bob Hanlon === Subject: Basic programming Hey I'm a beginner in mathematica and I'm trying to code a little something \ but can't seem to be able to make it work... I know its pretty basic and \ that's exactly my problem since the mathematica help is a bit overkill for \ what I need. I have daily stock prices for a stock on a 100 day period, I want to compute \ the standard deviation for a rolling 10 days period for the whole list of \ data. So basically, I would like to do something like this : stdev(1;;10) then stdev(2;;11) until stdev(91;;100) and get the results in a list Id also like to get it another way, by starting with only one observation \ and building my standard deviation calculation until I have my whole rolling \ period built up, for example : stdev(1) stdev(1,2) stdev(1,2,3) until stdev(1;;10) then same as before, roll the period until the end of dataset and produce a \ list of the results. === Subject: Re: right hand side aa = 2*x + 5*y == 1; y /. Solve[aa, y][[1]] (1/5)*(1 - 2*x) Last[Reduce[aa, y]] // Simplify (1/5)*(1 - 2*x) An alternate way to extract the results of Reduce y /. ToRules[Reduce[aa, y]] // Simplify (1/5)*(1 - 2*x) Bob Hanlon Hello Everyone! I suppose that my question can be very easy. I will translate it on simple equation, aa = 2*x + 5*y == 1, I need to plot this equation so i take Reduce [aa,y], the result is following y == 1/5 - (2 x)/5. Now I would like to take right side of equation to plot 1/5-(2x)/5. However I do not know how to do it. Magdalena -- Bob Hanlon === Subject: Re: Minimize Add a constraint to specify d, f are integers, For example In[3]:= NMinimize[{Abs[3^d + 5^f - 2^7], {d, f} \\[Element] Integers}, {d, f}]