mm-529 ==== Subject: Re: Constrained Optimization Your're right y was meant to be an unknown constant. As I understand > it know, Maximize[] does some sort of numerical optimization. I thought > it would be able to use some concave Programming logic (like > Kuhn-Tucker) to solve this problem for me, returning a list of possible > optima in symbolic form together with the neccessary constraints... But > I admit that maybe this is to much to ask for In the forthcoming edition of The Mathematica Journal (Vol. 9, Issue 4), Equations by Frank J. Kampas (fkampas@msn.com). The following code, KuhnTucker[obj_, cons_List, vars_, domain___] := Module[{consconvrule = {(x_) >= (y_) -> y - x <= 0, (x_) > (y_) -> y - x < 0, (x_) == (y_) -> x - y == 0, (x_) <= (y_) -> x - y <= 0}, stdcons, eqcons, ineqcons, lambdas, mus, numequals, numinequals, lagrangian, eqs1, eqs2, eqs3}, stdcons = cons /. consconvrule; eqcons = Cases[stdcons, (x_) == 0 :> x]; ineqcons = Cases[stdcons, (x_) <= 0 :> x]; numequals = Length[eqcons]; numinequals = Length[ineqcons]; lambdas = Array[la, numequals]; mus = Array[m, numinequals]; lagrangian = obj + lambdas . eqcons + mus . ineqcons; eqs1 = (D[lagrangian, #1] == 0 & ) /@ vars; eqs2 = Thread[mus >= 0]; eqs3 = Table[mus[[i]]*ineqcons[[i]] == 0, {i, numinequals}]; Reduce[Join[eqs1, eqs2, eqs3, cons], Join[vars, lambdas, mus], domain, Backsubstitution -> True]] constraints and the Kuhn-Tucker equations for inequality constraints (see http://mathworld.wolfram.com/Kuhn-TuckerTheorem.html) and solve using Reduce. In some cases, this approach can solve problems which cannot directly be solved with Maximize and Minimize. However, it does not appear to help for your example ... Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul http://InternationalMathematicaSymposium.org/IMS2005/ ==== Subject: Re: Constrained Optimization > KuhnTucker[obj_, cons_List, vars_, domain___] := ... In some cases, this approach can solve problems which cannot directly be > solved with Maximize and Minimize. However, it does not appear to help > for your example ... That's great. Actually it seems to work: In[]:= KuhnTucker[-(x - x^2) y, {1/5 <= x, x <= 2/5, y > 0}, {x}, Reals] Out[]:= y > 0 && x == 2/5 && m[1] == 0 && m[2] == y/5 bound (Maxim) and the maximizing x (Andrzej Kozlowski). Being new to Mathematica, I have not worked with this function before, but it seems that you can do a lot with it... -Caspar ==== Subject: Re: Re: OS X Keybindings > no matter what i do in this file, mathematica seems to be ignoring it! > any ideas? (i've even tried reassigning other things, such as home/end > to both scroll to the end... but no difference. i am quitting and > restarting mathematica each time) If you made a backup of the previous version of the file in the same directory, Mathematica may be finding the backup instead of the one you're modifying (it's not searching by filename, but by named resource within the file). So, make sure that you completely remove any backup version of the file from the TextResources directory and subdirectories. John Fultz jfultz@wolfram.com User Interface Group Wolfram Research, Inc. ==== Subject: Re: OS X Keybindings ==== Subject: 3D Plot formatting Hi all, does anyone know why the <{{-0.0001,10},{-0.0001,10}} It is a kludge, but it works. Kevin >>In a 2-dimensional plot, Mathematica typically does not label the >>origin. I would like X=0 to be labeled as 0. Is this possible? >> > You can add it yourself by doing something like this: Plot[x^2, {x, -1, 1}, Epilog -> Text[0, {0, -0.05}]] > -------------- > Selwyn Hollis > http://www.appliedsymbols.com ==== Subject: Re: Quadratic Form Contours Hi Joerg, To use Ellipsoid we need the semi-length and directions of the axes. The direction we obtain from: Eigenvectors[A] the half-length from: Sqrt[ b/Eigenvalues[A]] Therefore, an ellipsoid would be specified by: Ellipsoid[{x,y}, Sqrt[ b/Eigenvalues[A]], Eigenvectors[A] ] The erason for this is: If you turn the coordinate system in direction of the Eigenvectors, the quadratic form looks like: x1^2/ew1 + x2^2/ew2 == b where ew means eigenvalue. sincerely, Daniel does anybody know a simple way to calculate 2-D ellipsoids in x={x1,x2} > of a quadatric form solving xAx=b for a graphical output, i.e. contour > lines of the quadrtic form expressed as the Graphics primitive Ellipsoid? > I suppose that the option ParameterConfidenceRegion of NonlinearRegress > does something like that, but how? best, joerg > ==== Subject: Re: Quadratic Form Contours > To use Ellipsoid we need the semi-length and directions of the axes. > The direction we obtain from: Eigenvectors[A] > the half-length from: Sqrt[ b/Eigenvalues[A]] > Therefore, an ellipsoid would be specified by: Ellipsoid[{x,y}, Sqrt[ b/Eigenvalues[A]], Eigenvectors[A] ] Not quite. If A is an exact matrix then Eigenvectors[A] will not be normalised. Also, you need to transpose the Eigenvectors. The following code does the job: << Statistics`MultiDescriptiveStatistics` MatrixToEllipsoid[m_, b_, origin_:{0,0}] := Module[{a = Transpose[Eigenvectors[m]], r = Sqrt[b/Eigenvalues[m]]}, Ellipsoid[origin, r, a/(Norm /@ a)]] For example, with A = {{5, -2}, {-2, 8}}; b = 36; the ellipsoid equation is obtained via eqn = ExpandAll[{x, y} . A . {x, y} == b] We can plot the contours of this as follows: ContourPlot[First[eqn], {x, -4, 4}, {y, -4, 4}, Contours -> {b}, ContourShading -> False]; Alternatively, we can visualize the ellipse using Show[Graphics[MatrixToEllipsoid[A,b]], AspectRatio -> Automatic, Axes -> True] The two pictures agree. Paul > The erason for this is: > If you turn the coordinate system in direction of the Eigenvectors, the > quadratic form looks like: x1^2/ew1 + x2^2/ew2 == b where ew means eigenvalue. > sincerely, Daniel > does anybody know a simple way to calculate 2-D ellipsoids in x={x1,x2} > of a quadatric form solving xAx=b for a graphical output, i.e. contour > lines of the quadrtic form expressed as the Graphics primitive Ellipsoid? > I suppose that the option ParameterConfidenceRegion of NonlinearRegress > does something like that, but how? best, joerg > -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul http://InternationalMathematicaSymposium.org/IMS2005/ ==== Subject: Re: refering to a long pattern by a variable What about... txt = abcbacabzzcz; pat2char[twochar_String] /; StringLength[twochar] == 2 := With[{chars = Characters[twochar]}, First[chars] ~~ ___ ~~ Last[chars]] StringCases[txt, ShortestMatch[pat2char[bc]], Overlaps -> False] {bc, bac, bzzc} Or simplify things even more... stringmatches[twochar_String /; StringLength[twochar] == 2][txt_] := With[{chars = Characters[twochar]}, StringCases[txt, ShortestMatch[First[chars] ~~ ___ ~~ Last[chars]], Overlaps -> False]] stringmatches[bc][txt] {bc, bac, bzzc} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ hello i wish if i could refer to a long pattren by just a variable, suppose the: txt=abcbacabzzcz; and the pattern to search is b~~___~~c StringCases[txt, ShortestMatch[b ~~ ___ ~~ c], Overlaps -> False] Out[]={bc, bac, bzzc} ok, i hope there is a way to supply just the : pat=Characters[bc]; and some procedure will make the b ~~ ___ ~~ c from the above pat variable and assign this pattern to pat2 variable so we just write: StringCases[txt, ShortestMatch[pat2], Overlaps -> False] to give the output Out[]={bc, bac, bzzc} i have tried it by StringJoin but it does not work. ==== Subject: goto and label Hi can someone give clearer instruction on how to use Goto and label than the help offers? Guy ==== Subject: Re: goto and label a) don't use Goto[] Mathematica has many other programing constructs b) myFunction[x_] := Module[{i, w = x}, i = 0; Label[start]; i++; w += w*x + 1; If[i < 5, Goto[start]]; w ] ?? Jens Guy Israeli schrieb im > Hi can someone give clearer instruction on how to > use Goto and label than the > help offers? > Guy ==== Subject: Re: goto and label > can someone give clearer instruction on how to use Goto and label than the > help offers? Don't use it! Is that clear enough? speakers was John Nash. His talk was quite interesting but the Mathematica codes he showed were very primitive. At the end of his talk, Roman Maeder turned to me and remarked that in 15 years of working with and coding in Mathematica, this was the only time that he'd ever seen anyone use Goto ... Paul -- Paul Abbott Phone: +61 8 6488 2734 School of Physics, M013 Fax: +61 8 6488 1014 The University of Western Australia (CRICOS Provider No 00126G) AUSTRALIA http://physics.uwa.edu.au/~paul http://InternationalMathematicaSymposium.org/IMS2005/ ==== Subject: Re: Finding Position in an ordered list Hi Janos, I think DiscreteMath`Combinatorica`BinarySearch is what you are searching for. ?BinarySearch BinarySearch[l, k] searches sorted list l for key k and gives the position of l containing k, if k is present in l. Otherwise, if k is absent in l, the function returns (p + 1/2) where k falls between the elements of l in positions p and p+1. BinarySearch[l, k, f] gives the position of k in the list obtained from l by applying f to each element in l. sincerely, Daniel > I wonder if it is possible to use the knowledge > that a list in which I am looking for the position > of an element is ordered. I want a quicker solution then e.g. > lis={ac,dmk,rfg,sty,zxxer} > Position[lis,sty] I am certainly interested in longer lists... > Janos ==== Subject: Re: Viewing algebraic results > Is there a way to view the algebraic formulae for any variable defined >previously even if the variables in the formulae have been assigned a >numerical value? Milind > > If you have explicitly defined the variable by Set or SetDelayed why not try ??f for f[x_]=x^2+3*x+2 f[3] >>18 ??f >>f[x_]=x^2+3*x+2 Pratik Desai -- Pratik Desai Graduate Student UMBC Department of Mechanical Engineering Phone: 410 455 8134 ==== Subject: Re: Displaying Images on GUI during run time Since I could not run the code in the examples that you sent I thought that I would send working versions of what you requested with some slight modifications to the input data. In the second example, the imported data is a Mathematica Graphics [Raster[..]] expression which you could post-process before showing the image, but in my example, I simply display the opened image file as a PNG unmodified. Jeff Adams Wolfram Research -------------- Needs[GUIKit`] GUIRun[ Widget[Frame, {title -> Segmentation GUI, Widget[Panel,{ Widget[ImageLabel, {data -> Script[ img = Table[Sin[x]/Cos[x^2 + y^2], {x, -2, 2, 0.1}, {y, -2, 2, 0.1}]; ExportString[ListDensityPlot[img, Mesh -> False, FrameTicks - > False, DisplayFunction -> Identity],PNG] ]}, Name -> imgDisplay] }] }] ] GUIRun[ Widget[Frame, {title -> Segmentation GUI, Widget[Panel, { Widget[ImageLabel, {data -> Script[ img = Table[Sin[x]/Cos[x^2 + y^2], {x, -2, 2, 0.1}, {y, -2, 2, 0.1}]; ExportString[ListDensityPlot[img, Mesh -> False, FrameTicks -> False, DisplayFunction -> Identity], PNG]]}, Name -> imgDisplay] }], Widget[Button, {text -> Open, BindEvent[action, Script[ Widget[FileDialog, Name -> openFileDialog]; SetPropertyValue[{openFileDialog, multiSelectionEnabled}, False]; SetPropertyValue[{openFileDialog, fileSelectionMode}, PropertyValue[{openFileDialog, FILES_ONLY}]]; returnValue = InvokeMethod[{openFileDialog, showOpenDialog}, Null]; [{openFileDialog, APPROVE_OPTION}], PropertyValue[{PropertyValue[{openFileDialog, selectedFile}], path}], Null]; If[imgPath =!= Null, imgTMP = Import[imgPath]; SetPropertyValue[{imgDisplay, data}, ExportString[ Show[imgTMP, DisplayFunction -> Identity], PNG]]; ]] ] }] }] ] -------------- > Hi all, I am currently stuck on a problem using the GUIKit. I wanted to > creat a > panel to display an image. Then I want a Open button to get the > filepath and displays the image in the panel. Another Operation > button > to process the image data and then display the final image again in > the > same panel. I have a ImageLabel panel for image display. > GUIRun[ > Widget[Frame, {title -> Segmentation GUI, > WidgetGroup[{ > WidgetGroup[ > {Widget[Panel, { > Widget[ImageLabel, {data -> Script > [ExportString[ > ListDensityPlot[img, Mesh -> False, FrameTicks -> False, PlotRange - All, AspectRatio -> Automatic, DisplayFunction -> Identity], > PNG, ConversionOptions -> {Transparency -> GrayLevel[1]}]], > }, Name -> imgDisplay] Then I created a Open button to get the user selected filepath > and set > the string containing the filepath to the imgDisplay (ImageLabel > widget). Widget[Button, {text -> Open, > BindEvent[mouseClicked, > Script[imgPath = ToString[ > GUIResolve[Script[ > Widget[FileDialog, Name -> openFileDialog]; > SetPropertyValue[{openFileDialog, > multiSelectionEnabled}, > False]; > SetPropertyValue[{openFileDialog, fileSelectionMode}, > PropertyValue[{openFileDialog, FILES_ONLY}]]; > returnValue = InvokeMethod[{openFileDialog, > showOpenDialog}, Null]; > APPROVE_OPTION}], > PropertyValue[{PropertyValue[{openFileDialog, > selectedFile}], > path}], Null]]]]; > imgTMP = Import[imgPath].8b¥û1, 1, All, All.8b¥[YAcute]; > SetPropertyValue[{imgDisplay, data}, Script[ > ExportString[ ListDensityPlot[imgTMP,Mesh->False, FrameTicks->False, > PlotRange->All, AspectRatio->Automatic,DisplayFunction->Identity], > PNG,ConversionOptions->{Transparency->GrayLevel[1]}]]]]] > }, Name -> openButton] This didnt work. I am not sure if I can do this. What is the usual Goyan > ==== Subject: Re: simple set operations > Edward, Basically this is a tough nut to crack. The best way to learn Mathematica is to have the leisure to learn it or to just force one's self to take the time. The two groups of people I have sympathy for are students who are thrown into a technical course using Mathematica without ever really learning Mathematica, and professionals who are working on a deadline and suddenly decide they need something like Mathematica to complete their project. They want answers and aren't interested in becoming Mathematica gurus. But it's an unrealistic expectation. I don't know for others, but Mathematica is not actually that bad for me. Perhaps its because I come from a lisp/perl/python background, but the special symbols and what they stand for don't really bug me. Just comparing the three systems - as far as expressiveness goes, I think that perl has the edge, mainly because the syntax (IMO) is better thought out and tends to rely on more primitive constructions and is more amenable to beginners, but perl too has a bunch of special characters meaning special things which ease learning of mathematica. And again, as far as programmability goes, again perl/python has the edge, because they were designed with programming in mind and have symbolic debuggers and IDEs. However, as far as *functionality* goes, there are some things that you can do in mathematica which you simply can't do in either of the other two, which is why I want to learn it. My dream would be Mathematica written in perl6 and ported to parrot, because the syntax is IMO more well thought out and is designed to 'learn from the mistakes' of 10 years of experience and the syntax could probably support pretty much all of mathematica's functionality. Plus, mathematica could then learn from *its* mistakes, and simplify its expressions (as well as leverage off the feature set of perl5, perl6 and python). However, as I don't have the thousands of man-years necessary to devote to this, I think I'll be content with what I have.. Ed ==== Subject: Re: Re: simple set operations >That's what a decent cheatsheet (or cheatbook) would do for mathematica; > reach >out to a lot of professionals who don't really have the time to sit down > and >learn things from scratch, but need to learn by doing and applying the > knowledge >they have to Mathematica. A simple, condensed reference guide, something like a in a nutshell book >by O'Reilly would do the trick. Mathematica by Example, by Abell and Braselton, is that kind of book, hmm... Ok, I'll check into it. I guess my exhortations to write an O'Reilly book are coming to naught.. ;-) Too bad, they are a damn fine publisher, and very, very well known (and prestigious) in the computer world. High standards for publishing, well typeset (almost error free) books, and an almost fanatical readership. Perhaps I'm just an O'Reilly bigot here, but I still think that there's a book to be written here. Ed ==== Subject: Re: simple set operations Edward, Basically this is a tough nut to crack. The best way to learn Mathematica is to have the leisure to learn it or to just force one's self to take the time. The two groups of people I have sympathy for are students who are thrown into a technical course using Mathematica without ever really learning Mathematica, and professionals who are working on a deadline and suddenly decide they need something like Mathematica to complete their project. They want answers and aren't interested in becoming Mathematica gurus. But it's an unrealistic expectation. For students, it would be worthwhile to learn the basics of Mathematica in high school, instead of calculus, which they can learn better in college. Or it would be worthwhile if technical colleges taught one semester courses on Mathematica before students had to use it in technical courses. Otherwise students are going to have to scrape along. Professionals will just have to decide if Mathematica is important enough a tool for them to take the time to learn. Otherwise they can perhaps hire Mathematica consultants to help them with their work. I still think that the best way to learn Mathematica is to work through most of The Mathematica Book - actually typing in the examples and making certain they work. WRI supplies many materials with Mathematica and some of them can be considered as short introductions. The Getting Started with Mathematica booklets are the first place to start. Many MathGroup posters are unaware of the material in these short booklets! Steven Wolfram's Suggestions about Learning Mathematica, at the front of the book, is still the best guide for how to learn Mathematica. The 20 page A Tour of Mathematica at the front of The Book, although not a tutorial, will introduce one to many of the main features. Part 1: A Practical Introduction to Mathematica is really a shorter book within the book that will introduce most of the basic features. Then isn't the Help Browser itself a 'cheat sheet'. Isn't it a fast way to get information on almost all of the functions and commands and all major topics? The Help Browser will always be susceptible to improvement, but I think it is pretty darn good. There are many good books on the market introducing Mathematica. Two that I have that seem quite good are: The Beginner's Guide to Mathematica: Version 4 by Jerry Glynn and Theodore Gray Mathematica Navigator: Graphics and Methods of Applied Mathematics by Heikki Ruskeepaa. But books like these often are just more nicely written presentations of Part 1 of The Book. Once one has learned the basic syntax and basic commands it is often most productive to work with simple NON-Mathematica books to practice translating the material into Mathematica notebooks and calculations. For Tips and Tricks you might try: http://www.verbeia.com/mathematica/tips/Tricks.html Then there is MathGroup, which will usually get one good answers to most questions. They may not be instant but they're pretty fast if one provides a good email address. I can understand the frustration of new users. When I started with Mathematica I was working by myself and wasn't on the Internet. It was pure hell. But having spent the time to learn the basics and practice, things got better. There are still many areas of Mathematica I don't know very well, and larger parts of mathematics, but now being on the Internet and having a friendly community of Mathematica users it has turned into pure heaven. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ > Let's see: 300 to 600 pages constitutes a substantial chunk of Wolfram's > The Mathematica Book. Are you prepared to read that much of his book? > If so, you would surely have found out what you needed to answer your > original question: well of course, but that's not the point of a 'nutshell' book - the point is to get people up to speed really quickly on a technical subject by skipping the exposition and cramming the book with the most important, core concepts. Its ratio of ideas to text is very, very dense. I've looked at the mathematica book before. Its comprehensive, yes, but it is very wordy, and it has 'featuritis' - since it has to concentrate on everything, it can't focus on *anything* so there is no idea of what's the most basic ideas at the core of the system, and what is more advanced. And it weighs in at 5.2 pounds(!), with 1500 pages, so it isn't really a book that you can use as a readily accessible table reference. > ToExpression appears on page 428; MemberQ appears on page 124. (I refer > to printed version of the edition for Mathematica Version 5.) yes, and like I said, its a simple matter of actually finding these needles in this particular haystack. > Of course whatever you read in a Nutshell or other such condensed > treatment, the chances are great that later, if not sooner, you'll have > a problem that cannot directly be solved by what's there and that will > require putting together a bunch of stuff, or using sophisticated > techniques, etc. well, of course, but your argument seems to suggest that there is only one type of book that's worth writing - the comprehensive book. I'd say that to reach everybody you should have at least a 'learning mathematica' book, a 'mathematica reference' book, a 'mathematica tips and tricks' book, etc. etc. etc. Trying to shove all that stuff into one volume isn't doing Mathematica, or the users of mathematica, any good.. Ed ==== Subject: BarChart Hi Everyone, I was wondering if it is possible to have a straight dashed line for the bars on the barChart, instead of a bar? ==== Subject: Centering of graphics I am just writing a technical text with a lot of imported and Mathematica generated pictures/graphics. I wonder how to center them automatically. Or is there no solution for this simple problem? The contribution in the MathGroup Archive 1999 centering a figure from P.J. Hinton did not work: the picture keeps more at the left side than in the center of the page. I use Mathematica 5.1. Any suggestions? Markus ==== Subject: Function Fit to 3D data set I have been trying to do several analyses with an [x,y,z] data set, where z is dependent on x and y. First, I tried a 3D plot. However, the only way I was able to get Mathematica to plot my data was to assume a grid form for x and y, and use ListPlot3D. First question: can Mathematica make a 3D plot from stated x,y,z points? Secondly, I am trying to fit a function to the data. I have determined a function to which to fit parameters. However, Mathematica does not seem to want to accept y as a variable. Here is a simple suggestion of what I was trying. Note, my function is much more complicated. Please also ignore if the given does not work as stated, as I'm making it up. points = {{1, 1, 1}, {1, 2, 4}, {1, 4, 16}} f1 = FindFit[points, a + b*x^0 * y^1 + c*x^0 *y^2 +k*x^2 *y^0 + l*x^2 * y^1, {a, b, c, k, l}, x, y] The error I receive is !(* RowBox[{(FindFit::nonopt ), ((:)( )), RefGuideLinkText, ButtonFrame->None, ButtonData:>General::nonopt])>}]) Second question: Can Mathematica take a set of x,y,z data where z is dependent on x and y and fit a function to it? Secondary question for both: How? ==== Subject: Re: Function Fit to 3D data set You might do well to look up TriangularSurfacePlot and DelaunayTriangulation if you want to make a surface from your points. http://documents.wolfram.com/mathematica/Add-onsLinks/StandardPackages/Discr eteMath/ComputationalGeometry.html It seems as if you have not followed the correct syntax for calling FindFit. Try adapting one of the examples to your case. > I have been trying to do several analyses with an [x,y,z] data set, where z is dependent on x and y. First, I tried a 3D plot. However, the only way I was able to get Mathematica to plot my data was to assume a grid form for x and y, and use ListPlot3D. First question: can Mathematica make a 3D plot from stated x,y,z points? Secondly, I am trying to fit a function to the data. I have determined a function to which to fit parameters. However, Mathematica does not seem to want to accept y as a variable. Here is a simple suggestion of what I was trying. Note, my function is much more complicated. Please also ignore if the given does not work as stated, as I'm making it up. points = {{1, 1, 1}, {1, 2, 4}, {1, 4, 16}} > f1 = FindFit[points, a + b*x^0 * y^1 + c*x^0 *y^2 +k*x^2 *y^0 + l*x^2 * y^1, {a, b, c, k, l}, x, y] The error I receive is !(* > RowBox[{(FindFit::nonopt > ), ((:)( )), instead of !(y)) beyond > position !(4) in !([LeftSkeleton] 1 [RightSkeleton]). An > option must be a rule or a list of rules. !(*ButtonBox[More·, > ButtonStyle->RefGuideLinkText, ButtonFrame->None, > ButtonData:>General::nonopt])>}]) Second question: Can Mathematica take a set of x,y,z data where z is dependent on x and y and fit a function to it? Secondary question for both: How? > -- Chris Chiasson http://chrischiasson.com/ 1 (810) 265-3161 ==== Subject: Re: Function Fit to 3D data set a) use TriangularSufacePlot[] from < schrieb >I have been trying to do several analyses with an >[x,y,z] data set, where z is dependent on x and >y. First, I tried a 3D plot. However, the only >way I was able to get Mathematica to plot my data >was to assume a grid form for x and y, and use >ListPlot3D. First question: can Mathematica make >a 3D plot from stated x,y,z points? Secondly, I am trying to fit a function to the > data. I have determined a function to which to > fit parameters. However, Mathematica does not > seem to want to accept y as a variable. Here is > a simple suggestion of what I was trying. Note, > my function is much more complicated. Please > also ignore if the given does not work as > stated, as I'm making it up. points = {{1, 1, 1}, {1, 2, 4}, {1, 4, 16}} > f1 = FindFit[points, a + b*x^0 * y^1 + c*x^0 > *y^2 +k*x^2 *y^0 + l*x^2 * y^1, {a, b, c, k, l}, > x, y] The error I receive is !(* > RowBox[{(FindFit::nonopt > ), ((:)( )), instead of !(y)) beyond > position !(4) in > !([LeftSkeleton] 1 [RightSkeleton]). An option must be a rule or a list of rules. > !(*ButtonBox[More.89¥Ï, > ButtonStyle->RefGuideLinkText, > ButtonFrame->None, > ButtonData:>General::nonopt])>}]) Second question: Can Mathematica take a set of > x,y,z data where z is dependent on x and y and > fit a function to it? Secondary question for both: How? ==== Subject: Coloring in ShowGraph[] < I have the following very annoying problem in generating plots and > other graphic stuff. > I searched the Archives and the Web for help but I was not able to > solve it. > Maybe it is a trivial issue so I really hope someone can help. > When I add a text cell to a plot, it happens that the text cell > like the text cell had a white background that extends indefinitly on > the right and covers the plot. For instance, a simple command is: > Plot[x,{x,0,1},Epilog->{Text[a line,{0.3,0.5}]}] The graphic result is Figure1 posted on my webpage > http://pantheon.yale.edu/~mc654/mathproblem/mathproblem.html The same happens with the Ticks of the Frame (see Figure 2), and also > if I use different ways of adding text to a plot, like > Show[Graphics[{xxx,Text}]] (see Figure 3). > I'm running Mathematica 5.0 on Mac OS X 10.3 (Panther) on an Apple > PowerBook G4. > The problem appeared after a while, so it can be I toggled an option > that I don't remember (unlikely), but I tried a complete reinstallation > of Mathematica without success. > Did anybody hear of the same problem? Can please anybody help? > Marco - - - > Marco Cirelli > Sloane Physics Lab - Yale University > 217 Prospect St > P.O.Box 208120 > New Haven, CT 06520-8120, USA > phone: +1.203.432 3653 > fax: +1.203.432 5419 > marco.cirelli@yale.edu ==== Subject: Re: Print a selection within >I yust wanted to mark some Part with the cursor and send the >selection to the printer. >The menu entry print selection seems to be designed for that >purpose. >But it fails doing this when my Selection is only one function of a >whole package with lots of functions in it - instead the whole >Package gets to the printer. It sounds like all of your functions are in a single cell. The menu entry print selection probably should be called pring selected cell since the granularity seems to be individual cells within a notebook. Try creating a notebook with one function to a cell and see if you have the same problems. -- To reply via email subtract one hundred and four ==== Subject: Re: Print a selection within ... >> But it fails doing this when my Selection is only one function of a >> whole package with lots of functions in it - instead the whole >> Package gets to the printer. > It sounds like all of your functions are in a single cell. The menu > entry print selection probably should be called pring selected > cell since the granularity seems to be individual cells within a > notebook. Try creating a notebook with one function to a cell and see > if you have the same problems. -- To reply via email subtract one > hundred and four > Yes, your guess is right. I thought it was neccessary to put everything into one cell to create a package. Now I recognized, that save as package does the job of creating the cell and melting Structures down to pure ASCII text. So my problem isn't serious at all. Thans for all the answers. Detlef ==== Subject: Re: refering to a long pattern by a variable Hi First you need to recognize that the full form of ___ is BalnkNullSequence[]. The ~~ operator is StingExpression[] generate a function (not a clever one, but it will demonstrate the idea and easily can be modified) makePat[s_String]:=StringExpression @@ (Insert[Characters[s], BlankNullSequence[], 2]) then txt=abcbacabzzcz; StringCases[txt, ShortestMatch[makePat[bc]], Overlaps -> False] will return the answer you need. You can call makePat with any string you need (of two characters). yehuda > hello > i wish if i could refer to a long pattren by just a variable, > suppose the: > txt=abcbacabzzcz; > and the pattern to search is b~~___~~c > StringCases[txt, ShortestMatch[b ~~ ___ ~~ c], Overlaps -> False] > Out[]={bc, bac, bzzc} > ok, i hope there is a way to supply just the : > pat=Characters[bc]; > and some procedure will make the b ~~ ___ ~~ c from the above pat variable > and assign this pattern to pat2 variable so we just write: > StringCases[txt, > ShortestMatch[pat2], Overlaps -> False] > to give the output > Out[]={bc, bac, bzzc} > i have tried it by StringJoin but it does not work. > ==== Subject: Re: refering to a long pattern by a variable Hi Marloo, StringJoin joins plain strings. To join string pattern you must use StringExpression. > hello > i wish if i could refer to a long pattren by just a variable, > suppose the: > txt=abcbacabzzcz; > and the pattern to search is b~~___~~c > StringCases[txt, ShortestMatch[b ~~ ___ ~~ c], Overlaps -> False] > Out[]={bc, bac, bzzc} > ok, i hope there is a way to supply just the : > pat=Characters[bc]; > and some procedure will make the b ~~ ___ ~~ c from the above pat variable > and assign this pattern to pat2 variable so we just write: > StringCases[txt, > ShortestMatch[pat2], Overlaps -> False] > to give the output > Out[]={bc, bac, bzzc} > i have tried it by StringJoin but it does not work. ==== Subject: Re: refering to a long pattern by a variable txt = abcbacabzzcz; pat = Characters[bc] pat2 = StringExpression @@ (pat /. b :> Sequence @@ {b, ___}) StringCases[txt, ShortestMatch[pat2], Overlaps -> False] ?? Jens schrieb im Newsbeitrag > hello > i wish if i could refer to a long pattren by > just a variable, > suppose the: > txt=abcbacabzzcz; > and the pattern to search is b~~___~~c > StringCases[txt, ShortestMatch[b ~~ ___ ~~ > c], Overlaps -> False] > Out[]={bc, bac, bzzc} > ok, i hope there is a way to supply just the : > pat=Characters[bc]; > and some procedure will make the b ~~ ___ ~~ > c from the above pat variable > and assign this pattern to pat2 variable so we > just write: > StringCases[txt, > ShortestMatch[pat2], Overlaps -> False] > to give the output > Out[]={bc, bac, bzzc} > i have tried it by StringJoin but it does not > work. ==== Subject: Re: Finding Position in an ordered list The immediate answer is to perform a binary search. This will result with a complexity of O(Log[2,n]) (n being the length of the list) and not O(n). There is an implementation of a binary search algorithm in the Combinatorica package << DiscreteMath`Combinatorica` ? BinarySearch good luck yehuda > I wonder if it is possible to use the knowledge > that a list in which I am looking for the position > of an element is ordered. I want a quicker solution then e.g. > lis={ac,dmk,rfg,sty,zxxer} > Position[lis,sty] I am certainly interested in longer lists... > Janos > ==== Subject: Re: Finding Position in an ordered list Janos, If your data is numerical, and you want to find the positions of many numbers at once, then Interpolation is a much quicker method. Again, some numeric data: In[1]:= x = Sort[Table[Random[], {10^6}]]; Load your package: In[2]:= Needs[DiscreteMath`] Define my function to find the position: In[3]:= f = Interpolation[Transpose[{x, N[Range[Length[x]]]}], InterpolationOrder -> 1]; // Timing Out[3]= {0.844 Second, Null} Compare finding the positions of 5000 elements using BinarySearch and using my Interpolation method: In[7]:= r1 = BinarySearch[x, #] & /@ Take[x, 5000]; // Timing r2 = Round[f[#]] & /@ Take[x, 5000]; // Timing Out[7]= {2.453 Second, Null} Out[8]= {0.062 Second, Null} Out[9]= True As you can see, the Interpolation method is 40 times faster. Carl Woll ----- Original Message ----- ==== Subject: Re: Finding Position in an ordered list there exist a built in function, as Daniel told me: BinarySearch in DiscreteMath. Janos >I wonder if it is possible to use the knowledge > that a list in which I am looking for the position > of an element is ordered. I want a quicker solution then e.g. > lis={ac,dmk,rfg,sty,zxxer} > Position[lis,sty] I am certainly interested in longer lists... > Janos > Janos, I would think a binary search would be the quickest. I won't bother giving > an implementation, as you can do a search in the archives. For example: http://forums.wolfram.com/mathgroup/archive/1998/Jul/msg00022.html Could you provide a few more details on your problem? For example, is your > ordered list numeric, or does it contain names as you indicated in your > post. Also, are you interested in finding positions of more than one > element? If the answer to both of the above is yes, then you might find > using the built in binary search in Interpolation useful. For example, > suppose your list contained a million reals: x = Sort[Table[Random[], {10^6}]]; Create the interpolating function: In[2]:= > Timing[f = Interpolation[Transpose[{x, N[Range[Length[x]]]}], > InterpolationOrder -> 1]; ] > Out[2]= > {0.844 Second, Null} Find the location of an element: In[3]:= > Round[f[x[[100000]]]] // Timing > Out[3]= > {0. Second, 100000} Contrast this with using Position: In[4]:= > Position[x, x[[100000]]] // Timing > Out[4]= > {2.093 Second, {{100000}}} Finally, let's make sure that f returns the correct answers for every > element in your list: In[5]:= Out[5]= > {5.344 Second, True} Carl Woll > ==== Subject: Re: Finding Position in an ordered list Hi Janos, Here is a little experiment. First I create a list of strings. $Version 5.1 for Microsoft Windows (January 27, 2005) Needs[Miscellaneous`Dictionary`] words = FindWords[__]; Length[words] 92836 Now I search the position of four words with Position: Timing[ {Position[words,egg],Position[words,book ],Position[words,you],Position[words,paper]}] {0.05 Second, {{{25730}}, {{8885}}, {{92516}}, {{57800}}}} Now I create a little database: db = Dispatch[Thread[words -> Range[Length[words]]]]; Timing[{egg, book, you, paper} /. db] {0. Second,{25730,8885,92516,57800}} It is faster, as wanted. Janos, maybe you could now determine the search time as a function of the list size. >-----Original Message----- ==== >Subject: Finding Position in an ordered list I wonder if it is possible to use the knowledge >that a list in which I am looking for the position >of an element is ordered. I want a quicker solution then e.g. >lis={ac,dmk,rfg,sty,zxxer} >Position[lis,sty] I am certainly interested in longer lists... >Janos > ==== Subject: Re: Manipulating textfiles (subtitlefiles for films) Hi Peter, First read the data: d = Import[FileName]; add e.g. diff=1000: d = StringReplace[d, RegularExpression[ {(d+)}] :> ({ <> ToString[ToExpression[$1] + diff] <> })]; export the changed string: Export[NewFileName] sincerely, Daniel > I have a textfile of the following format: > . > . > {822}{918}En del unga m.8anniskor|tar itu med sina disillusioner > {926}{1038}genom att s.9aka illusioner p.8c egen hand- > {1046}{1126}i ett illegalt verkligt virtuellt krigsspel. > {1134}{1294}Spelets simulerade sp.8anning och d.9adande|.8ar tv.8cngsm.8assiga > och beroendeframkallande. > {1302}{1430}N.8cgra spelare, jobbar|i team som kallas 'parties'. > {1438}{1550}till och med tj.8anar sitt leverbr.9ad p.8c spelet. > . > . > It is a subtitle file used to display subtitles in .avi films. > Sometimes subtitles and the film are not in sync, and the numbers in > the curly paranthesis has to have a number added or subtracted. > so, how to add a number to each of the pair of numbers in each line? > And save the result in a file without changing anything else? > The numbers in this case is frame numbers I think. (the film may be > shown with 23 fps for instance.) > I have tried a couple of variants, and one difficulty is that the > saved files does not save my special country characters. Best > PW > ==== Subject: Re: Re: Print a selection within correction of previous post: may be -> may not be > I think the functionality you are looking for may be available in the > front end, which is why I suggested the other method. Of course, you could always highlight the text, and copy/paste it to a > new notebook and then print that. It would only be one extra step. Technically, a notebook itself is just an expression, with the same > being true for cells. Find the appropriate way to address a cell > object, and you could use Extract to take out the boxes corresponding > the extracted part as a cell. Off hand, I do not know the code for > doing so. I think this is a misunderstanding. It's merely a front end question: I yust wanted to mark some Part with the cursor > and send the selection to the printer. The menu entry print selection seems to be designed > for that purpose. But it fails doing this when my Selection is only one function > of a whole package with lots of functions in it - instead > the whole Package gets to the printer. > -- > Chris Chiasson > http://chrischiasson.com/ > 1 (810) 265-3161 -- Chris Chiasson http://chrischiasson.com/ 1 (810) 265-3161 ==== Subject: Re: Re: Print a selection within I think the functionality you are looking for may be available in the front end, which is why I suggested the other method. Of course, you could always highlight the text, and copy/paste it to a new notebook and then print that. It would only be one extra step. > Technically, a notebook itself is just an expression, with the same > being true for cells. Find the appropriate way to address a cell > object, and you could use Extract to take out the boxes corresponding > the extracted part as a cell. Off hand, I do not know the code for > doing so. I think this is a misunderstanding. It's merely a front end question: I yust wanted to mark some Part with the cursor > and send the selection to the printer. The menu entry print selection seems to be designed > for that purpose. But it fails doing this when my Selection is only one function > of a whole package with lots of functions in it - instead > the whole Package gets to the printer. -- Chris Chiasson http://chrischiasson.com/ 1 (810) 265-3161 ==== Subject: Re: Print a selection within > Technically, a notebook itself is just an expression, with the same > being true for cells. Find the appropriate way to address a cell > object, and you could use Extract to take out the boxes corresponding > the extracted part as a cell. Off hand, I do not know the code for > doing so. > I think this is a misunderstanding. It's merely a front end question: I yust wanted to mark some Part with the cursor and send the selection to the printer. The menu entry print selection seems to be designed for that purpose. But it fails doing this when my Selection is only one function of a whole package with lots of functions in it - instead the whole Package gets to the printer. ==== Subject: Re: goto and label Think of the tag in Label as a line number - for instance, Label[L100]. You can then use Goto[L100] to move control to that point. The help shows (in v5.1) shows all the commands on one line - you can put in line breaks after each semicolon command break (;) to help make the code more readable. BUT - before you go ahead, a recommendation: Don't use Goto!! It's a horrible command that you should never need to use. It's only included in Mathematica for completeness. There are far more efficient ways of doing whatever task it is that you want, that will run faster, and that you will be able to understand when you come back in 3 months (or whatever) and try to debug or modify you code. Perhaps if you post what the problem is someone in the group could suggest a 'standard' way of doing it. Hywel ------------------------------------------- Hywel Owen h.owen@dl.ac.uk Accelerator Science and Technology Centre CCLRC Daresbury Laboratory United Kingdom Tel/Fax: +44 1925 603797/603192 ------------------------------------------- > -----Original Message----- ==== > Subject: goto and label Hi can someone give clearer instruction on how to use Goto and > label than the help offers? > Guy