A105 === Subject: Request for Collective Wisdom... (*Below is a request for suggestions for hints for beginners. The preface is a bit long-winded *) I am working on an applied math for physical scientists undergraduate text---I am using Mathematica as the engine to learn and solve problems quickly. I have an appendix that I have been creating (empirically) for a couple years: Common Mathematica Beginners' Errors. This wasn't difficult. I am now considering how to write another Appendix: Mathematica Usage Paradigms for Beginners. This one is not as straightforward because it will be a list of short sequences of Mathematica code. The size of the list should be a compromise between length, completeness, and orthogonality. Some topics are obvious to (subjective) me: work symbolically and with exact representations; scale to remove units when possible; visualize often and when in doubt evaluate as a number; pure functions are power; avoid the outdoors unless you have applied the documentation, lists are your friends... Nota bene, this is a book for undergraduates who have just received the physics, chemistry, and multivariable calculus catechism, and (typically) don't appreciate that there are common themes in their education (think back...). (* Punchline: *) I would sincerely appreciate thoughtful (bullet-type) suggestions for paradigms. (off-line or on- as you please). PS: Implicit in this is what a dear friend called The Homotopy Conjecture. Give me a small working example, and it can deformed into a complicated one for my own purposes. PPS: I expect a small fraction of snarky answers---I won't respond. -- W. Craig Carter === Subject: Re: Manipulate in HelpBrowser: Bug There are bugs in the older Help Browser such that dynamic displays often don't work. (There were worst problems in Version 5.2 with some animations that were generated by package code.) In Version 6 the result is that Manipulate and Animate expressions sometimes (but not always) just don't operate, i.e., the controls don't work. There are two fixes. One is to copy the output cell from the Help Browser window into a regular Mathematica notebook. Without any further evaluation it should then work properly. A second fix is to append CreateDialog@ to the Manipulate or Animate statement and evaluate. This brings it up in an outside window and again it will work properly. -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > > I wanted to use the Manipulate command in some of my old help files, > i.e. HelpBrowser and not DocumentationCenter. > Thereby I noticed the following weird behavior: > > Open the HB with > FrontEndTokenExecute[HelpDialog]. > > Evaluate > Manipulate[Plot[Sin[k x], {x, 0, 1}], {k, 1, 2}]. > > It won't behave properly when moving the slider. Now strange is that > 1.) Animate works > 2.) Copying the output cell and pasting it again works. > > I used M6 in Windows, on Mac and Linux everything worked as expected. > > Can anyone explain this behavior or (even better) knows a (simple) > workaround. My best idea would be to use Animate instead. > > > Markus Huber > === Subject: Question on the Limiting Value of Ratios of Consecuative Primes... Is there some analytic limit to the ratio of consecuative primes? The expression Limit[Prime[i]/Prime[i+1],{i,->Infinity}] returns unevaluated. Plotting Table[ Prime[i]/Prime[i+1],{i,1,20000}] shows a lot of structure with a minimum of 3/5. -- Richard Palmer === Subject: Re: orthonormal eigenvectors] First, since m is not hermitian, its eigenvectors are not necessarily orthogonal with each other. In[17]:= res = Eigenvectors[m] Out[17]= {{0, 0, 1}, {(-I)*Sqrt[2], 1, 0}, {I/Sqrt[2], 1, 0}} Relatively to the usual euclidean scalar product, we can see that these vectors are not orthogonal : In[55]:= Outer[Dot, res, res, 1] // N Out[55]= {{1., 0., 0.}, {0., -1., 2.}, {0., 2., 0.5}} but notice that Dot is not an hermitian form for *complex vector spaces*! One should use instead a scalar product like : Scal[u_List, v_List] := Dot[u, Conjugate[v]] // ComplexExpand then we have orthogonality : In[58]:= Outer[Scal, res, res, 1] // N Out[58]= {{1., 0., 0.}, {0., 3., 0.}, {0., 0., 1.5}} Hope this helps... Claude -- ********************************* Claude Mant.8e UMR CNRS 6117 LMGEM http://www.com.univ-mrs.fr/LMGEM/ Centre d'Oc.8eanologie de Marseille Campus de Luminy, Case 901 13288 MARSEILLE Cedex 09 tel : (+33) 491 829 127 fax : (+33) 491 829 119 ********************************* === Subject: Calculations with Interpolating Functions Hi I obtain an Interpolating function as a solution of a differential equation with the command NDSolve, lets call it =93solution=94, which gives x(t). Next I want to use this solution for further calculations. With the commands =93result=Evaluate[x(t)/. First[solution]]=94 or =93result= x(t)/.solution, {t,0,tmax}=94 I do the plot x(t) without any problems. Now, with version 5.2 I manage to integrate x(t) or linear functions of it. But when I try to integrate non linear functions of x(t), like x(t)^2 or Sin[x(t)] (which is what I want), Mathematica is unable to give a numerical result, all I get is an integral saying that there is an InterpolatingFunction in the integrand. With Mathematica 6 the linear integration does not work either. Any help would be appreciated. Joao Paulo === Serdar -----Original Message----- === Subject: Re: Problem: is not a list of numbers with dimensions In both cases, use Exp rather than exp A = 1*10^(-4); k = 2/3; g = 1.12*10^(-11); Attenuation = 0.23026*0.475*10^(-3); L = 7200; Leff = (1 - Exp[-Attenuation*L])/Attenuation; FindRoot[x - A*Exp[k*g*x*Leff - Attenuation*L], {x, 0}] {x->0.0000454986} Bob Hanlon > When run the below code, > A=1*10^(-4); k=2/3; g=1.12*10^(-11); Attenuation= 0.23026*0.475*10^(-3); L=7200; Leff=(1-exp[-Attenuation*L])/Attenuation; FindRoot[x-A*exp[k*g*x*Leff-Attenuation*L],{x,0}] It executes the below solution, FindRoot::nlnum: The function value {0.-0.0001 exp[-0.787489+0. (1.+Times[<<2>>])]} is not a list of numbers with dimensions {1} at {x} = {0.}. I need your help about numerical and Alpha_numeric solution of this problem. > f(x)= x-A*exp[k*g*x*Leff-Attenuation*L Serdar === Subject: Re: LayeredGraphPlot without edge crossing. OK. I assume that Mathematica cannot plot a directed tree without edge crossing. I also assume that the position of elements within a layer (in the LayeredGraphPlot) depends on the original order of the displayed data. Is that true? If yes, what is the relation. If not, what defines the order of elements in the layer? === Subject: Re: Definite integral I'm not sure why Mathematica wouldn't do it, but the result of that unevaluated integral is (using 6.0.1.0 on Linux x86 -- 32-bit) Integrate[(3/2)*Sqrt[Sin[2*[Theta]]^2], {[Theta], 3*(Pi/2), t}, Assumptions -> Element[t, Reals] && 3*(Pi/2) < [Theta] < 2*Pi] -(3/(2*Sign[3*Pi - 2*t])) - (3/2)*Abs[Cos[t]]*Sin[t]*Tan[t] Hope that helps! C.O. > I don't understand Mathematica can't calculate the last definite > integral. For the first three integrals works fine, but for the last > one crush. You can see in this paper > >WysEERSilJsIeVif4THE-OC9pisLLDECe8l5BwmXXnNsFOempl8HAl8JkHsusoMR-tRlq_vv1lR g >eh&gsc=CGn5gQsAAABmIpg7U95zHJwjbRxzLtsD > -- Curtis Osterhoudt cfo@remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html === Subject: Re: Definite integral On 5=D4=C25=C8=D5, =CF=C2=CE=E76=CA=B117=B7=D6, Miguel w= rote: > I don't understand Mathematica can't calculate the last definite > integral. For the first three integrals works fine, but for the last > one crush. You can see in this paper > > What I get is 3/2 + 1/2 (3 - 3 Abs[Cos[t]] Sin[t] Tan[t]) if your definition is s4[t_] = s2[Pi*3/2] + Integrate[...]. But I think it may be s4[t_] = s3[Pi*3/2] + Integrate[...], in this case the answer is 9/2+1/2 (3-3 Abs[Cos[t]] Sin[t] Tan[t]). U should add t > Pi*3/2 to the assumption. === Subject: Re: Definite integral > I don't understand Mathematica can't calculate the last definite > integral. For the first three integrals works fine, but for the last > one crush. You can see in this paper > This is because you typed [Epsilon] instead of [Element]. This works fine: Integrate[3/2 Sqrt[Sin[2 x]^2], {x, 3 Pi/2, t}, Assumptions -> 2 Pi > t > (3 Pi)/2] It is not necessary to separately specify that variables used in inequalities are reals. But if you do, use x [Element] Reals or Element[x, Reals], but *not* x [Epsilon] Reals. The two symbols have nothing to do with each other! So this is one more reason why the ugly lunate epsilon should not be used in mathematics ... I never understood why American/English textbooks were so fond of this symbol (never seen it in any Eastern European books). === Subject: Re: Problem/bug with ends of thick lines in graphics > Consider the following graph: > > Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {AbsoluteThickness[20]}] > > When you plot it you will see that the line's ends are not > rectangular, whereas you would certainly want them to be so. =2E.. > Does anyone have any solutions to either or both of these issues? There are a couple of things you can do to alter the appearance of this graphic. In this specific case adding PlotPoints->3 to the Plot command is enough to do the trick. Another option is to manually remove a few (4-5) points from both the start and end of the Line primitive in the resulting graphic. This problem occurs when the points at the beginning/end of the line are so very close together that the OS graphics library gets a little confused about what angle to draw the line cap, and it's really only noticeable when the line is thick enough that the cap is clearly visible. -Rob === Subject: Re: Problem/bug with ends of thick lines in graphics Good try Jens! Alas it creates a series of points that create a jagged outer boundary where the disks of the points undulate. But an approach like this may work for the end points. I have communicated with the folks at WRI about this and the bug is known. --David On May 5, 6:18 am, Jens-Peer Kuska > > Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {AbsoluteThickness[20]}] /. > Line[pnts_] :> {AbsolutePointSize[20], Point[pnts]} > > may help in this case. But AFAIK Mathematica has no directive > to set the line ends. > > Jens > > In a quick search of things I haven't found a mention of the following > simple graphics issue and I'm checking in with the group to see if > there is a memory of its mention and if there is a simple fix (and > which is not a complicated hack) that I've not been able to come up > with. > > Consider the following graph: > > Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {AbsoluteThickness[20]}] > > When you plot it you will see that the line's ends are not > rectangular, whereas you would certainly want them to be so. (An > alternative would be to have them be rounded, for example, but the > question will remain the same whatever your preference is.) Rather > they appear as polygonal in a way inconsistent with the line itself. > > One assums that this is an artifact of how the line is rendered based > on the individual line segments, and that that segmental rendering has > to do something with how a segment relates to the segments on either > side of it. The lack of a segment beyond the end segment presumably > runes the algorithm for rendering in a way that leads to this > appearance. > > I have two related questions here. The first is how, if at all > possible, to fix this in a general way through some specific options > settings for the graphics function. > > The second is how, when exporting this graphic as, say, a PDF, to make > it behave properly. > > There was a trick in pre version-6 Mathematica that would involve > adding an explicit postscript command to the PlotStyle option. Though= > this would not (I think) correct the screen appearance of the graphic, > it would properly fix it when the graphic was exported to PDF or EPS. > Here is an example of how it was done: > > Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {{ PostScript[0 setlinecap],AbsoluteThickness[20]}}] > > This, however, no longer works in Mathematica 6+ presumably because of > the new way that graphics rendering is handled. > > Does anyone have any solutions to either or both of these issues? > > > --David === Subject: Re: Problem/bug with ends of thick lines in graphics > In a quick search of things I haven't found a mention of the following > simple graphics issue and I'm checking in with the group to see if > there is a memory of its mention and if there is a simple fix (and > which is not a complicated hack) that I've not been able to come up > with. > > Consider the following graph: > > Plot[x, {x, 1/3, 3/4}, PlotRange -> {{0, 1}, {0, 1}}, > PlotStyle -> {AbsoluteThickness[20]}] > > When you plot it you will see that the line's ends are not > rectangular, whereas you would certainly want them to be so. (An > alternative would be to have them be rounded, for example, but the > question will remain the same whatever your preference is.) Rather > they appear as polygonal in a way inconsistent with the line itself. Obviously this is a bug. Unfortunately this bug is not fixed in version 6.02. And in version 5.2 this bug does not appear. Thus this is regression bug! Some graphical functionality was broken in version 6! === Subject: Solving on mathematica How would i go about solving this equaiton on mathematica (Xi -Ux)^2 + (Yi - Uy)^2 + (Zi - Uz) = (Ri - Cb) i = 1,2,3,4 where we need to find Ux, Uy, Uz, Cb tried a few things and they dont work. NSolve[ (Xi - U)^2 + (Yi - V)^2 + (Zi - W)^2 == (Ri - B)^2, {U, V, W, B}, { i = 1, 2, 3, 4} ] any ideas? === Subject: Re: Getting the size of the bounding box of a Graphics3D[] Hello David and Szabolcs, Yes it does appear to be a bug for the new primitives: PlotRange /. AbsoluteOptions[Graphics3D[Cylinder[]]] PlotRange /. AbsoluteOptions[Graphics3D[Cylinder[{{0, 0, 0}, {2, 1, 200}}, 1]]] Same incorrect bounding box.... > I think it's a bug for Sphere. > > It works for other things. > > plot1 = ParametricPlot3D[{Sin[u], Sin[u], Cos[u]} {Cos[v], Sin[v], > 1}, {u, 0, Pi}, {v, 0, 2 Pi}] > PlotRange /. AbsoluteOptions[plot1] > {{-1., 1.}, {-1., 1.}, {-1., 1.}} > > > > > > Is there a reliable way to get the coordinates and size of the bounding > > box of a Graphics3D object? > > PlotRange /. AbsoluteOptions[Graphics3D[Sphere[]]] > > > > but it gives {{0., 1.}, {0., 1.}, {0., 1.}}, whereas the correct answer > > should be {{-1., 1.}, {-1., 1.}, {-1., 1.}}. W. Craig Carter === Subject: Re: Wolfram Workbench user experiences Before Workbench existed, many times I used a very simple ASCII editor (Notepad for Windows) to create Mathematica packages. My personal reason for using an ASCII editor is that I like to have control on the exact code that is actually written, and I liked to have my code in a readable way, even if you do Not have Mathematica (if you used Mathematica 5.2 as your IDE, to write the packages, then .m file was not so easy to read, end-of-line characters were missing, weird characters would appear, etc. so that you actually needed the original .nb file from which the .m file was created, in order to be able to read -as a human- the package) That is my personal way of programming. Sometimes I do the same with HTML files, just use a simple ASCII editor, so I have all the control in the actual code. Now that I have Wolfram Workbench 1.0.0, I like it very much. For me, it is like a simple ASCII editor but it does know about Mathematica syntax, so I have syntax coloring, when I mouse-over a known Mathematica command, I get the message about the basic syntax of that command, etc. But at the same time, WHAT I WRITE IS WHAT I GET in the final .m file, which is something that I like very much. Furthermore, you also get syntax coloring when you print your program. That I love: many advantages without losing the control of the exact code that is written in the .m file of my packages. Therefore, for me, who used to program in simple ASCII editor (Notepad for Windows), the Workbench has been great. Of course I do a very basic use of all the possibilities of Workbench, so far I have Not written a package where different programming languages are used, neither have I used other advanced features of Workbench. I have written just plain Mathematica packages, like the one here: http://homepage.cem.itesm.mx/lgomez/quantum/index.htm Jose Mexico -----Mensaje original----- De: David Bailey [mailto:dave@Remove_Thisdbailey.co.uk] Enviado el: Viernes, 02 de Mayo de 2008 02:43 a.m. Para: mathgroup@smc.vnet.net Asunto: Wolfram Workbench user experiences I would be very interested in other people's experiences with the Wolfram Workbench. I must admit that I prefer to use the frontend as my 'IDE', and the workbench seemed fairly alien when I tried it. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: smart change of variables? I would like to change variables of a coupled system of ordinary differential equations F1(A,B,A',B',A'',B'',A''',A'''')=0 F2(A,B,A',B',A'',B'',A''',A'''')=0 A''',A'''' -third,fourth ord. deriv. of A. F1 and F2 are polynomials in their variables (first order in A'''',A''',B''; second order in A'',B',B; fourth order in A). We can substitute F2 by F3=F3(A,B,A',B',A'',B'') a second order polynomial. I am trying to find decoupling variables to the system. I expect that Groebner Basis of the polynomials can help in detecting such variables, however the derivatives make the problem a bit harder. Can anyone suggest a function or a package in Mathematica, which could help in determining good variables ? Artur Janda >> >> I have a arithmetic problem. >> I have an expression expr = (p1 + 2*p2)*(k1 + 2*k2) >> where p1 + p2 = k1 + k2 >> I wanna make the following change of variables, >> s = (p1 + p2)^2 >> t = (p1 - k1)^2 >> u = (p1 - k2)^2 >> >> Is it possible to tell Mathematica to express expr >> in terms of s, t, and u automatically? >> >> any ideas would be appreciated. > > More or less. You can create a Groebner basis out of the defining > polynomials, such that variables p1, p2, k1, and k2 are ordered higher > than s, t, and u. Then generalized division (aka polynomial reduction) > of expr will do what it can to make such a replacement. > > polys = {s-(p1+p2)^2,t-(p1-k1)^2,u-(p1-k2)^2,p1+p2-(k1+k2)}; > vars = {p1,p2,k1,k2,s,t,u}; > gb = GroebnerBasis[polys, vars]; > > In[19]:= InputForm[PolynomialReduce[(p1+2*p2)*(k1+2*k2), gb, vars][[2]]] > Out[19]//InputForm= 3*k2*p2 + (3*s)/2 + t/2 - u/2 > > In general the replacement will be dependent on variable and monomial > ordering. But I'm fairly certain that you will be stuck with some part > not replaced no matter waht orders are used, since this particular > variable/monomial ordering does not manage to reduce k2*p2. > > Daniel Lichtblau > Wolfram Research > > === Subject: Re: locator snap answers gave me a bit more insight in what is possible with dynamic and dynamic module. I also found a solution with manipulate, which not only gives a 'snapped result' as the solution below, but which also snaps the locator in the graphics: Manipulate[Column@{Graphics [{Disk[Round[p,0.1],0.05]},Axes->True,PlotRange->1],Round[p,0.1]}, {{p,{0,0}},Locator,Appearance-> }] I do not show the locator, but replace it with a graphics object at the rounded position of the locator. Maarten PS: the solution below is not jerking on my pc (6.0.2, windows xp) |--------+-----------------------> | | Kevin J. | | | McCann | | | | | | | | | 30/04/2008 | | | 13:03 | | | | |--------+-----------------------> >---------------------------------------------------------------------------- ----------------------------------------------------------------------| | | | cc: | === | Subject: Re: locator snap | >---------------------------------------------------------------------------- ----------------------------------------------------------------------| Hey Szabolcs, This works fine, but I notice that the graph jerks around a lot when you move the locator. I assume that Mathematica is redrawing everything on each move or ...? Anyway, does anyone know why? Kevin > > In the example below the locator can be moved to any position in the > graphic. > Can the locator be made to snap to multiples of say 0.1? > > Manipulate[Column@{Graphics[{}, Axes -> True], p}, {{p, {0, 0}}, > Locator}] > >> Hi Maarten, >> >> I am not aware of any way to do this directly with Manipulate. (Of >> course this does not mean that there doesn't exist a way!) >> >> Here is an example of doing it directly with Dynamic: >> >> Graphics[ >> Locator[Dynamic[{x, y}, ({x, y} = Round[#, 0.1]) &]], >> PlotRange -> 1, Frame -> True, >> GridLines -> {#, #} & @ >> Table[{x, If[Mod[x, 1/2] == 0, Black, Gray]}, {x, -1, 1, 1/10}] >> ] >> > > Sorry, I forgot to mention that x and y must be initialized before this= > will work: > > {x, y} = {0, 0} > > Also, the x in the Table is an unfortunate choice for a local variable > name---it has nothing to do with the x in the Dynamic. > -- Kevin J. McCann Research Associate Professor JCET/Physics Physics Building University of Maryland, Baltimore County 1000 Hilltop Circle Baltimore, MD 21250 === Subject: Re: Want a general method to extract cases resulting from Reduce > Someone recently posted asking How to remove unneeded constraints. > I can see a general use for something perhaps related to this. > > Reduce often gives back fairly complicated nested boolean structures > of constraints. Consider the results from the following concrete > example: > > Reduce[{a x1^2 + b x1 + c == y1, a x2^2 + b x2 + c == y2, a( -b/ > (2a))^2+ b ( -b/(2a)) + c == y3, y1 < y3, y2 < y3, x1 < x2, > Element[Alternatives[x1,x2,x3,y1,y2,y3,a,b,c],Reals]}, {a,b,c}] =2E.. Here is another common example where the output of Reduce could be enhanced. I often find results of the form (x==y && ALongExpressionOfConditions) || (SomeLongExpressionOfConditions && x (List @@ #)] & /@ newlst], SelfLoopStyle -> None, VertexLabeling -> True] However, there are couple of issues with the above that I could not figure out: 1) Not all nodes are shown. For instance 12 is shown only once in the output. Whereas I would like to see all 3 instances of 12. 2) I would like the above to look like the following (this is sort of the representation I want): 13 
 13 14
 16
 16 
 15 12 12
 12 
 5 
16 is the maximum value in my lst and that is why it is in the center. The values in the cluster of 16 {16,16,15} are in the center. 15 is a little further away because of the distance of 1. The cluster of {13,13,14} appears to be closer than the {12,12,12,5} because the sum of 13+13+14 = 40 and 12+12+12+5=41. 
 _____________________________________________________________________________ _______ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ === Subject: FindClusters & BarCharts Hi everyone, I have the following list: list = {{2, 4, 2, 2, 9}, {7, 2, 8, 5, 4}, {2, 1, 4, 5, 3}} I would like to find clusters in the above list: tmpVal = 3; temp = FindClusters[Cases[Flatten[Sort[list]], Except[tmpVal]]] This gives me: {{2, 1, 2, 2, 2, 2}, {4, 4, 4}, {5, 5}, {9, 7, 8}} which is correct. However, I do want one of the clusters to include the value of 3 and get something as follows: {{2, 1, 2, 2, 2, 2}, {4, 4, 4}, {5, 5}, {9, 7, 8}, {3}} If I change tmpVal = 2 I get something that is not desired: tmpVal=2 temp = FindClusters[Cases[Flatten[list], Except[value]]] This gives me: {{4, 5, 4, 1, 4, 5, 3}, {9, 7, 8}}. However, I would like the output to be somewhat as the following (In other words {{1}, {2,2,2,2,2}, {3,4,5}, {7,8,9}} Similarly, if I change the variable value=8, I get: {{2, 2, 2, 2, 2, 1, 3}, {4, 5, 4, 4, 5}, {9, 7}} but would like the output to include: {{2, 2, 2, 2, 2, 1, 3}, {4, 5, 4, 4, 5}, {7}, {8}, {9}} In other words, split the list up at the value and then I would like to plot the above in a BarChart: Needs[BarCharts`] BarChart[Map[Length[#] &, temp]] I would like the bars to have the labels as the minimum and maximum for each of the lists. For instance: {{4, 5, 4, 1, 4, 5, 3}, {9, 7, 8}, {2,2,2,2,2}} The first bar would be labeled 1-5 === Subject: Re: root of complex function > I need to get a list of root intervals of a complex function. I tried > in vain to use the package IntervalRoots. However, this package seems > to work only with real functions. I appreciate it if someone can > provide me with a simple code that does the job. I also tried to > download the Rootsearch package by Ersek but the package is not > downloadable. I tried to access MathSource this morning and did not get any trouble to access the Ted Ersek's package web page. Just to be sure, I downloaded the package file and the sample file on my system. http://library.wolfram.com/infocenter/MathSource/4482/ [I have sent both files to your private email.] -- Jean-Marc === Subject: Re: root of complex function What is your complex function? I'm amazed at how often posters ask questions but don't give the example. Have you explored the function graphically? You should be able to download RootSearch from MathSource. http://library.wolfram.com/infocenter/MathSource/4482/ Just click the icons at the bottom far left. However, RootSearch is only for single variable real functions. For this it seems to be much better than FindRoot and in my opinion should be part of Mathematica proper. But it won't help with complex functions. (Except there is a method where you can find find contours where the real part of the function is zero and then use RootSearch to search along these lines for points where the imaginary part is zero.) -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > > I need to get a list of root intervals of a complex function. I tried > in vain to use the package IntervalRoots. However, this package seems > to work only with real functions. I appreciate it if someone can > provide me with a simple code that does the job. I also tried to > download the Rootsearch package by Ersek but the package is not > downloadable. > > > > HMQ > === Subject: Re: root of complex function I just now downloaded Ersek's RootSearch.m from library.wolfram.com/infocenter/MathSource. Do a search and you should find it. I need to get a list of root intervals of a complex function. I tried > in vain to use the package IntervalRoots. However, this package seems > to work only with real functions. I appreciate it if someone can > provide me with a simple code that does the job. I also tried to > download the Rootsearch package by Ersek but the package is not > downloadable. HMQ > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Problem: is not a list of numbers with dimensions In both cases, use Exp rather than exp A = 1*10^(-4); k = 2/3; g = 1.12*10^(-11); Attenuation = 0.23026*0.475*10^(-3); L = 7200; Leff = (1 - Exp[-Attenuation*L])/Attenuation; FindRoot[x - A*Exp[k*g*x*Leff - Attenuation*L], {x, 0}] {x->0.0000454986} Bob Hanlon > When run the below code, > A=1*10^(-4); k=2/3; g=1.12*10^(-11); Attenuation= 0.23026*0.475*10^(-3); L=7200; Leff=(1-exp[-Attenuation*L])/Attenuation; FindRoot[x-A*exp[k*g*x*Leff-Attenuation*L],{x,0}] It executes the below solution, FindRoot::nlnum: The function value {0.-0.0001 exp[-0.787489+0. (1.+Times[<<2>>])]} is not a list of numbers with dimensions {1} at {x} = {0.}. I need your help about numerical and Alpha_numeric solution of this problem. > f(x)= x-A*exp[k*g*x*Leff-Attenuation*L Serdar === Subject: Re: Fitting with a power embedded in a integration I don't know how to fit my data with a power embedded in > a integration, and can't find related answer in this forum. This is the function I want to fit > !( > *SubsuperscriptBox[([Integral]), (w), (R)](c* > SuperscriptBox[(x), (-p)] > FractionBox[(x), > SqrtBox[( > *SuperscriptBox[(x), (2)] - > *SuperscriptBox[(w), (2)])]] [DifferentialD]x)) w is variable, R is a parameter, and c, p is parameters should > be fitted. I can't find a way to simplified the power law to log form > so that can't avoid the trouble while fit the power law. > Lynn > Lynn, I believe you are using a version prior to 6.0, in this case you should use the _InputForm_ when copying an expression from a Mathematica notebook to an email client: select the cell(s) you want to include in your email, then within the *Cell* menu select either *Convert To* or *Display As* and choose *InputForm*. Finally, copy and paste as usual. As posted, the expression is rendered in a weird (nonsensical) way on my system when copied and pasted. -- Jean-Marc === Subject: Re: Dashing[{}] > If I invoke Dashed somewhere in my Graphics3D display code= , a > subsequent Dashing[{}], Line[...] is supposed to draw solid lines > thereafter. It seems to have no effect as everything after that is > still dashed. Might there be something simple I'm missing? Or a bug? You should post a code snippet that produces wrong results. I cannot reproduce the problem with this simple example: Graphics[ {Dashing[{.05, .05}], Line[{{0, 0}, {1, 1}}], Dashing[{}], Line[{{1, 1}, {2, 0}}]} ] Also note that Dashing[] will only have an effect inside the enclosing { }: Graphics[ {{Dashing[{.05, .05}], Line[{{0, 0}, {1, 1}}]}, Line[{{1, 1}, {2, 0}}]} ] === Subject: Re: Dashing[{}] > If I invoke Dashed somewhere in my Graphics3D display code, a > subsequent Dashing[{}], Line[...] is supposed to draw solid lines > thereafter. It seems to have no effect as everything after that is > still dashed. Might there be something simple I'm missing? Or a bug? Steve Gray > The following works as expected on my system. Table[Graphics3D[{Dashing[{r, 0.1 - r}], Line[{{0, 0, 0}, {2, 1, 1}}], Dashing[{}], Line[{{0, 1, 0}, {2, 0, 1}}]}], {r, {0.01, 0.03, 0.05, 0.08}}] See, http://homepages.nyu.edu/~jmg336/mathematica/dashing.pdf Since you did not provide an example of faulty code, it is hard to tell more about the possible issue you encountered. -- Jean-Marc === Subject: Re: Dashing[{}] Example? -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > If I invoke Dashed somewhere in my Graphics3D display code, a > subsequent Dashing[{}], Line[...] is supposed to draw solid lines > thereafter. It seems to have no effect as everything after that is > still dashed. Might there be something simple I'm missing? Or a bug? > > Steve Gray > === Subject: Re: Dashing[{}] $Version 6.0 for Mac OS X x86 (64-bit) (March 13, 2008) Show[Graphics3D[{ Blue, Thick, Dashing[{.05, .05}], Line[{{0, 0, 0}, {1, 1, 1}}], Red, Thick, Dashing[{}], Line[{{1, 1, 1}, {2, 2, 0}}]}]] This works as expected on my system. Bob Hanlon > If I invoke Dashed somewhere in my Graphics3D display code, a > subsequent Dashing[{}], Line[...] is supposed to draw solid lines > thereafter. It seems to have no effect as everything after that is > still dashed. Might there be something simple I'm missing? Or a bug? Steve Gray > === Subject: Re: orthonormal eigenvectors > I have a 3X3 matrix M: {1,-i(2^(1/2)),0} {i(2^(1/2)),0,0} {0,0,2} > And I am trying to find a set of orthonormal eigenvectors for M. You can find a set of eigenvectors by doing: In[54]:= m = {{1, -I (2^(1/2)), 0}, > {I (2^(1/2)), 0, 0}, > {0, 0, 2}}; In[55]:= ev = Eigenvectors[m] Out[55]= {{0, 0, 1}, {-I Sqrt[2], 1, 0}, {I/Sqrt[2], 1, 0}} Then it is easy to normalize these by doing: In[56]:= len = (#.#) & /@ ev; > ev /Sqrt[len] Out[57]= {{0, 0, 1}, {-Sqrt[2], -I, 0}, {I, Sqrt[2], 0}} But while all of these have unit length, they do not form an > orthonormal set since In[58]:= Dot @@ Rest[%] Out[58]= -2 I Sqrt[2] which is clearly not zero. That is for your matrix, a set of > orthonormal eigenvectors doesn't exist. > The matrix is Hermitian, i.e. m == Conjugate@Transpose[m], so a set of orthonormal eigenvectors is guaranteed to exist with respect to the dot product complexDot = #1 . Conjugate[#2] &. Even though one eigenvalue of the matrix is degenerate, the set of vectors returned by Eigenvectors are orthogonal to each other, but not normalized: In[16]:= ev = Eigenvectors[m] Out[16]= {{0, 0, 1}, {-I Sqrt[2], 1, 0}, {I/Sqrt[2], 1, 0}} In[17]:= Outer[complexDot, ev, ev, 1] Out[17]= {{1, 0, 0}, {0, 3, 0}, {0, 0, 3/2}} Normalize[] handles complex vectors correctly, so we can simply do the following: In[19]:= ev = Normalize /@ ev Out[19]= {{0, 0, 1}, {-I Sqrt[2/3], 1/Sqrt[3], 0}, {I/Sqrt[3], Sqrt[2/3], 0}} In[20]:= Outer[complexDot, ev, ev, 1] Out[20]= {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}} === Subject: Re: Hash Table for self avoiding random walks > Daniel Lichtblau: http://library.wolfram.com/infocenter/Conferences/321/ > , which shows how downvalues can be used in a similar way to hash > still the state of the art. The idea is simple. If I have a walk that took steps {{1,1},{1,2}, > {2,2}} then I make a function h: h[{1,1}] = True; > h[{1,2}] = True; > h[{2,2}] = True; My primary complaint with this technique is that it seems to require > giving your hash table a name with global scope. What if I want to > make 100 different walks? Do I have to give them all separate names? > I guess I could do something like h[10][1,1] = True;, but then I > always have to keep track of which walk I'm working on. I'd rather > just be able to let them all be anonymous and stick them in a list. Any ideas? Just an idea that pops up. You could use different contexts (with their names automatically generated/discarded during each run) to store the h[m,n] values. See *Contexts* http://reference.wolfram.com/mathematica/tutorial/Contexts.html *Manipulating Symbols and Contexts by Name* http://reference.wolfram.com/mathematica/tutorial/ManipulatingSymbolsAndCont extsByName.html HTH, -- Jean-Marc === Subject: Re: Hash Table for self avoiding random walks > Here's my current best effort: neighborhood[n_] := > With[{seed = ReplacePart[ConstantArray[0, n], 1 -> 1]}, > Join[Permutations[seed], Permutations[-seed]]] availableSteps[{points_, visitedFunction_}] := > With[{steps = (Last[points] + #) & /@ > neighborhood[Dimensions[points][[2]]]}, > Select[steps, visitedFunction[#] =!= True &]] takeStep[{points_, visitedFunction_}] := > With[{newStep = > RandomChoice[availableSteps[{points, visitedFunction}]]}, > visitedFunction[Last[points]] = True; > {Append[points, newStep], visitedFunction}] Clear[trail]; > {points, trail} = > NestWhile[ > takeStep, {{{0, 0, 0}}, trail}, (Length[availableSteps[#]] > 0) &]; The part that I really don't like is the Clear[trail] part. > Your code looks good to me. You can use Module[] to localize 'trail', this way it won't be necessary to use Clear[]. Here's a slight modification that runs ~4x faster on my machine: neighbourhood[n_] := neighbourhood[n] = With[{seed = ReplacePart[ConstantArray[0, n], 1 -> 1]}, Join[Permutations[seed], Permutations[-seed]]] step[visited_][pt_] := With[ {steps = Select[(pt + #) & /@ neighbourhood@Length[pt], ! ValueQ[visited[#]] &]}, If[steps =!= {}, With[{next = RandomChoice[steps]}, visited[next] = True; next ], Null] ] Module[{trail}, Most@NestWhileList[step[trail], {0, 0, 0}, # =!= Null &] I've thrown this together quickly, so it's a bit messy ... sorry about that (especially about merging takeStep and availableSteps, which serves no purpose in this case). The two main optimizations are caching the result of neighbourhood[], and using NestWhileList instead of NestWhile + Append. I have not timed the parts of the function separately, but I suspect that the speedup is due to the latter change. I hope this helps, Szabolcs === Subject: Re: Hash Table for self avoiding random walks > Hello JM, > > I may be misunderstanding your question completely, so I am sorry if > this suggestion is off target: > > atrail := Module[{trail}, NestWhile[takeStep, {{{0, 0, 0}}, trail}, > (Length[availableSteps[#]] > 0) &]] > > Table[atrail,{4}] This is exactly what I was looking for. I knew there was a simple step I was missing. About 5 minutes after posting, I came up with a similar solution: atrail = NestWhile[takeStep, {{{0, 0, 0}}, Unique[]}, (Length[availableSteps[#]] > 0) &] JM === Subject: Re: Hash Table for self avoiding random walks > Executive Summary: Can I make a bunch of things that work like hash tables without > polluting the global scope? Long winded Version: I've been playing around with self avoiding random walks. Generating > them efficiently requires a fast way of checking whether a given step > will intersect the set of previous steps, which is generally a sparse > subset of the underlying lattice. Using a list of the previous steps isn't so great because searching it > for collisions is order the size of the list. Using an array isn't so > great because it has predefined boundaries and because, as the > dimensionality increases, the size of the array goes like (side > length)^dimensions. I think the ideal data structure is a hash table. It takes constant > time to add new elements and constant time to check if a trial step > collides with a previous step, and there are no predefined > boundaries. But it seems Mathematica doesn't have a true hash table. > SparseArray doesn't qualify because it wraps negative values and > complains if you look for something outside the boundaries. Dispatch > doesn't qualify because (as far as I know) there's no way to add new > rules to an already created DispatchTables. Daniel Lichtblau: http://library.wolfram.com/infocenter/Conferences/321/ > , which shows how downvalues can be used in a similar way to hash > still the state of the art. The idea is simple. If I have a walk that took steps {{1,1},{1,2}, > {2,2}} then I make a function h: h[{1,1}] = True; > h[{1,2}] = True; > h[{2,2}] = True; My primary complaint with this technique is that it seems to require > giving your hash table a name with global scope. What if I want to > make 100 different walks? Do I have to give them all separate names? > I guess I could do something like h[10][1,1] = True;, but then I > always have to keep track of which walk I'm working on. I'd rather > just be able to let them all be anonymous and stick them in a list. Any ideas? Here's my current best effort: neighborhood[n_] := > With[{seed = ReplacePart[ConstantArray[0, n], 1 -> 1]}, > Join[Permutations[seed], Permutations[-seed]]] availableSteps[{points_, visitedFunction_}] := > With[{steps = (Last[points] + #) & /@ > neighborhood[Dimensions[points][[2]]]}, > Select[steps, visitedFunction[#] =!= True &]] takeStep[{points_, visitedFunction_}] := > With[{newStep = > RandomChoice[availableSteps[{points, visitedFunction}]]}, > visitedFunction[Last[points]] = True; > {Append[points, newStep], visitedFunction}] Clear[trail]; > {points, trail} = > NestWhile[ > takeStep, {{{0, 0, 0}}, trail}, (Length[availableSteps[#]] > 0) &]; The part that I really don't like is the Clear[trail] part. As an aside, although there is no documentation for HashTable, doing FullForm[Dispatch[Table[n -> 1, {n, 4}]]] gives Dispatch[List[Rule[1,1],Rule[2,1],Rule[3,1],Rule[4,1]],List[HashTable[1,4,1,L ist[List[1,2,3],List[],List[4]]]]] Is the feature set I want just hiding? > JM > Remember that the DownValue's in Daniel Lichtblau's technique can relate to a local variable: Module[{h}, h[{1,1}]=True; etc. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Hash Table for self avoiding random walks Hello JM, I may be misunderstanding your question completely, so I am sorry if this suggestion is off target: atrail := Module[{trail}, NestWhile[takeStep, {{{0, 0, 0}}, trail}, (Length[availableSteps[#]] > 0) &]] Table[atrail,{4}] > As an aside, although there is no documentation for HashTable, doing There is something, but not much, in the doc for Dispatch. I am not sure, but I don't think you will need to get to the guts of HashTable. > Can I make a bunch of things that work like hash tables without > polluting the global scope? : : > My primary complaint with this technique is that it seems to require > giving your hash table a name with global scope. What if I want to > make 100 different walks? Do I have to give them all separate names? > I guess I could do something like h[10][1,1] = True;, but then I > always have to keep track of which walk I'm working on. I'd rather > just be able to let them all be anonymous and stick them in a list. > > Any ideas? Here's my current best effort: > > neighborhood[n_] := > With[{seed = ReplacePart[ConstantArray[0, n], 1 -> 1]}, > Join[Permutations[seed], Permutations[-seed]]] > > availableSteps[{points_, visitedFunction_}] := > With[{steps = (Last[points] + #) & /@ > neighborhood[Dimensions[points][[2]]]}, > Select[steps, visitedFunction[#] =!= True &]] > > takeStep[{points_, visitedFunction_}] := > With[{newStep = > RandomChoice[availableSteps[{points, visitedFunction}]]}, > visitedFunction[Last[points]] = True; > {Append[points, newStep], visitedFunction}] > > Clear[trail]; > {points, trail} = > NestWhile[ > takeStep, {{{0, 0, 0}}, trail}, (Length[availableSteps[#]] > 0) &]; > > The part that I really don't like is the Clear[trail] part. > -- W. Craig Carter === Subject: Re: Hash Table for self avoiding random walks > > h[{1,1}] = True; > h[{1,2}] = True; > h[{2,2}] = True; > > My primary complaint with this technique is that it seems to require > giving your hash table a name with global scope. What if I want to > make 100 different walks? Do I have to give them all separate names? > I guess I could do something like h[10][1,1] = True;, but then I > always have to keep track of which walk I'm working on. I'd rather > just be able to let them all be anonymous and stick them in a list. > This is the approach that I'd recommend, too. h does not need to have global scope. You can always put it into a Module: Module[ {h}, ... ... h[{a,b}] = True ... ] Szabolcs === Subject: Re: StringMatchQ and Regular Expressions > Hi I'm running Mathematica v6.0.2 on Windows XP. I define a regex thus: doStmt = RegularExpression[do(?=s*w+=)]; and then execute: StringCases[doindex= , doStmt] which brings the response {do} I then execute StringMatchQ[doindex= , doStmt] which brings the response False I had expected that if StringCases found any cases, then StringMatchQ > would return True. Obviously this is not the case, but can anyone out > there throw light upon this. > Mark Westwood > See also StringFreeQ and the section Properties & Relations (3) in its homepage. hth, albert === Subject: Symbolic Optimization Problem I need to maximize [Pi] = R*[Alpha] (1/[Alpha] ([Beta]/R)^(1/( 1 - [Beta])) - (1 - [Gamma])*[Beta]^(2/( 1 - [Beta]))*[Alpha]^([Beta]/( 1 - [Beta]))) - (1/[Alpha] ([Beta]/R)^(1/( 1 - [Beta])) - (1 - [Gamma])*[Beta]^(2/( 1 - [Beta]))*[Alpha]^([Beta]/(1 - [Beta]))) with respect to R (R will be in terms of alpha, beta and gamma) under the assumption that beta, alpha and gamma will all be between 0 and 1. How can I solve this symbolic optimization with Mathematica? I tried to solve it but I am not very experienced with Mathematica and your help is greatly appreciated. Gonca Senel Bilkent University === Subject: Re: Finding the line that caused an error > Is there any way to display the specific line of code that caused > an error in Mathematica? > I'm used to working with C++ compilers that give you a line number > along with each error message, and I'm starting to get frustrated > with Mathematica. It'd be much simpler to immediately see the cause > of the error instead of sifting through many lines of code. If you are seeing an error message: TraceDialog[expr,Message[___]] will stop execution at the point of the error. You can then examine the execution stack to locate the origin of the problem. Ssezi === Subject: Re: Finding the line that caused an error > Is there any way to display the specific line of code that caused an error= in Mathematica? > I'm used to working with C++ compilers that give you a line number alon= g with each error message, and I'm starting to get frustrated with Mathemati= ca. It'd be much simpler to immediately see the cause of the error instead o= f sifting through many lines of code. The Front End does highlight parsing errors. This is analogous to the error messages of a C++ compiler (static checking). For messages generated while the program is running, you could try using the Break at messages feature of the debugger, which will highlight the part of code that generated the message. === Subject: Re: Interpolation with FourierTrigSeries with mathematica 6 tia sal2 I believe problem is your data and the request for periodic numeric interpolation. (The message window reveals the warning). data2 is not periodic: The following works, but has some difficulties with convergence of the numerical integration: lp = ListPlot[data3] f = Interpolation[data3, PeriodicInterpolation -> True] pf = Plot[f[x], {x, 0, 139}] fs = N[FourierTrigSeries[f[x], x, 25, FourierParameters -> {-1, 1/139}]] fp = Plot[fs, {x, 0, 138}] Show[lp, fp, pf] > When I change different data points to the code example: > > data2 = {{0, 0}, {1, 1}, {3, 0}, {7, -2}, {14, 1}, {17, 6}, {19, -2}, > {25, -6}, {34, 6}, {41, 4}, {49, -6}, {56, -5}, {63, 4}, {69, 3}, {74, > -5}, {77, -3}, {86, 3}, {90, 7}, {95, -3}, {96, -8}, {103, 7}, {112, > 9}, {120, -8}, {129, -9}, {138, 9}}; > > f = Interpolation[data2, PeriodicInterpolation -> True]; > << FourierSeries` > > s[x_] = N[ > FourierTrigSeries[f[x], x, 25, FourierParameters -> {-1, 1/138}]] > > my partial output becomes : > > 0.00729927 NIntegrate[ > Interpolation[{{0, 0}, {1, 1}, {3, 0}, {7, -2}, {14, 1}, {17, -- W. Craig Carter === Subject: Re: Interpolation with FourierTrigSeries with mathematica 6 tia sal2 > Interpolation with FourierTrigSeries with mathematica 6 tia sal2 > When I change different data points to the code example: data2 = {{0, 0}, {1, 1}, {3, 0}, {7, -2}, {14, 1}, {17, 6}, {19, -2}, > {25, -6}, {34, 6}, {41, 4}, {49, -6}, {56, -5}, {63, 4}, {69, 3}, {74, > -5}, {77, -3}, {86, 3}, {90, 7}, {95, -3}, {96, -8}, {103, 7}, {112, > 9}, {120, -8}, {129, -9}, {138, 9}}; The endpoint must have a y-value equals to the y-value of the start point. In your case, since the function starts with a value of zero, the last point must be {138, 0} because the function *must* be periodic. This is exactly what Mathematica complains about in the *error message* you have chosen to disregard. Needs[FourierSeries`] data2 = {{0, 0}, {1, 1}, {3, 0}, {7, -2}, {14, 1}, {17, 6}, {19, -2}, {25, -6}, {34, 6}, {41, 4}, {49, -6}, {56, -5}, {63, 4}, {69, 3}, {74, -5}, {77, -3}, {86, 3}, {90, 7}, {95, -3}, {96, -8}, {103, 7}, {112, 9}, {120, -8}, {129, -9}, {138, 9}}; f = Interpolation[data2, PeriodicInterpolation -> True]; s[x_] = N[ FourierTrigSeries[f[x], x, 25, FourierParameters -> {-1, 1/138}]] Interpolation::per: In dimension 1 the data at the endpoints of the fundamental period are not equal. >> > f = Interpolation[data2, PeriodicInterpolation -> True]; > << FourierSeries` s[x_] = N[ > FourierTrigSeries[f[x], x, 25, FourierParameters -> {-1, 1/138}]] my partial output becomes : 0.00729927 NIntegrate[ > Interpolation[{{0, 0}, {1, 1}, {3, 0}, {7, -2}, {14, 1}, {17, > 6}, {19, -2}, {25, -6}, {34, 6}, {41, > 4}, {49, -6}, {56, -5}, {63, 4}, {69, > 3}, {74, -5}, {77, -3}, {86, 3}, {90, > 7}, {95, -3}, {96, -8}, {103, 7}, {112, > 9}, {120, -8}, {129, -9}, {138, 9}}, > PeriodicInterpolation -> True][x], {x, -(137/2), 137/2}] + > 0.0145985 Cos[0.0458627 x] NIntegrate.......................... does anyone know why this no longer outputs in the form of just sin > and cos? > (which I really want) Therefore, using *periodic* data points, we get Needs[FourierSeries`] data2 = {{0, 0}, {1, 1}, {3, 0}, {7, -2}, {14, 1}, {17, 6}, {19, -2}, {25, -6}, {34, 6}, {41, 4}, {49, -6}, {56, -5}, {63, 4}, {69, 3}, {74, -5}, {77, -3}, {86, 3}, {90, 7}, {95, -3}, {96, -8}, {103, 7}, {112, 9}, {120, -8}, {129, -9}, {138, 0}}; f = Interpolation[data2, PeriodicInterpolation -> True]; s[x_] = N[ FourierTrigSeries[f[x], x, 25, FourierParameters -> {-1, 1/138}]] [Warning messages about slow convergence discarded] -1.33366 - 1.93771 Cos[0.0455303 x] - 1.84218 Cos[0.0910607 x] - 0.915718 Cos[0.136591 x] + 1.96324 Cos[0.182121 x] + 1.32678 Cos[0.227652 x] + 0.178997 Cos[0.273182 x] - 1.85621 Cos[0.318712 x] + 1.24014 Cos[0.364243 x] + 2.53467 Cos[0.409773 x] + 0.178343 Cos[0.455303 x] - 0.597821 Cos[0.500834 x] + 0.59092 Cos[0.546364 x] - 0.129048 Cos[0.591894 x] - 0.377664 Cos[0.637425 x] + 0.303572 Cos[0.682955 x] + 1.10636 Cos[0.728485 x] + 0.234811 Cos[0.774016 x] - 0.339997 Cos[0.819546 x] - 0.247664 Cos[0.865076 x] + 0.136132 Cos[0.910607 x] - 0.0551202 Cos[0.956137 x] - 0.146821 Cos[1.00167 x] - 0.028917 Cos[1.0472 x] + 0.0668191 Cos[1.09273 x] - 0.0534889 Cos[1.13826 x] - 0.19826 Sin[0.0455303 x] + 0.823365 Sin[0.0910607 x] + 0.967715 Sin[0.136591 x] + 3.57456 Sin[0.182121 x] + 3.72198 Sin[0.227652 x] - 4.41631 Sin[0.273182 x] - 0.783889 Sin[0.318712 x] + 0.985987 Sin[0.364243 x] + 0.297933 Sin[0.409773 x] - 0.182527 Sin[0.455303 x] + 1.85795 Sin[0.500834 x] + 0.603078 Sin[0.546364 x] - 0.92085 Sin[0.591894 x] - 0.693979 Sin[0.637425 x] + 0.0286992 Sin[0.682955 x] + 0.0714767 Sin[0.728485 x] - 0.0838198 Sin[0.774016 x] + 0.284645 Sin[0.819546 x] + 0.296819 Sin[0.865076 x] - 0.138192 Sin[0.910607 x] - 0.320014 Sin[0.956137 x] + 0.0703057 Sin[1.00167 x] + 0.176853 Sin[1.0472 x] + 0.0718324 Sin[1.09273 x] - 0.10215 Sin[1.13826 x] -- Jean-Marc === Subject: Re: 32 or 64 bit front-end on 64-bit Mac > Just installed Mathematica 6.0.2.1 on a Mac Pro running OS X 10.5.2 > (Leopard). TThe system info (portions included below) reports that the > Mathematica kernel is 64 bit as expected, it says the front end is 32 > bit. Note that in that section, the processor type is reported as x86 > not x86-64. > SystemInformationData[{Kernel -> {Version - 6.0 for Mac OS X x86 (64-bit) (March 13, 2008), > ReleaseID -> 6.0.2 (1009763, 1009696), ... > MachineType -> PC, > OperatingSystem -> MacOSX, ProcessorType -> x86-64, > ..... > FrontEnd -> {Version - 6.0 for Mac OS X x86 (32-bit) (March 13, 2008), > ReleaseID -> 6.0.2 (1009763, 1009694), ... > MachineType -> PC, > OperatingSystem -> MacOSX, ProcessorType -> x86, > ..... Why doesn't the front end report as 64 bit and not 32 bit? Is this Jay, AFAIK, the front-end for Mac OS X is compiled and *shipped* by WRI only as a 32-bit application. So your installation is fine and what the command *SystemInformation[]* reports is correct. -- Jean-Marc === Subject: Re: 32-bit front-end on 64-bit machine > Just installed version 6.0.2.1 on a early 2008 mac pro running OS X 10.5.2. Though the Mathematica kernel version is reported as 64-bit, the front-end version is reported as 32-bit. Should I be getting 64 for that not 32? > SystemInformationData[{Kernel -> {Version - 6.0 for Mac OS X x86 (64-bit) (March 13, 2008), > ReleaseID -> 6.0.2 (1009763, 1009696), FrontEnd -> {Version - 6.0 for Mac OS X x86 (32-bit) (March 13, 2008), > ReleaseID -> 6.0.2 (1009763, 1009694), > AFAIK, the front-end for Mac OS X is compiled and *shipped* by WRI only as a 32-bit application. So your installation is fine and what the command *SystemInformation[]* reports is correct. -- Jean-Marc === Subject: Re: 32-bit front-end on 64-bit machine > Just installed version 6.0.2.1 on a early 2008 mac pro running OS X 10.5.2. Though the Mathematica kernel version is reported as 64-bit, the front-end version is reported as 32-bit. Should I be getting 64 for that not 32? > SystemInformationData[{Kernel -> {Version - 6.0 for Mac OS X x86 (64-bit) (March 13, 2008), > ReleaseID -> 6.0.2 (1009763, 1009696), FrontEnd -> {Version - 6.0 for Mac OS X x86 (32-bit) (March 13, 2008), > ReleaseID -> 6.0.2 (1009763, 1009694), I think the FE is always 32-bits - there would be no real advantage in having a 64-bit version, because if the kernel were to send it more than 2G bytes of data, think how long it would take, and what could the FE sensibly do with it! David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: 32-bit front-end on 64-bit machine The response I got from WRI support on this was that indeed the Front End is 32-bit still (and there may be no great reason to modify this). HTH ... Syd Syd Geraghty B.Sc, M.Sc. sydgeraghty@mac.com My System Mathematica 6.0.2.1 for Mac OS X x86 (64 - bit) (March 13, 2008) MacOS X V 10.5.2 > Just installed version 6.0.2.1 on a early 2008 mac pro running OS X > 10.5.2. > > Though the Mathematica kernel version is reported as 64-bit, the > front-end version is reported as 32-bit. Should I be getting 64 > for that not 32? > > > SystemInformationData[{Kernel -> {Version -> > 6.0 for Mac OS X x86 (64-bit) (March 13, 2008), > ReleaseID -> 6.0.2 (1009763, 1009696), > > FrontEnd -> {Version -> > 6.0 for Mac OS X x86 (32-bit) (March 13, 2008), > ReleaseID -> 6.0.2 (1009763, 1009694), > > === Subject: Re: Problem: is not a list of numbers with dimensions Hello Fikri, When beginning to use Mathematica, it is probably a good idea to leave off the trailing ; In this way, you will quickly see the syntax errors---this will lead you to start exploring some of the documentation. For this example, I would say this would be a good paradigm for those just getting started: (*Build up expressions with symbols, not numbers*) Leff = (1 - Exp[-Attenuation*L])/Attenuation GenExpr = x - A*Exp[k*g*x*Leff - Attenuation*L] (*use replace to create a particular instance of your expression*) Expr = GenExpr /. {A -> 10^(-4), k -> 2/3, g -> 1.12*10^(-11), L -> 7200, Attenuation -> 0.23026*0.475*10^(-3) } (*visualize what you intend to do*) Plot[Expr, {x, -1, 1}] (*Check the documentation and (if everything is fine) get your answer*) FindRoot[Expr, {x, 0}] > When run the below code, > > > A=1*10^(-4); > > k=2/3; > > g=1.12*10^(-11); > > Attenuation= 0.23026*0.475*10^(-3); > > L=7200; > > Leff=(1-exp[-Attenuation*L])/Attenuation; > > > > FindRoot[x-A*exp[k*g*x*Leff-Attenuation*L],{x,0}] > > > > It executes the below solution, > > > > FindRoot::nlnum: The function value {0.-0.0001 exp[-0.787489+0. > > (1.+Times[<<2>>])]} is not a list of numbers with dimensions {1} at > > {x} = {0.}. > > > > I need your help about numerical and Alpha_numeric solution of this problem. > > > > > f(x)= x-A*exp[k*g*x*Leff-Attenuation*L > > > > Serdar > > > -- W. Craig Carter === Subject: Re: Problem: is not a list of numbers with dimensions > When run the below code, A=1*10^(-4); k=2/3; g=1.12*10^(-11); Attenuation= 0.23026*0.475*10^(-3); L=7200; Leff=(1-exp[-Attenuation*L])/Attenuation; Must be Exp > FindRoot[x-A*exp[k*g*x*Leff-Attenuation*L],{x,0}] Must be Exp > It executes the below solution, FindRoot::nlnum: The function value {0.-0.0001 exp[-0.787489+0. (1.+Times[<<2>>])]} is not a list of numbers with dimensions {1} at {x} = {0.}. I need your help about numerical and Alpha_numeric solution of this problem. f(x)= x-A*exp[k*g*x*Leff-Attenuation*L Must be Exp Hi Serdar, You just made a typo when writing the exponential function. Keep in mind that every function names starts with a capital letter, i.e. *Exp* and not exp. In[1]:= A = 1*10^(-4); k = 2/3; g = 1.12*10^(-11); Attenuation = 0.23026*0.475*10^(-3); L = 7200; Leff = (1 - Exp[-Attenuation*L])/Attenuation; FindRoot[x - A*Exp[k*g*x*Leff - Attenuation*L], {x, 0}] Out[7]= {x -> 0.0000454986} -- Jean-Marc === Subject: Re: Problem: is not a list of numbers with dimensions > When run the below code, > > A=1*10^(-4); > > k=2/3; > > g=1.12*10^(-11); > > Attenuation= 0.23026*0.475*10^(-3); > > L=7200; > > Leff=(1-exp[-Attenuation*L])/Attenuation; > > FindRoot[x-A*exp[k*g*x*Leff-Attenuation*L],{x,0}] > > It executes the below solution, > > FindRoot::nlnum: The function value {0.-0.0001 exp[-0.787489+0. > > (1.+Times[<<2>>])]} is not a list of numbers with dimensions {1} at > > {x} = {0.}. > > I need your help about numerical and Alpha_numeric solution of this problem. > > f(x)= x-A*exp[k*g*x*Leff-Attenuation*L > > Serdar All Mathematica functions start with an uppercase letter, so exp[...] should be Exp[...] Bhuvanesh, Wolfram Research === Subject: Re: Wolfram User Interface Research? I am sorry, I was trying to be helpful. My copy of that book is at my office and I don't have access to it at the moment. Nevertheless, I am glad that you were able to find the list you were looking for. > > The Mathematica book has a list of such symbols in its table of > > contents . . . > > . . . under the name or title of ??? [The TOC is 6 pages full of quite > tiny type] > > [I think you may perhaps be referring to Appendix A.2.7, Operator Input > Forms --- ???] > > === Subject: Re: Integral wit Norm function alfa[t_] := {t^2, 4 t, 8 t^3} normt[t_] = Simplify[Norm[alfa[t]], t > 0] t*Sqrt[64*t^4 + t^2 + 16] Clear[int]; int[a_] = FullSimplify[Integrate[normt[t], {t, 1, a}, Assumptions -> {a > 0}]] (1/8192)*(16*Sqrt[64*a^4 + a^2 + 16]*(128*a^2 + 1) + 4095*ArcSinh[(128*a^2 + 1)/ (3*Sqrt[455])] - (9/2)*(4128 + 455*Log[91/5])) Plot[int[a], {a, 0, 2}] Bob Hanlon > How can I to calculate the integral of an expression which include > Norm function?. By example, Let the curve alfa[t_]:={t^2,4t, 8t^3}. Calculate > Integral[Norm[alfa[t]],{t,1,a}], where a is Real and >0. === Subject: Re: Coordinate readout from Graphics3D? >> I thought I saw somewhere that one could read out coordinates from a >> Graphics plot, according to the mouse position. I can't find it now, >> and I don't see how it would work with Graphics3D. But anything would >> >> Steve Gray > > So I have a simpler question. > > I know I can see the options that are set for a particular 3D object > typing Options[ ] around the object. This is particularly useful > when I have rotated the object with the mouse. > > But when I right click on the object and then use the object > inspector (ctrl-shift-o) and then choose Formatting, Expression > Formatting, Graphics3D Box Options, a change viewpoint (which has > lots of decimal places) is not completely visible.. Typing Options > when can use the mouse seems clunky, but not if you cannot view the > entire set of options. > > Any ideas? > You may try the following function: ExtrahiereViews[ll_]:= Flatten[Union[Extract[ll,Position[ll,#]]&/@ {ViewPoint->_, ViewCenter->_, ViewVertical->_, ViewAngle->_, ViewVector->_, ViewRange->_}]]; Call it and paste the graphics you moved with your mouse as argument. I use CMD+Shift+L (copy output from above) for that purpose Gruss Peter -- ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-== Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de === Subject: Re: Does Mathematica really need more printed, introductory documentation? > I don't understand the problem here. The online documentation > open up in a window in the front end just like any notebook. If > you go to the menu bar and select Window->Magnification you will > get a menu list allowing you to select several different > magnification levels up to 300%. When you select one of these, > all of the text is re-scaled by that factor. Isn't this adequate? Yes --- except the enlargement doesn't stick: Close the doc window, come back to another one later, and the later one is not enlarged. Also, secondarily, doesn't enlarge the window itself --- you get enlarged text scrunched up in same size window. Would be nice if defaults for both of these could be changed. === Subject: Re: ChebyshevT command syntax and polynomial question using 21 - 10 x + x^2 I get zero for both answers 1/2 Cos[2 ArcCos[x]] + 43/2 - 10 x also gives me zero for both but when I do a TrigReduce In[148] := 21 - 10 x + x^2 /. x -> Cos[y] // TrigReduce I get Out[149]:= 1/2 (43 - 20 Cos[x] + Cos[2 x]) x=3 gives me 31.88 x=7 gives me 14.0293 Am I doing something wrong or leaving a part out? tia sal2 > > I execute the command and get the following output: > > In[83] := FunctionExpand[1/2 Cos[2 ArcCos[x]] + 43/2 - 10 x] // Expand= > Out[83]:= 21 - 10 x + x^2 > > What would be the proper format to execute the polynomial using > ChebyshevT to do it in reverse order? > > Example: > I would input > In[83] := FunctionExpand[ChebyshevT[n, x]] > and it gives me > Out[83]:= Cos[n ArcCos[x]] > > How can I do a > In[83] := FunctionExpand[ChebyshevT[n, x]] > and it would give me > Out[83]:= 1/2 Cos[2 ArcCos[x]] + 43/2 - 10 x > > Use TrigReduce: > > 21 - 10 x + x^2 /. x -> Cos[y] // TrigReduce === Subject: Re: ContourPlot3D and positive contours > Hello everyone :) Using the ContourPlot3D, how can I plot only the positive contours (or > only the negative ones for that matter=85) > I would imagine an option like this : ContourPlot3D[f,Contours->{#>0&,10}] which would plot the first 10 positive contours. But that does not > exist=85 Right now, I'm plotting the contours of the positive part of my > function like this : ContourPlot3D[1/2*(f+Abs[f]),Contours->{10}] but that's not pretty=85 Is there a better way to do this ? You could try using RegionFunction. Here's is an example: ContourPlot[x^3 - 3 y^2 x, {x, -3, 3}, {y, -3, 3}, RegionFunction -> Function[{x, y, f}, f > 0], Contours -> 20] This should be applicable to 3D as well. === Subject: crosshatch shading I am preparing a graph for publication. I have been able to shade various areas in the graph different colors using the Filling option. However, for publication the paper will be in black and white. I would like to change the shaded areas to be filled in with crosshatches, parallel lines, etc. What are the options and commands to do this? I have looked online, but have not found an answer. === Subject: Re: crosshatch shading Yes, I think you can. Others may have a better way but here is a method using the Presentations package. I use it to hatch the positive lobe of a Sin curve. Basically I draw a set of slanted parallel lines and restrict their extent with a RegionFunction. Needs[Presentations`Master`] Draw2D[ {Draw[Sin[x], {x, 0, 2 [Pi]}], Line[{{0, 0}, {2 [Pi], 0}}], GrayLevel[.5], Draw[# + .5 x, {x, 0, 2 [Pi]}, PlotPoints -> 40, RegionFunction -> Function[{x, y, u}, 0 < y < Sin[x]]] & /@ Range[-1.6, 1, .1]}, PlotRange -> {-1.1, 1.1}, Frame -> True] Here is a method for a stand alone hatched plot without the package. RegionPlot[0 < y < Sin[x], {x, 0, [Pi]}, {y, 0, 1}, ColorFunction -> (White &), BoundaryStyle -> Black, Mesh -> 30, MeshFunctions -> {.5 #1 - #2 &}] And here is the way to combine RegionPlots with other plot elements using Presentations. Draw2D[ {Draw[Sin[x], {x, 0, 2 [Pi]}], Line[{{0, 0}, {2 [Pi], 0}}], RegionDraw[0 < y < Sin[x], {x, 0, [Pi]}, {y, 0, 1}, ColorFunction -> (White &), BoundaryStyle -> Black, Mesh -> 30, MeshFunctions -> {.5 #1 - #2 &}]}, PlotRange -> {-1.1, 1.1}, Frame -> True] -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ >I am preparing a graph for publication. I have been able to shade > various areas in the graph different colors using the Filling option. > However, for publication the paper will be in black and white. I would > like to change the shaded areas to be filled in with crosshatches, > parallel lines, etc. What are the options and commands to do this? I > have looked online, but have not found an answer. > > === Subject: Re: crosshatch shading > I am preparing a graph for publication. I have been able to shade > various areas in the graph different colors using the Filling option. > However, for publication the paper will be in black and white. I would > like to change the shaded areas to be filled in with crosshatches, > parallel lines, etc. What are the options and commands to do this? I > have looked online, but have not found an answer. > > > had this problem in the past, regretfully found no such capability. gradient shading also not to be found. For bar charts, etc. I transferred the data back to Excel. === Subject: Looping in Mathematica Packages.m I know mathematica is a one line type software package but is there a way of looping in a Package.m file. You can use % sign or %%% for 3 lines back but is there a way to go 3 lines back and execute all the successive lines in a Package? === Subject: Re: Looping in Mathematica Packages.m > I know mathematica is a one line type software package but is there a way of looping in a Package.m file. You can use % sign or %%% for 3 lines back but is there a way to go 3 lines back and execute all the successive lines in a Package? > You have to be kidding - Mathematica supports looping in a whole range of styles - how do you think developers produce serious software with it? My general advice would be to go on a training course, but try looking up While, For, Map, MapIndexed, Nest, FixedPoint ..... in the help system and see what you find. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: Question about OneIdentity > (Scroll down for the actual question) > > I never really understood Flat and OneIdentity, and unfortunately > documentation about them is scarce. > > OneIdentity is an attribute that can be assigned to a symbol f to > indicate that f[x], f[f[x]], etc. are all equivalent to x for the > purpose of pattern matching. > > OneIdentity has an effect only if f has attribute Flat. > ** Some comments: > > There is also an example, listing the Attributes of Times and showing > that Times[a] evaluates to a. However, this is misleading because this > behaviour cannot be caused by Times's attributes: > > In[1]:= Attributes[f] = Attributes[Times] > Out[1]= {Flat, Listable, NumericFunction, > OneIdentity, Orderless, Protected} > > In[2]:= f[a] > Out[2]= f[a] > > If we assign the same attributes to f, f[a] will not evaluate to a. Was= > the technical writer also confused, or is the example supposed to > illustrate something different than what I understood? > > ** And now the actual question: > > According to the text in the docs (f[x] is considered equivalent to x in > pattern matching) I would expect > > MatchQ[1, f[1]] > > to give True after evaluating SetAttributes[f, {Flat, OneIdentity}]. > But it gives False. > > ** The application: > > This came up in the following application: > > fun[HoldPattern@Plus[terms__]] := doSomething[{terms}] > > This function should handle a single term, too. Of course, there are > workarounds, but I couldn't come up with anything as simple as the > pattern above (which unfortunately does not work). This doesn't seem very logical to me, but it will work if you add a definition for Default: In[1]:= Attributes[f] = OneIdentity; Default[f] = 0; fun[f[terms_.]] := doSomething[List @@ terms] In[4]:= {fun[f[a, b]], fun[c]} Out[4]= {doSomething[{a, b}], doSomething[c]} Maxim Rytin m.r@inbox.ru === Subject: Re: Does Mathematica really need more printed, introductory documentation? >>Given it has only been a few months since Mathematica 6 was >>released and the time it takes to write any text and get it >>published it should not be surprising there are not any third party >>books on Mathematica yet. But given the number of books published >>for previous versions, it seems certain there will be books for >>version 6 in due time. >Bill, it's been for all practical purposes a _year_ now since >Mathematica 6 was released. Well, I was going to say I did not get version that long ago. But then I checked to see when I got version 6 and indeed it has been nearly a year. I had not realized I had been using version 6 that long. >And though I don't have a cite at hand, I'm sure I've read about how >major software companies, when they have a major emerging project or >upgrade under development, will invite a selected author or authors >with a good track record to come into their company and give them >substantial access to advance knowledge about the developing product >--- with appropriate nondisclosure agreements of course --- just so >their book or manual can appear on the shelves at the same instant >the product is released. >A software company may do this because they don't want to divert >in-house resources from product development to preparing an book for >the emerging product or upgrade --- or they may do this even though >they're developing their own manual also, on the grounds that the >more, the better so far as manuals go; they're in the software >business, not the manual business. >To be frank I just cannot imagine Wolfram Research not having done >the same. I've no idea whether Wolfram has done as you suppose above or not. It seems to me it might be equally reasonable to assume Wolfram made a decision not to support published documentation. But whether or not Wolfram did as you suppose above, there don't seem to be any third party books out yet that reflect version 6. So, either it takes longer than you expect to create and publish such books, no one started as long ago as you might think or no one feels it worthwhile to create such books. Given the number of books published for previous versions, I don't think the last possibility is credible. That is, I expect there will be books out for version 6 at some point. You simply have to wait. Meanwhile, you have access to the same documentation as everyone else. And while I agree, the online documentation doesn't fill every need I might have for documentation it does provide a list of new functions and sufficient information to allow me to use them. Perhaps, it will be necessary to do more work than you would prefer to get the information you want. But this is nothing more than anyone else has to do at this time. === Subject: Help with Manipulate Details of computations omitted; much too complicated, and irrelevant. After lots of computation, showit calls Graphics3D[{........}]. manip2[xyz_] := Module[{xr}, ptvertS[[5]] = xyz; finlist; sphrAll; allspt; setDisp; showit ] m1 = 100; m2 = {m1,m1,m1}; Manipulate[manip2[xyz], {{xyz, {-22, -92, +47}, V5, XYZ}, -m2, m2}] This works fine (at least some of the time), including the initial value and label. ptvertS[[1]],...,ptvertS[[5]] are each just numerical {x,y,z} coordinates. However the 3-part slider no longer has the little symbol which you can expand to see values and control them. Is there a way to see the values of a list in this situation? Currently I use Epilog to display them. *********************** BUT this one does not work, giving an error message something like indeterminate should be triple of numbers. But as an example, manip3[{11,22,33},{44,55,66}] by itself works. manip3[xyz1_, xyz2_] := Module[{xr}, ptvertS[[1]] = xyz1; ptvertS[[2]] = xyz2; finlist; sphrAll; allspt; setDisp; showit ] m1 = 100; m2 = {m1, m1, m1}; Manipulate[manip3[c1, c2], {c1, -m2, m2}, {c2, -m2, m2}] I will appreciate any help. Steve Gray === Subject: Exact Cover Hello All, Someone can help me with this function? ExactCover[matrix] finds all subsets of rows of the rectangular matrix which have exactly one nonzero element in each column. matr = {{0, 0, 1, 0, 1, 1, 0}, {1, 0, 0, 1, 0, 0, 1}, {0, 1, 1, 0, 0, 1, 0}, {1, 0, 0, 1, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 1}, {0, 0, 0, 1, 1, 0, 1}} ExactCover[matr] {{{1, 4}, {3, 5, 6}, {2, 7}}} Johum, === Subject: Re: Exact Cover > Hello All, > > Someone can help me with this function? > > ExactCover[matrix] > > finds all subsets of rows of the rectangular matrix which have exactly one nonzero element in each column. > > matr = {{0, 0, 1, 0, 1, 1, 0}, > {1, 0, 0, 1, 0, 0, 1}, > {0, 1, 1, 0, 0, 1, 0}, > {1, 0, 0, 1, 0, 0, 0}, > {0, 1, 0, 0, 0, 0, 1}, > {0, 0, 0, 1, 1, 0, 1}} > > ExactCover[matr] > > {{{1, 4}, {3, 5, 6}, {2, 7}}} > You did not say what the question was. If you're looking for an implementation, here's one: http://www.imtek.de/simulation//mathematica/IMSweb/imsTOC/Game%20Theory/Exac tCoverDocu.html === Subject: Re: Complex Plot > Hello Jean-Marc, > In 6.0, we can use ContourPlot for implicit equations, but the timing > seems much slower that what you are getting: > > Timing[cp1 = > ContourPlot[Sin[x^2*y] == Log[x/y], {x, -12, 35}, {y, -8, 23}];] > (*about 1 second my machine) > > cp1 > > Timing[cp2 = > > ContourPlot[Sin[x^2*y] == Log[x/y], {x, -12, 35}, {y, -8, > 23},PlotPoints-> 25];] > (*about 3 seconds my machine*) > > cp2 > > Timing[cp3 = > > ContourPlot[Sin[x^2*y] == Log[x/y], {x, -12, 35}, {y, -8, > 23},PlotPoints-> 50];] > (*about 15 seconds my machine*) > > Timing[cp3 = > > ContourPlot[Sin[x^2*y] == Log[x/y], {x, -12, 35}, {y, -8, 23}, > PlotPoints -> 75];] > (*about 36 seconds my machine*) > > The estimate is about 1/2 hour on my machine (if no swapping)... > > So, unless your machine is about 6 times faster than mine, the > implicit version is slower... > > However, PlotPoints->50, seems to be sufficient to see the lovely structure. Hi Graig, My machine is about 10% slower than yours, indeed. (I have just ran the test you provided.) The magic in my original code was to use a high number of points but to turn off the adaptive algorithm by setting the option MaxRecursion to zero. For instance, the fourth plot (75 points) took about 40 seconds with the default settings, while it took only 0.75 second with MaxRecursion->0. That explains the huge discrepancy in timing and why I could claim that it took only few minutes for Mathematica to draw the plot with a sampling of 500 points. (Note that the memory consumption is relatively slow too.) Timing[cp1 = ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, MaxRecursion -> 0, PlotPoints -> 25];] (*about 0.04 seconds my machine*) cp1 Timing[cp2 = ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, MaxRecursion -> 0, PlotPoints -> 25];] (*about 0.07 seconds my machine*) cp2 Timing[cp3 = ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, MaxRecursion -> 0, PlotPoints -> 50];] (*about 0.29 seconds my machine*) cp3 Timing[cp4 = ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, MaxRecursion -> 0, PlotPoints -> 75];] (*about 0.73 seconds my machine*) cp4 > > > > > > Can anyone tell me how I can re-express this > > > equation in terms of x for plotting? > > > > > > Sin[x^2*y]==Log[x/y] > > > > > ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, > > ImageSize -> 500] > > > > ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, > > ImageSize -> 500, ColorFunction -> (White &), ContourStyle -> Black, > > MaxRecursion -> 0, PlotPoints -> 500] > > > > Hope this helps, > > -- Jean-Marc > > > > > > > > -- > W. Craig Carter > -- Jean-Marc === Subject: Re: Complex Plot > >> Can anyone tell me how I can re-express this >> equation in terms of x for plotting? >> >> Sin[x^2*y]==Log[x/y] >> >> last sighted: http://tinyurl.com/3s4hfd > > Hi Chris, > > If you are interested in the graphical representation of this > function, > you may want to use *ContourPlot* and experiment with its various > options. For instance, > > ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, > ImageSize -> 500] > > ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, > ImageSize -> 500, ColorFunction -> (White &), ContourStyle -> Black, > MaxRecursion -> 0, PlotPoints -> 500] > > You can see the result at > > http://homepages.nyu.edu/~jmg336/mathematica/ > chrisdegnencomplexplot.pdf > > Note that the second plot may take several minutes to complete due to > the huge number of sampling points, but it should be very close to > what > you have seen on the Internet. > > Hope this helps, > -- Jean-Marc > I do not think this gives a realistic plot, due to numerous artifices caused by ContourPlot. Here is one way to get a realistic graph without using ContourPlot. We want to plot the set of solutions to: Sin[x^2*y] == Log[x/y] We first use a substitution: x == t y The equation that we get in terms of y and t can now be completely solved by Mathematica: Reduce[Sin[t^2*y^3] == Log[t], y, Reals] Element[C[1], Integers] && 1/E <= t <= E && (y == Root[-#1^3 - ArcSin[Log[t]]/t^2 + (2*Pi*C[1])/t^2 + Pi/t^2 & , 1] || y == Root[-#1^3 + ArcSin[Log[t]]/t^2 + (2*Pi*C[1])/t^2 & , 1]) We can use Plot to get a graph of this: g = Plot[Evaluate[Flatten[ Table[{Root[ -#1^3 - ArcSin[ Log[t]]/t^2 + (2*Pi*n)/t^2 + Pi/t^2 & , 1], Root[-#1^3 + ArcSin[Log[t]]/ t^2 + (2*Pi*n)/ t^2 & , 1]}, {n, -100, 100}]]], {t, 1/E, E}]; Now we can convert this graph into a graph of the relationship we want: Show[g1 = g /. {t_?NumberQ, y_?NumberQ} -> {t y, y}, AspectRatio -> Automatic, PlotRange -> All] This is rather different from the graph displayed at the link above but quite similar to: Show[ContourPlot[Sin[x^2*y] == Log[x/y], {x, -3, 3}, {y, -3, 3}], Axes -> True] Andrzej Kozlowski === Subject: Re: Complex Plot Hello Jean-Marc, In 6.0, we can use ContourPlot for implicit equations, but the timing seems much slower that what you are getting: Timing[cp1 = ContourPlot[Sin[x^2*y] == Log[x/y], {x, -12, 35}, {y, -8, 23}];] (*about 1 second my machine) cp1 Timing[cp2 = ContourPlot[Sin[x^2*y] == Log[x/y], {x, -12, 35}, {y, -8, 23},PlotPoints-> 25];] (*about 3 seconds my machine*) cp2 Timing[cp3 = ContourPlot[Sin[x^2*y] == Log[x/y], {x, -12, 35}, {y, -8, 23},PlotPoints-> 50];] (*about 15 seconds my machine*) Timing[cp3 = ContourPlot[Sin[x^2*y] == Log[x/y], {x, -12, 35}, {y, -8, 23}, PlotPoints -> 75];] (*about 36 seconds my machine*) The estimate is about 1/2 hour on my machine (if no swapping)... So, unless your machine is about 6 times faster than mine, the implicit version is slower... However, PlotPoints->50, seems to be sufficient to see the lovely structure. Craig > > > Can anyone tell me how I can re-express this > > equation in terms of x for plotting? > > > > Sin[x^2*y]==Log[x/y] > > ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, > ImageSize -> 500] > > ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, > ImageSize -> 500, ColorFunction -> (White &), ContourStyle -> Black, > MaxRecursion -> 0, PlotPoints -> 500] > Hope this helps, > -- Jean-Marc > > -- W. Craig Carter === Subject: Re: Complex Plot Chris, I think Jean-Marc has what you need if you just use the Contours->{0} option, then it will show you the answer. It is interesting that the larger you make PlotPoints, the more solutions there are. There is probably some sort of relationship to chaotic functions here. The code below takes a while on my reasonably fast machine, Jean-Marc's original code set PlotPoints to 500 and it took a really long time. Kevin Here is a slight mod on Jean-Marc's code: ContourPlot[Sin[x^2 y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, ImageSize -> 500, ContourShading -> None, ContourStyle -> Red, MaxRecursion -> 0, PlotPoints -> 250, Contours -> {0}, FrameLabel -> {x, y}, PlotLabel -> Contours of Sin[!(*SuperscriptBox[x, 2]) y]-Log[!(*FractionBox[x, y])] = 0, BaseStyle -> {FontFamily -> Arial, FontWeight -> Bold, FontSize -> 14}, FrameStyle -> AbsoluteThickness[2]] > Can anyone tell me how I can re-express this >> equation in terms of x for plotting? >> >> Sin[x^2*y]==Log[x/y] >> >> last sighted: http://tinyurl.com/3s4hfd Hi Chris, If you are interested in the graphical representation of this function, > you may want to use *ContourPlot* and experiment with its various > options. For instance, ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, > ImageSize -> 500] ContourPlot[Sin[x^2*y] - Log[x/y], {x, -12, 35}, {y, -8, 23}, > ImageSize -> 500, ColorFunction -> (White &), ContourStyle -> Black, > MaxRecursion -> 0, PlotPoints -> 500] You can see the result at http://homepages.nyu.edu/~jmg336/mathematica/chrisdegnencomplexplot.pdf Note that the second plot may take several minutes to complete due to > the huge number of sampling points, but it should be very close to what > you have seen on the Internet. Hope this helps, > -- Jean-Marc > -- Kevin J. McCann Research Associate Professor JCET/Physics Physics Building University of Maryland, Baltimore County 1000 Hilltop Circle Baltimore, MD 21250 === Subject: Re: Complex Plot ContourPlot[Sin[x^2*y] == Log[x/y], {x, -4, 4}, {y, -4, 4}, Exclusions -> {y == 0}] Bob Hanlon > Can anyone tell me how I can re-express this > equation in terms of x for plotting? Sin[x^2*y]==Log[x/y] last sighted: http://tinyurl.com/3s4hfd > === Subject: Re: Old Toolbar from 5.2 to 6.0.2 The command is still on the menu, just in a different place: Window > Show Toolbar (It seems to me to be a more logical place to put it than in the old Format menu, but I did have to break an old habit of looking there for it.) This might sound a bit silly, but I really miss the toolbar that > Mathematica 5.2 used to have under the Format > Show Toolbar menu. > Now in current 6.0.2 there doesn't seem to be this simple option. > However, if I open an old Mathematica notebook which was originally > created with 5.2 with a toolbar from within the new 6.0.2, then the > toolbar remains. > Is that the only way to have it? Must I start every notebook in > Mathematica 5.2, assign a toolbar to it, and then open it with > Mathematica 6? Surely not! Can someone help? > Gideon > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: Old Toolbar from 5.2 to 6.0.2 >> >> This might sound a bit silly, but I really miss the toolbar that >> Mathematica 5.2 used to have under the Format > Show Toolbar menu. >> Now in current 6.0.2 there doesn't seem to be this simple option. >> However, if I open an old Mathematica notebook which was originally >> created with 5.2 with a toolbar from within the new 6.0.2, then the >> toolbar remains. >> Is that the only way to have it? Must I start every notebook in >> Mathematica 5.2, assign a toolbar to it, and then open it with >> Mathematica 6? Surely not! > > The Show Toolbar and Show Ruler otpions have been moved to the Window m= enu. You can also set the Toolbar to be turned on by default in the OptionsInspector. Under Global Preferences, open up Notebook Options, then Display Options, and set the WindowToolbars to EditBar. It would be nice if this option were in the Preferences, perhaps on the Interface tab. -- Helen Read University of Vermont === Subject: Re: diff equation [resent a more readable form - moderator] I have an differential equation. I can not solve in mathematica. Would you help me, please? dM/d t =D[d^2 M//dr^2 +(2/r) (dM/dr)]-kM Boundary conditions are: 1-) at t=0, M= Mo 2-) r = 0, dM/dr=0 3-) at r = R, M = Ms .85[CapitalYAcute]r.G.9ar. Ali YILDIRIM Gaziantep .86niversitesi Nizip Meslek Y.9fksekokulu Gàda Teknolojisi Programà 27700-Nizip-Gaziantep/T.9frkiye ayildirim@gantep.edu.tr === Subject: Re: diff equation > [resent a more readable form - moderator] > I have an differential equation. I can not solve in mathematica. > Would you help me, please? dM/d t =D[d^2 M//dr^2 +(2/r) (dM/dr)]-kM -----------!!!----!!!! Not sure for what this D stands here. I discarded it in the example below. Also you have a spurious backslash. So you could write your equation as D[M[r, t], t] == D[M[r, t], r, r] + 2/r D[M[r, t], r] - k M[r, t] > Boundary conditions are: 1-) at t=0, M= Mo M[r, 0] == M0 > 2-) r = 0, dM/dr=0 D[M[0, t], t] == 0 > 3-) at r = R, M = Ms M[R, t] == Ms Then you can use DSolve or NDSolve as in DSolve[{D[M[r, t], t] == D[M[r, t], r, r] + 2/r D[M[r, t], r] - k M[r, t], M[r, 0] == M0, D[M[0, t], t] == 0, M[R, t] == Ms}, M, {r, t}] -- Jean-Marc === Subject: Bilateral cell problem w/ Manipulate Although AuthorTools is considered legacy code for Mathematica 6, I've still been using the bilateral cells palette because I don't know of any other better alternative. Although it still works well, I've found that it sometimes breaks ÷ but sometimes not ÷ when using Manipulate, and I don't know why. The following, for example, can be converted into a bilateral cell (assuming that the three cells are suitably inserted into a notebook): (* This is the text on the left. *) Cell[This is an example of Manipulate., MathCaption] (* Put this in an Input cell *) Manipulate[ Graphics[ Raster[ Table[Block[{r = Random[]}, If[r < t, 1 - r, 1]], {100}, {100}] ] ], {t, 0, 1} ] (* Evaluate the above to get the Output cell. *) (* ... *) However, suppose that the object of the Manipulate isn't a simple graphic, but the output of a Plot like the following: (* Put this in an Input cell. *) Manipulate[ Plot[Sin[a x], {x, 0, 2 Pi}], {a, 0, 10} ] If you try to convert that Manipulate into a bilateral cell, you get an error. On my machine (an Intel Mac), I just get a grey rectangle inside the Manipulate construct (in the bilateral cell). If I position the mouse over the grey rectangle, I get the message: This dynamic content could not be displayed because dynamic updating has been disabled in the Evaluation menu. Except, dynamic updating hasn't actually been disabled in the evaluation menu ÷ other dynamic objects can still be manipulated in the notebook. However, if you save the notebook containing the broken bilateral cell, restart Mathematica, and then load the notebook, the bilateral cell works! Any suggestions as to what might be going wrong would be appreciated. I find the cell manipulations performed by MakeBilateralCell a bit mysterious, to say nothing of the magic that happens with Manipulate! Jason Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm === Subject: Re: Bilateral cell problem w/ Manipulate > Although AuthorTools is considered legacy code for Mathematica 6, > I've still been using the bilateral cells palette because I don't know = > of any other better alternative. Although it still works well, I've > found that it sometimes breaks =97 but sometimes not =97 when using > Manipulate, and I don't know why. You might consider trying the new Grid, Row, Column, and GraphicsGrid, GraphicsRow, GraphicsColumn instead of the bilateral cells. -- Helen Read University of Vermont === Subject: Mathematica student certification now available Mathematica Student Certification Now Available Wolfram Research is pleased to announce the Mathematica Student Certification Program to support our student users. Mathematica Student Certification can give student resum.8es the competitive edge needed in many career fields. Many businesses are looking for employees who can solve problems in a quick, efficient manner--which is something Mathematica users can do. Students who want to demonstrate and receive recognition for their Mathematica skills are invited to take the Certification test. More details are available at the Mathematica Student Certification Program: http://www.wolfram.com/services/certification === Subject: Re: Mathematica student certification now available It would be fun for the community to develop a professional version of such a test, with questions taken from this group that show up over and over, year after year. question #1: what does @@@ do? question #2: how to get a high-resolution publication-quality pdf question #3: is Sqrt[] broken? question #4: how do you get Solve[] to product results using litzghoff-weitzerstrauss notation ( trick question ) < your contribution here.. > > Mathematica Student Certification Now Available > > Wolfram Research is pleased to announce the Mathematica Student > Certification Program to support our student users. Mathematica > Student Certification can give student resum=E9s the competitive > edge needed in many career fields. Many businesses are looking > for employees who can solve problems in a quick, efficient > manner--which is something Mathematica users can do. Students who > want to demonstrate and receive recognition for their Mathematica > skills are invited to take the Certification test. > > More details are available at the Mathematica Student > Certification Program: > http://www.wolfram.com/services/certification > > === Subject: Re: Assigning multiple variables within a Block[] statement (e.g. > What I'm trying to do: > I have a list of parameters that I am using across several functions. I am > trying to come up with a good way to avoid copying/pasting these parameter > assignments everywhere. Here is an example code that sort of accomplishes > this goal: (Suppose my parameters are a,b, and c) paramlist = {a -> 1, b -> 4, c -> 8}; > paramlistnames = First /@ paramlist; foobar2[x_] := Block[Evaluate[Flatten[{paramlistnames, {d, e, f}}]], > {a, b, c} = paramlistnames /. paramlist; > {d,e,f} = {1,1,1}; > x*a*b*c*d*e*f > ] The line > {a, b, c} = paramlistnames /. paramlist; > effectively sets a, b, and c to their values, at which point I can proceed > with the rest of the function. Questions: > 1. Is this the most effective way to accomplish the task at hand? If no, > what is? I think you are fooling yourself. Using Block (or Module) mainly serves the purpose of scoping, which doesn't work if you do it this way. To see what I mean evaluate the following: foobar2[5] a=2 foobar2[5] You need to be more careful about evaluation when doing this. One possibility would be: foobar3[x_] := Block @@ Join[ Replace[Hold[Evaluate@Join[ Flatten[ Extract[OwnValues[paramlistnames], {1, 2}, Hold] /. List -> Hold], Hold[d, e, f] ]], Hold -> List, {2}, Heads -> True], Hold[ {a, b, c} = List @@ paramlistnames /. List @@ paramlist; {d, e, f} = {1, 1, 1}; x*a*b*c*d*e*f ] ] As you can note, there is extra effort necessary to avoid early evaluation. Maybe this can be done more elegant than what I have come up with. Note that you need to access the ownvalue of paramlistnames directly to avoid early evaluation of the parameternames and you have to take care to define your parameters before any of their names get any definition. This can be avoided by e.g. wrapping your parameterlist with Hold instead of List, which also can make the later handling easier. However you achieve to avoid early evaluation at the various stages, you might want to define something like: SetAttributes[ParameterBlock, HoldRest] ParameterBlock[params_, {vardefs___}, body_] := Apply[ Block, Join[ Replace[ Hold[Evaluate@Join[params /. Rule -> Set, Hold[vardefs]]], Hold -> List, {2}, Heads -> True ], Hold[body] ] ] which will make possible to define your parameters and functions as e.g.: $parameter = Hold[a -> 1, b -> 4, c -> 8] foobar4[x_] := ParameterBlock[$parameter, {d = 1, e = 1, f}, f = 1; x*a*b*c*d*e*f ] > 2. Note that I still have to explicitly use {a, b, c} = paramlistnames /. > paramlist; something like Hold[paramlistnames] = paramlistnames /. > paramlist; results in an error message. Is there a way to do the assignment > but use the paramlistnames somehow so that I don't have to name the > variables explicitly? the above definition of ParameterBlock solves this, too. If you want to understand what it does it is best to replace the Block with Hold, then you will see the (held) expression which Block is applied to and can check that it basically is what you want (I think you want) it to be... A last remark: you probably should look into how Options work for Mathematica functions, which is the standard way of handling what seems to be part of your problem... hth, albert === Subject: Re: Assigning multiple variables within a Block[] statement (e.g. Hi Leo, For question 2, you could use a line like: Set[Evaluate[paramlistnames], paramlistnames /. paramlist] Good luck! > What I'm trying to do: > I have a list of parameters that I am using across several functions. I am > trying to come up with a good way to avoid copying/pasting these parameter > assignments everywhere. Here is an example code that sort of accomplishes > this goal: (Suppose my parameters are a,b, and c) > > paramlist = {a -> 1, b -> 4, c -> 8}; > paramlistnames = First /@ paramlist; > > foobar2[x_] := Block[Evaluate[Flatten[{paramlistnames, {d, e, f}}]], > {a, b, c} = paramlistnames /. paramlist; > {d,e,f} = {1,1,1}; > x*a*b*c*d*e*f > ] > > The line > {a, b, c} = paramlistnames /. paramlist; > effectively sets a, b, and c to their values, at which point I can proceed > with the rest of the function. > > Questions: > 1. Is this the most effective way to accomplish the task at hand? If no, > what is? > > 2. Note that I still have to explicitly use {a, b, c} = paramlistnames /. > paramlist; something like Hold[paramlistnames] = paramlistnames /. > paramlist; results in an error message. Is there a way to do the assignment > but use the paramlistnames somehow so that I don't have to name the > variables explicitly? > > > --Leo === Subject: Re: Assigning multiple variables within a Block[] statement (e.g. {a,b} = {c,d}) Why not define your functions with the list of parameters? currentparms = {1, 4, 8}; foobar3[parmlist : {_, _, _}][x_] := Module[{a, b, c, d, e, f}, {a, b, c} = parmlist; {d, e, f} = {1, 1, 1}; x a b c d e f] foobar3[currentparms][x] 32 x -- David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ > What I'm trying to do: > I have a list of parameters that I am using across several functions. I > am > trying to come up with a good way to avoid copying/pasting these parameter > assignments everywhere. Here is an example code that sort of accomplishes > this goal: (Suppose my parameters are a,b, and c) > > paramlist = {a -> 1, b -> 4, c -> 8}; > paramlistnames = First /@ paramlist; > > foobar2[x_] := Block[Evaluate[Flatten[{paramlistnames, {d, e, f}}]], > {a, b, c} = paramlistnames /. paramlist; > {d,e,f} = {1,1,1}; > x*a*b*c*d*e*f > ] > > The line > {a, b, c} = paramlistnames /. paramlist; > effectively sets a, b, and c to their values, at which point I can proceed > with the rest of the function. > > Questions: > 1. Is this the most effective way to accomplish the task at hand? If no, > what is? > > 2. Note that I still have to explicitly use {a, b, c} = paramlistnames /. > paramlist; something like Hold[paramlistnames] = paramlistnames /. > paramlist; results in an error message. Is there a way to do the > assignment > but use the paramlistnames somehow so that I don't have to name the > variables explicitly? > > > --Leo > > > === Subject: ExtraAxes for Plot[] maybe this is valuable for some of you. Below you can find a Mathematica Package containing 2 Functions one for additional X-Axes generation and one for Y-Axes. The additional Axes are included in the Epilog of Plot. Plot[......, Epilog -> {..., ExtraXAxes[......], ...} ] Multiple Axes in both directions can be specifyed. Standard Mathematica Axes Options such as TicksStyle or AxesStyle can be used. Below the Package you can find an example (* start of package code *) BeginPackage[ExtraAxes`] {InsertStartPos,InsertEndPos},YInsertPos]<>n<> step TickStep.<>n<> tThe additional Axes is inserted from x: InsertStartPos to InsertEndPos at y: YInsertPos.<>n<> tOptions can be passed e.g. TicksStyle- >Directive[{Blue,Thick}]<>n<> tInclude the additional Axes by means of Epilog->ExtraXAxes[] {InsertStartPos,InsertEndPos},XInsertPos]<>n<> step TickStep.<>n<> tThe additional Axes is inserted from y: InsertStartPos to InsertEndPos at x: XInsertPos.<>n<> tOptions can be passed e.g. TicksStyle- >Directive[{Blue,Thick}]<>n<> tInclude the additional Axes by means of Epilog->ExtraYAxes[] Begin[`Private`] ExtraXAxes[{from_,to_,step_},{xpos_,xend_},ypos_,opts_:{}]:= Graphics[{},AspectRatio->Full,ImagePadding->0,Axes- >{True,False},Sequence@opts, PlotRange->{{from-1/2 step,to+1/2 step},0{-1,1}},Ticks->{Table[i, {i,from,to,step}],None}]//Inset[#,{xpos,ypos},{from,0},((step (xend- xpos))/(to-from)+xend-xpos){1,1}]& ExtraYAxes[{from_,to_,step_},{ypos_,yend_},xpos_,opts_:{}]:= Graphics[{},AspectRatio->Full,ImagePadding->0,Axes- >{False,True},Sequence@opts, PlotRange->{0{-1,1},{from-1/2 step,to+1/2 step}},Ticks->{None,Table[i, {i,from,to,step}]}]//Inset[#,{xpos,ypos},{0,from},((step (yend-ypos))/ (to-from)+yend-ypos){1,1}]& End[] EndPackage[] (* start sample test code *) Plot[{Sin[x],2+Cos[x]},{x,0[Pi],3[Pi]},ImageSize->600,PlotRange- >All,PlotStyle->{Black,Blue}, Epilog->{ExtraXAxes[{1/2[Pi],3/2[Pi],[Pi]/8},{1/2[Pi],3/2[Pi]}, 2,TicksStyle->Directive[Darker@Magenta,Italic, Bold]],ExtraYAxes[{-150,350,50},{-1.5,3.5},8,{TicksStyle- >Directive[Blue,Large],AxesStyle->Directive[Orange,Thick]}]}] === Subject: Convert funcion Hello Group, Someone could help me with this function? fConver[cmatrix], this function will find all subsets of rows of the rectangular matrix which have exactly one nonzero element in each column. For example: cmatrix=({{0,0,1,0,1,1,0},{1,0,0,1,0,0,1},{0,1,1,0,0,1,0}, {1,0,0,1,0,0,0},{0,1,0,0,0,0,1},{0,0,0,1,1,0,1}}); fConvert[cmatrix] the out put will be {{{1,4},{3,5,6},{2,7}}} Johum, === Subject: Re: Convert funcion > > Hello Jean-Marc, > > Yes, I am try to solve the Latin Square Puzzle problem, therefore I need > this function. Do you know how to implement this function?. > > > Johum S. > > Since you seem to have taken your example from the documentation of > the Imtek`ExactCover` function, available at > > http://www.imtek.de/simulation//mathematica/IMSweb/imsTOC/Game%20Theory/Exact CoverDocu.html > > it is not clear why you would not use it as it is? Dis you try it? Did > you face any difficulty or get any erroneous results? What would you do > with such a function? Perhaps solving the Latin Square Puzzle or the > Height Queens Puzzle? I do not know (and I do not bother to know) how to write such a function since the function has already been implemented (nicely) in the IMS (IMTEK Mathematica Supplement) package, which is an *open source* package. *Open source* means that the source code is available free of charge. Therefore, if I were you, I would download the IMS package, install it on my machine, then I would play around with the function *ExactCover* to get acquainted with it (the documentation have some examples about Latin squares) and I would look at its code (which is provided with package) if I wish. The IMS main web page contains links to the download area as well as directions to install the package. http://www.imtek.uni-freiburg.de/simulation/mathematica/IMSweb/ -- Jean-Marc === Subject: Re: Convert funcion > Someone could help me with this function? fConver[cmatrix], this function will find all subsets of rows of the rectangular matrix which have exactly one nonzero element in each column. For example: cmatrix=({{0,0,1,0,1,1,0},{1,0,0,1,0,0,1},{0,1,1,0,0,1,0}, > {1,0,0,1,0,0,0},{0,1,0,0,0,0,1},{0,0,0,1,1,0,1}}); > fConvert[cmatrix] the out put will be > {{{1,4},{3,5,6},{2,7}}} Since you seem to have taken your example from the documentation of the Imtek`ExactCover` function, available at http://www.imtek.de/simulation//mathematica/IMSweb/imsTOC/Game%20Theory/Exac tCoverDocu.html it is not clear why you would not use it as it is? Dis you try it? Did you face any difficulty or get any erroneous results? What would you do with such a function? Perhaps solving the Latin Square Puzzle or the Height Queens Puzzle? -- Jean-Marc === Subject: Inverse of symbolic matrix The expressions a and b below seem reasonable. However when I assemble them into a matrix and take the inverse I get the message Inverse::sing :Matrix...is singular. However the determinant seems fine. If I rationalize the matrix and then take its inverse then everything seems fine and I can almost get the unit matrix by multiplying back onto the original matrix. Is there a problem with approximate numbers in symbolic matrices? Is this a bug? Is Rationalize the best method for working around this problem? Hugh Goyder a = -((4.739*^-6 - 0.0008*I)/((0.0122 + 1.544*I) + s)) - (4.7395*^-6 + 0.00088*I)/ ((0.0122 - 1.544*I) + s); b = -((0.000015 - 0.00022*I)/((0.0122 + 1.544*I) + s)) - (0.000015 + 0.000226*I)/ ((0.0122 - 1.544*I) + s); mat = {{a, 0}, {0, b}}; Inverse[mat] Det[mat] matr = Rationalize[mat, 0]; inv = Inverse[matr] Rationalize[Factor[Together[mat . inv]], 1.*^-8] === Subject: Re: Inverse of symbolic matrix > The expressions a and b below seem reasonable. However when I assemble > them into a matrix and take the inverse I get the message > Inverse::sing :Matrix...is singular. However the determinant seems > fine. If I rationalize the matrix and then take its inverse then > everything seems fine and I can almost get the unit matrix by > multiplying back onto the original matrix. Is there a problem with > approximate numbers in symbolic matrices? The issue is whenever you mix machine-size numbers with symbolic or exact arithmetic entries, the machine-size numbers poison the symbolic/exact matrix, which is not symbolic anymore. So 1.0 is not the same as 1 w.r.t. the accuracy of each entry and the numeric stability that result of different algorithms in use with each computational model. > Is this a bug? No. > Is Rationalize the best method for working around this problem? Rationalize as early as possible (see below). Note the given matrix is not invertible for s == -0.0122 - 1.544 I or s == -0.0122 + 1.544 I > Hugh Goyder a = -((4.739*^-6 - 0.0008*I)/((0.0122 + 1.544*I) + > s)) - (4.7395*^-6 + 0.00088*I)/ > ((0.0122 - 1.544*I) + s); b = -((0.000015 - 0.00022*I)/((0.0122 + 1.544*I) + > s)) - (0.000015 + 0.000226*I)/ > ((0.0122 - 1.544*I) + s); mat = {{a, 0}, {0, b}}; Inverse[mat] Det[mat] matr = Rationalize[mat, 0]; inv = Inverse[matr] Rationalize[Factor[Together[mat . inv]], 1.*^-8] Here is an example of how to deal with your matrix so exact arithmetic is use all along the computations. In[1]:= a = Simplify[ Map[Rationalize[#, 0] &, -((4.739*^-6 - 0.0008*I)/((0.0122 + 1.544*I) + s)) - (4.7395*^-6 + 0.00088*I)/((0.0122 - 1.544*I) + s), Infinity]] b = Simplify[ Map[Rationalize[#, 0] &, -((0.000015 - 0.00022*I)/((0.0122 + 1.544*I) + s)) - (0.000015 + 0.000226*I)/((0.0122 - 1.544*I) + s), Infinity]] mat = {{a, 0}, {0, b}} inv = Inverse[mat] Factor[Together[mat.inv]] Reduce[Denominator[Simplify[Det[mat]]] == 0] % // N Out[1]= (-25938043623 + 9767720 I) + (94785000 + 800000000 I) s -(-------------------------------------------------------) 2 400000 (59602121 + 610000 s + 25000000 s ) Out[2]= (-1720645 + 183 I) + (75000 + 15000 I) s -(----------------------------------------) 2 100 (59602121 + 610000 s + 25000000 s ) Out[3]= (-25938043623 + 9767720 I) + (94785000 + 800000000 I) s {{-(-------------------------------------------------------), 0}, 2 400000 (59602121 + 610000 s + 25000000 s ) (-1720645 + 183 I) + (75000 + 15000 I) s {0, -(----------------------------------------)}} 2 100 (59602121 + 610000 s + 25000000 s ) Out[4]= 2 400000 (59602121 + 610000 s + 25000000 s ) {{-(-------------------------------------------------------), 0}, (-25938043623 + 9767720 I) + (94785000 + 800000000 I) s 2 100 (59602121 + 610000 s + 25000000 s ) {0, -(----------------------------------------)}} (-1720645 + 183 I) + (75000 + 15000 I) s Out[5]= {{1, 0}, {0, 1}} Out[6]= 61 193 I 61 193 I s == -(----) - ----- || s == -(----) + ----- 5000 125 5000 125 Out[7]= s == -0.0122 - 1.544 I || s == -0.0122 + 1.544 I -- Jean-Marc === Subject: Re: For help about NSolve Hello xxhai, It does give a solution (perhaps not unique), but not a very interesting one: ode = D[y[x], {x, 2}] + y[x] (1 + D[y[x], x]^(3/2)) nsol = NDSolve[{ode == 0, y[0] == 0, y[1] == 0}, y[x], x] Plot[y[x] /. nsol, {x, 0, 1}] Table[y[x] /. nsol, {x, 0, 1, .1}] However ode = D[y[x], {x, 2}] + y[x] (1 + D[y[x], x]^(3/2)) nsol = NDSolve[{ode == 0, y[0] == 0, y[1] == 1}, y[x], x] Plot[y[x] /. nsol, {x, 0, 1}] is more interesting---perhaps the question is in regard to your boundary conditions? If not, take a look at the option Method and the final example in NDSolve (6.0 Documentation) Best Wishes, Craig > Differential Equation: > y[x]''+y[x]*{(1+y[x]'^2)}^(3/2)=0 > > aboundery condition: y[0]=0, y[1]=0 > > For Numerical Solution ? > > why Mathematica can't solve the Equation with the initial condition ? > > please give the correct program for differential equation. > > > thank you a lot. > > > -- W. Craig Carter === Subject: For help about NSolve Differential Equation: y[x]''+y[x]*{(1+y[x]'^2)}^(3/2)=0 aboundery condition: y[0]=0, y[1]=0 For Numerical Solution ? why Mathematica can't solve the Equation with the initial condition ? please give the correct program for differential equation. thank you a lot. === Subject: Re: For help about NSolve > Differential Equation: > y[x]''+y[x]*{(1+y[x]'^2)}^(3/2)=0 aboundery condition: y[0]=0, y[1]=0 For Numerical Solution ? why Mathematica can't solve the Equation with the initial condition ? please give the correct program for differential equation. > thank you a lot. (* Here is an example of how to use NDSolve and its result *) nsol = NDSolve[{y''[x] + y[x]*((1 + y'[x]^2))^(3/2) == 2, y[0] == 0, y[1] == 0}, y, {x, 0, 1}] Plot[y[x] /. nsol[[1]], {x, 0, 1}] Table[y[x] /. nsol[[1]], {x, 0, 1, 0.1}] (* As given, your original equation has y(x) = 0 as solution *) nsol = NDSolve[{y''[x] + y[x]*((1 + y'[x]^2))^(3/2) == 0, y[0] == 0, y[1] == 0}, y, {x, 0, 1}] Plot[y[x] /. nsol[[1]], {x, 0, 1}] Table[y[x] /. nsol[[1]], {x, 0, 1, 0.1}] -- Jean-Marc === Subject: Re: For help about NSolve 2008/5/2 wtpdrj <45417003@163.com>: > > > This is the result. > > > why ? [Cross-posted to comp.soft-sys.math.mathematica aka MathGroup] ode = y''[x] + y[x]*(1 + y'[x])^(3/2) nsol = NDSolve[{ode == 0, y[0] == 0, y[1] == 0}, y, {x, 0, 1}] Plot[y[x] /. nsol[[1]], {x, 0, 1}] Table[y[x] /. nsol[[1]], {x, 0, 1, 0.1}] Works fine on my system. $Version 6.0 for Mac OS X x86 (64-bit) (February 7, 2008) See http://homepages.nyu.edu/~jmg336/mathematica/helpaboutndsolve.pdf I suspect that you are using a version prior 6.0 and that NDSolve has been improved meanwhile. > > .8c[Thorn]¬2008-05-01.95.b9ÔJean-Marc Gulliet .8cºú.8eªã.95.b9û > > > > > Differential Equation: > y[x]''+y[x]*{(1+y[x]'^2)}^(3/2)=0 > > aboundery condition: y[0]=0, y[1]=0 > > For Numerical Solution ? > > why Mathematica can't solve the Equation with the initial condition ? > > please give the correct program for differential equation. > > > thank you a lot. > > (* Here is an example of how to use NDSolve and its result *) > nsol = NDSolve[{y''[x] + y[x]*((1 + y'[x]^2))^(3/2) == 2, y[0] == 0, > y[1] == 0}, y, {x, 0, 1}] > Plot[y[x] /. nsol[[1]], {x, 0, 1}] > Table[y[x] /. nsol[[1]], {x, 0, 1, 0.1}] > > (* As given, your original equation has y(x) = 0 as solution *) > nsol = NDSolve[{y''[x] + y[x]*((1 + y'[x]^2))^(3/2) == 0, y[0] == 0, > y[1] == 0}, y, {x, 0, 1}] > Plot[y[x] /. nsol[[1]], {x, 0, 1}] > Table[y[x] /. nsol[[1]], {x, 0, 1, 0.1}] > > -- Jean-Marc > > -- Jean-Marc === Subject: Locator Hi Everyone, Very recently I started using Mathematica with the hopes of accomplishing the following. I have had some progress by using extensively the documentation center, however, any help will be really appreciated. I have 2 questions in particular and have described them below: I have created 3 notebooks with the following command: lst = Table[ NotebookCreate[WindowSize -> {240, 240}, WindowTitle -> new, WindowMargins -> {{RandomInteger[{0, 100}], Automatic}, { Automatic, RandomInteger[{0, 50}]}}], {3}]; newlst=Map[WindowMargins /. Options@# &, Select[Notebooks[], StringMatchQ[(WindowTitle /. NotebookInformation[#]), new] &]] I then retrieve the notebook locations for the 3 notebooks. coord = Map[({#[[1, 1]], #[[2, 2]] }) &, newlst] Finally, I want to create locators for each of the above notebooks, such that when I move the locators the notebooks are moved. In other words, the {x,y} position of the locators is mapped to the WindowMargins of that particular notebook. I have successfully created the locators but I have no clue how to map the locators such that the notebooks are moved. Below is the code for it: DynamicModule[{pt = new1}, LocatorPane[Dynamic[pt], Dynamic@ ListPlot[pt, AxesOrigin -> {0, 0}, PlotRange -> {{0, 100}, {0, 50}}]]] I can move the locators, but with the moving of locators I need to the move corresponding notebook. Any help would be of great help Ekta === Subject: plot a function I have X=f(Y) (i know the analytical form, but this isn't easy to invert) how do i plot Plot[ Y, {x, xmin, xmax} ] === Subject: Re: plot a function > I have > > X=f(Y) (i know the analytical form, but this isn't easy to > invert) > > how do i plot > > Plot[ Y, {x, xmin, xmax} ] ParametricPlot[{f[y], y}, {y, ymin, ymax}] You will have to figure out ymin and ymax on your own, but that should be easy using Solve/NSolve. === Subject: list of dates I have a list of dates in the format YYYY-MM-DD and I want to convert them to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly to 85.5. Any suggestions on the best way to do this? Roger === Subject: Re: list of dates > I have a list of dates in the format YYYY-MM-DD and I want to convert them > to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly > to 85.5. Any suggestions on the best way to do this? It is not possible to do this in a precise way because years don't pass linearly. Leap years are longer than non-leap years. So we have to make a compromise: if y1, y2, y3, and y4 are the floating point numbers you use to represent dates, it will either not be true that if (y2-y1) == (y4 - y3) then the time interval between y1 and y2 has the same length as the interval between y3 and y4; or the date 19AB-01-01 might not be converted to the exact integer AB. dateToFloat[date_String] := dateToFloat[1963-01-01] 62.9997 dateToFloat[1985-07-01] 85.4972 If you use different anchors than 1900-01-01 and 2000-01-01, then you'll get slightly different results. I hope this helps, Szabolcs === Subject: Re: list of dates > I have a list of dates in the format YYYY-MM-DD and I want to convert them > to a decimal value, so 1963-01-01 goes to 63.0 and 1985-07-01 goes roughly > to 85.5. Any suggestions on the best way to do this? To help you started, the following function assume an input date as a string and that a year as 360 days (i.e. 12 months of 30 days). yy = yy - 1900; td = 30 (mm - 1) + dd; yy + Rescale[td, {1, 360}] // N ] Out[79]= 63. Out[80]= 85.5014 -- Jean-Marc === Subject: DSolve Issues I am solving the following Differential Equation Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some constant) ; kinda has a cos/sin solution 2.71828^(-0.323232 [ImaginaryI] r) ((0.+ 0. [ImaginaryI]) + (0.+ 0. [ImaginaryI]) 2.71828^( 0.646465 [ImaginaryI] r) + (0.+ 1.54687 [ImaginaryI]) K - (0.+ 1.54687 [ImaginaryI]) 2.71828^(0.646465 [ImaginaryI] r) K) all divided by r. My problem is that Mathematica is not treating those zeros.... as well zeros. Thus, the solution cannot really be used. In fact, if I manually reproduce the solution and remove those zeros, then the solution is fine. I have another similar ODE Anyone have any ideas. Phi''[r]+2*r^(-1)Phi'[r]- 287.31*Phi[r]==0 and Phi[3R]==0(some constant) ; kinda has a cosh/sinh solution As you might have notice I need to match these two solutions and their derivatives at some point. The ratio of which gives me what I desire the value of R. Yet, Mathematica treats those zeros as something else. === Subject: Wolfram Workbench user experiences I would be very interested in other people's experiences with the Wolfram Workbench. I must admit that I prefer to use the frontend as my 'IDE', and the workbench seemed fairly alien when I tried it. David Bailey http://www.dbaileyconsultancy.co.uk === Subject: Re: partial differential equation of diffusion > > > > > When I was clear my equation, the resulting one is bellow. > > > dM/d t =a[d^2 M//dr^2 +(2/r) (dM/dr)]-kM > The differentials are partial differentials. > a and k are constants. > > >Could you write now, please? [Note that it is better to ask/post questions directly to MathGroup rather than to send it to a specific person.] Do you mean that you do not know how to multiply expressions with Mathematica? If this is the case you should familiarize yourself with the basis of Mathematica syntax, this will really help you and be a time saver in the future. D[M[r, t], t] == a*(D[M[r, t], r, r] + (2/r)*D[M[r, t], r]) - k*M[r, t] > > > ÌöÄÄr.GÌ.a6r. Ali YILDIRIM > Gaziantep Ì[Thorn]niversitesi > Nizip Meslek YÌ.b9ksekokulu > Gıda Teknolojisi Programı > 27700-Nizip-Gaziantep/TÌ.b9rkiye > ayildirim@gantep.edu.tr > -----------!!!----!!!! > Not sure for what this D stands here. I discarded it in the example > below. Also you have a spurious backslash. So you could write your > equation as > > D[M[r, t], t] == D[M[r, t], r, r] + 2/r D[M[r, t], r] - k M[r, t] > >> Boundary conditions are: >> >> 1-) at t=0, M= Mo > > M[r, 0] == M0 > >> 2-) r = 0, dM/dr=0 > > D[M[0, t], t] == 0 > >> 3-) at r = R, M = Ms > > M[R, t] == Ms > > Then you can use DSolve or NDSolve as in > > DSolve[{D[M[r, t], t] == > D[M[r, t], r, r] + 2/r D[M[r, t], r] - k M[r, t], M[r, 0] == M0, > D[M[0, t], t] == 0, M[R, t] == Ms}, M, {r, t}] > > > > -- Jean-Marc === Subject: Axes at the origin, for 3D plots/graphs Does anyone know of a way to move the axes from the outside of the box and have it centered at the origin instead? I know you can draw lines using the graphics function to do this but it looks bad. I am looking for something similar to how you can move the axes using AxisOrigin for 2D plots. === Subject: Re: function to check if array is empty Your array is hardly empty: it's full of zeros! If what you want to do is test to see whether every entry is 0, the following will do it: And @@ Thread[0 == Flatten @ X] ] this probably already exists, but I can't find it anywhere: is there a function that will check if an array is empty? i'm looking for a function to return either True (or 1), or False (or 0) when it checks an array. eg: X = Array[0 &, {3, 3}] then test with function (called ArrayEmpty, for example) In: ArrayEmpty[X] Out: True best wishes, Will > -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: function to check if array is empty Will, a null row is a list of one or more 0's {(0)..} and a null matrix is a list of one or more null rows {{(0)..}..}, so In[4]:= MatchQ[X, {{(0) ..} ..}] Out[4]= True and ArrayEmpty=MatchQ[#, {{(0) ..} ..}]& If you want to match both exact and approximate 0's replace (0).. with (0|0.).. Adriano Pascoletti > > this probably already exists, but I can't find it anywhere: > > is there a function that will check if an array is empty? > > i'm looking for a function to return either True (or 1), or False (or 0) > when it checks an array. eg: > > X = Array[0 &, {3, 3}] > > then test with function (called ArrayEmpty, for example) > > In: ArrayEmpty[X] > > Out: True > > best wishes, > > Will > > === Subject: function to check if array is empty this probably already exists, but I can't find it anywhere: is there a function that will check if an array is empty? i'm looking for a function to return either True (or 1), or False (or 0) when it checks an array. eg: X = Array[0 &, {3, 3}] then test with function (called ArrayEmpty, for example) In: ArrayEmpty[X] Out: True best wishes, Will === Subject: Re: function to check if array is empty > is there a function that will check if an array is empty? i'm looking for a function to return either True (or 1), or False (or 0) when it checks an array. eg: X = Array[0 &, {3, 3}] then test with function (called ArrayEmpty, for example) In: ArrayEmpty[X] Out: True If you deal only with m x n rectangular arrays (matrices) you could use ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] A more general function would be ArrayEmptyQ[arr_List] := If[Count[arr, x_ /; x != 0, -1] != 0, False, True] For instance, X = Array[0 &, {3, 3}] ArrayEmptyQ[arr_List] := MatrixQ[arr, (# == 0 &)] ArrayEmptyQ[X] X[[1, 2]] = 1; X ArrayEmptyQ[X] {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}} True {{0, 1, 0}, {0, 0, 0}, {0, 0, 0}} False -- Jean-Marc === Subject: Re: Transforming a polynomial into a trigonometric format tia sal2 I think what you want is this function: Chebyshev[f_, x_] := With[{n = Exponent[f, x]}, Sum[a[i]*Cos[i ArcCos[x]], {i, 0, n}] /. SolveAlways[f == Sum[a[i]*ChebyshevT[i, x], {i, 0, n}], x][[1]]] So now, for example: Chebyshev[21 - 10*x + x^2, x] -10*x + (1/2)*Cos[2*ArcCos[x]] + 43/2 TrigExpand[%] x^2 - 10*x + 21 Chebyshev[21 - 10*x + x^2 + 3*x^3, x] -((31*x)/4) + (1/2)*Cos[2*ArcCos[x]] + (3/4)*Cos[3*ArcCos[x]] + 43/2 and so on. Andrzej Kozlowski > I'm sorry if I didn't explain myself better I hope this clarifies it > better > > when I test for x =3 x= 7 for equation: > 21 - 10 x + x^2 I get zero for both answers > > I used another math program using the ChebyshevT command and I > got this > 1/2 Cos[2 ArcCos[x]] + 43/2 - 10 x I tested with x=3 and x=7 and I > also got zero for both > > but when I do a TrigReduce > > In[148] := 21 - 10 x + x^2 /. x -> Cos[y] // TrigReduce > > I get > > Out[149]:= 1/2 (43 - 20 Cos[x] + Cos[2 x]) > x=3 gives me 31.88 > x=7 gives me 14.0293 > > I would like to use the ChebyshevT in mathematica 6 because I prefer > that software but I'm not sure > how to get the 1/2 Cos[2 ArcCos[x]] + 43/2 - 10 x answer in > mathematica 6 > > Am I doing something wrong with the TrigReduce function or leaving a > part out why are the answers not even close? > > tia sal2 > >> Transforming a polynomial into a trigonometric format tiasal2 >> >> >> I'm using mathematica 6 and I have a polynomial and would like to >> convert it into >> a Trigonometric format. Is this possible? >> >> Example: >> I have a polynomial >> 0.00154991- 4.01371 x + 1.81197 x^2 + 8.00183 x^3 - 9.3462 x^4 >> >> How can I transform this into a trigonometric format >> Example: >> 0.00596679 Cos[6.98132 x] + 0.00358397 Cos[7.21403 x] + >> 2.25013 Sin[0.232711 x] - 4.51511 Sin[0.465421 x] >> >> Note: these aren't correct answers I just wanted to include and >> example >> >> tiasa > === Subject: Re: Transforming a polynomial into a trigonometric format tia sal2 Actually the TrigReduce approach I posted does the same thing, one just has to substitute ArcCos[x] for the y variable. Here's a complete function: chebyshev2[f_, x_] := Module[{y}, Expand@TrigReduce[f /. x -> Cos[y]] /. y -> ArcCos[x]] (Applying Expand is not really necessary. In this case it ensures that chebyshev[] will give the result in the same form as Chebyshev[].) Szabolcs > It is slightly better to localize the symbol a: > > Chebyshev[f_, x_] := > Module[{a, n = Exponent[f, x]}, > > Sum[a[i]*Cos[i ArcCos[x]], {i, 0, n}] /. > SolveAlways[f == Sum[a[i]*ChebyshevT[i, x], {i, 0, n}], x][[1]]] > > Andrzej Kozlowski > > > > > > I think what you want is this function: > > > Chebyshev[f_, x_] := > With[{n = Exponent[f, x]}, > Sum[a[i]*Cos[i ArcCos[x]], {i, 0, n}] /. > SolveAlways[f == Sum[a[i]*ChebyshevT[i, x], {i, 0, n}], x][[1]]] > > So now, for example: > > Chebyshev[21 - 10*x + x^2, x] > -10*x + (1/2)*Cos[2*ArcCos[x]] + 43/2 > > TrigExpand[%] > x^2 - 10*x + 21 > > Chebyshev[21 - 10*x + x^2 + 3*x^3, x] > -((31*x)/4) + (1/2)*Cos[2*ArcCos[x]] + (3/4)*Cos[3*ArcCos[x]] + 43/2 > > > and so on. > > Andrzej Kozlowski > > > > > I'm sorry if I didn't explain myself better I hope this clarifies it > better > > when I test for x =3 x= 7 for equation: > 21 - 10 x + x^2 I get zero for both answers > > I used another math program using the ChebyshevT command and I > got this > 1/2 Cos[2 ArcCos[x]] + 43/2 - 10 x I tested with x=3 and x=7 and I > also got zero for both > > but when I do a TrigReduce > > In[148] := 21 - 10 x + x^2 /. x -> Cos[y] // TrigReduce > > I get > > Out[149]:= 1/2 (43 - 20 Cos[x] + Cos[2 x]) > x=3 gives me 31.88 > x=7 gives me 14.0293 > > I would like to use the ChebyshevT in mathematica 6 because I prefer > that software but I'm not sure > how to get the 1/2 Cos[2 ArcCos[x]] + 43/2 - 10 x answer in > mathematica 6 > > Am I doing something wrong with the TrigReduce function or leaving a > part out why are the answers not even close? > > tia sal2 > > > Transforming a polynomial into a trigonometric format tiasal2 > > > I'm using mathematica 6 and I have a polynomial and would like to > convert it into > a Trigonometric format. Is this possible? > > Example: > I have a polynomial > 0.00154991- 4.01371 x + 1.81197 x^2 + 8.00183 x^3 - 9.3462 x^4 > > How can I transform this into a trigonometric format > Example: > 0.00596679 Cos[6.98132 x] + 0.00358397 Cos[7.21403 x] + > 2.25013 Sin[0.232711 x] - 4.51511 Sin[0.465421 x] > > Note: these aren't correct answers I just wanted to include and > example > > tiasa > > > > > > > === Subject: Re: Transforming a polynomial into a trigonometric format tia sal2 It is slightly better to localize the symbol a: Chebyshev[f_, x_] := Module[{a, n = Exponent[f, x]}, Sum[a[i]*Cos[i ArcCos[x]], {i, 0, n}] /. SolveAlways[f == Sum[a[i]*ChebyshevT[i, x], {i, 0, n}], x][[1]]] Andrzej Kozlowski > I think what you want is this function: > > > Chebyshev[f_, x_] := > With[{n = Exponent[f, x]}, > Sum[a[i]*Cos[i ArcCos[x]], {i, 0, n}] /. > SolveAlways[f == Sum[a[i]*ChebyshevT[i, x], {i, 0, n}], x][[1]]] > > So now, for example: > > Chebyshev[21 - 10*x + x^2, x] > -10*x + (1/2)*Cos[2*ArcCos[x]] + 43/2 > > TrigExpand[%] > x^2 - 10*x + 21 > > Chebyshev[21 - 10*x + x^2 + 3*x^3, x] > -((31*x)/4) + (1/2)*Cos[2*ArcCos[x]] + (3/4)*Cos[3*ArcCos[x]] + 43/2 > > > and so on. > > Andrzej Kozlowski > > > >> I'm sorry if I didn't explain myself better I hope this clarifies it >> better >> >> when I test for x =3 x= 7 for equation: >> 21 - 10 x + x^2 I get zero for both answers >> >> I used another math program using the ChebyshevT command and I >> got this >> 1/2 Cos[2 ArcCos[x]] + 43/