Subject: 'NonlinearFit` confusion I'm trying to fit a sinusoidal function to my data using 'NonlinearFit' but it's exhibiting rather odd behaviour. Please see my examples below: **** As a test, I created a list of data from a function of the form y = 6 + 2Sin[3 + x] with: datay = Table [6 + 2Sin[3 + x], {x, -10Pi, 10Pi, 0.05}]; datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; **** Then tested to see whether NonlinearFit would correctly deduce the equations parameters with: NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}] **** As expected, it gave me '6.+ 2. Sin[3. + 1. x]' ... exactly as one would expect :) **** Second test, I modified the equation by multiplying x by 5, ie. y = 6 + 2Sin[3 + 5x]: datay = Table [6 + 2Sin[3 + 5 x], {x, -10Pi, 10Pi, 0.05}]; datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; ***** and applied the NonlinearFit as before: NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}] ***** but this time I get a wildly innacurate result: 6.000165 + 0.025086 Sin[0.0080308 - 0.247967 x] Specifically, the parameters 'a', 'd' and 'e' are all completely in error by orders of magnitude. I tried extending the range of the data to include more cycles of the sinusoid, thereby making it more continuous/monotonic but that made no difference. Am I missing something fundamental here? Any assistance would be greatly appreciated. PS: I'm using Mathematica 5.0 on a MAC. === Subject: Re: 'NonlinearFit` confusion Why not take less points, rather than more?? In[480]:= Clear[datay,datax,data1] datay = Table [6 + 2Sin[3 + x], {x, -10Pi, 10Pi, 0.05}]; datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; data1 = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; Length[data1] First[data1] Out[484]= 1257 Out[485]= {-31.4159,6.28224} In[511]:= Clear[a,b,c,d,e] sinFit1=NonlinearFit[Take[data1,40], c + a *Sin[d + e *x], x, {a, c, d,e}] Out[512]= 6.[InvisibleSpace]+2. Sin[3.[InvisibleSpace]+1. x] In[513]:= Clear[y,datay,datax,a,b,c,d,e] datay = Table [6 + 2Sin[3 + 5 x], {x, -10Pi, 10Pi, 0.05}]; datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; data2 = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; Length[data2] First[data2] Out[517]= 1257 Out[518]= {-31.4159,6.28224} In[519]:= y=a*Sin[d+e x]+c; sinFit2=NonlinearFit[Take[data2,40],y, x, {a,c, d,e}] Out[520]= 6.[InvisibleSpace]+2. Sin[122.381[InvisibleSpace]+5. x] DisplayTogether[ Plot[sinFit1, {x, -10Pi, -8 Pi}, PlotStyle -> Blue], Plot[sinFit2, {x, -10Pi, -8 Pi}, PlotStyle -> Red], ListPlot[Take[data1, 40], PlotStyle -> {Blue, PointSize[0.011]}], ListPlot[Take[data2, 30], PlotStyle -> {Red, PointSize[0.011]}], Prolog -> { { Blue, Text[sinFit1, {-27.5, 7}, {-1, 0}, TextStyle -> {FontFamily -> Times, FontWeight -> Bold, FontSize -> 18 } ] }, { Red, Text[sinFit2, {-26.9, 6}, {-1, 0}, TextStyle -> {FontFamily -> Times, FontWeight -> Bold, FontSize -> 18 } ] } }, ImageSize -> 800, Frame -> False, AxesOrigin -> {-31.5, 4.0} ] Yas > I'm trying to fit a sinusoidal function to my data using > 'NonlinearFit' but it's exhibiting rather odd behaviour. Please see my > examples below: > **** As a test, I created a list of data from a function of the form y > = 6 + 2Sin[3 + x] with: > datay = Table [6 + 2Sin[3 + x], {x, -10Pi, 10Pi, 0.05}]; > datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; > data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; > **** Then tested to see whether NonlinearFit would correctly deduce > the equations parameters with: > NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}] > **** As expected, it gave me '6.+ 2. Sin[3. + 1. x]' ... exactly as > one would expect :) > **** Second test, I modified the equation by multiplying x by 5, ie. > y = 6 + 2Sin[3 + 5x]: > datay = Table [6 + 2Sin[3 + 5 x], {x, -10Pi, 10Pi, 0.05}]; > datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; > data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; > ***** and applied the NonlinearFit as before: > NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}] > ***** but this time I get a wildly innacurate result: 6.000165 + > 0.025086 Sin[0.0080308 - 0.247967 x] > Specifically, the parameters 'a', 'd' and 'e' are all completely in > error by orders of magnitude. > I tried extending the range of the data to include more cycles of the > sinusoid, thereby making it more continuous/monotonic but that made no > difference. > Am I missing something fundamental here? > Any assistance would be greatly appreciated. > PS: I'm using Mathematica 5.0 on a MAC. Dr. Yasvir A. Tesiram Associate Research Scientist Oklahoma Medical Research Foundation Free Radical Biology and Ageing Research Program 825 NE 13th Street, OKC, OK, 73104 P: (405) 271 7126 F: (405) 271 1795 E: yat@omrf.ouhsc.edu === Subject: Re: 'NonlinearFit` confusion Fitting equations to data is always an inexact science. That's the only fundamental you're missing, I think. Bobby > I'm trying to fit a sinusoidal function to my data using > 'NonlinearFit' but it's exhibiting rather odd behaviour. Please see my > examples below: >**** As a test, I created a list of data from a function of the form y > = 6 + 2Sin[3 + x] with: > datay = Table [6 + 2Sin[3 + x], {x, -10Pi, 10Pi, 0.05}]; > datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; > data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; > **** Then tested to see whether NonlinearFit would correctly deduce > the equations parameters with: > NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}] > **** As expected, it gave me '6.+ 2. Sin[3. + 1. x]' ... exactly as > one would expect :) > **** Second test, I modified the equation by multiplying x by 5, ie. > y = 6 + 2Sin[3 + 5x]: > datay = Table [6 + 2Sin[3 + 5 x], {x, -10Pi, 10Pi, 0.05}]; > datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; > data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; > ***** and applied the NonlinearFit as before: > NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}] > ***** but this time I get a wildly innacurate result: 6.000165 + > 0.025086 Sin[0.0080308 - 0.247967 x] > Specifically, the parameters 'a', 'd' and 'e' are all completely in > error by orders of magnitude. > I tried extending the range of the data to include more cycles of the > sinusoid, thereby making it more continuous/monotonic but that made no > difference. > Am I missing something fundamental here? > Any assistance would be greatly appreciated. > PS: I'm using Mathematica 5.0 on a MAC. -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: 'NonlinearFit` confusion > I'm trying to fit a sinusoidal function to my data using > 'NonlinearFit' but it's exhibiting rather odd behaviour. Please see my > examples below: > > **** As a test, I created a list of data from a function of the form y > = 6 + 2Sin[3 + x] with: > datay = Table [6 + 2Sin[3 + x], {x, -10Pi, 10Pi, 0.05}]; > datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; > data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; You can generate this data directly using data = Table[{x,6 + 2Sin[3 + x]}, {x, -10Pi, 10Pi, 0.05}] > **** Then tested to see whether NonlinearFit would correctly deduce > the equations parameters with: > NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}] > **** As expected, it gave me '6.+ 2. Sin[3. + 1. x]' ... exactly as > one would expect :) > **** Second test, I modified the equation by multiplying x by 5, ie. > y = 6 + 2Sin[3 + 5x]: > datay = Table [6 + 2Sin[3 + 5 x], {x, -10Pi, 10Pi, 0.05}]; > datax = Table [x, {x, -10Pi, 10Pi, 0.05}]; > data = Table[{datax[[i]], datay[[i]]}, {i, 1, Length[datay]}]; After re-generating your data, data = Table[{x,6 + 2Sin[3 + 5 x]}, {x, -10Pi, 10Pi, 0.05}] have a look at it: ListPlot[data] I think you will see what the problem is. > ***** and applied the NonlinearFit as before: > NonlinearFit[data, c + a Sin[d + e x], x, {a, c, d,e}] > ***** but this time I get a wildly innacurate result: 6.000165 + > 0.025086 Sin[0.0080308 - 0.247967 x] > Specifically, the parameters 'a', 'd' and 'e' are all completely in > error by orders of magnitude. > I tried extending the range of the data to include more cycles of the > sinusoid, thereby making it more continuous/monotonic but that made no > difference. In 5.0 you can use FindFit instead of NonlinearFit. Note that you may still have to provide a reasonable initial guess for the parameters to obtain convergence. Paul -- Paul Abbott Phone: +61 8 9380 2734 School of Physics, M013 Fax: +61 8 9380 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: Failure to Evaluate? Clear[f, g, h] f = x^2/x + 1; g = x^4 + 7; h[x_] = Evaluate[D[f, x]/ D[g, x]] h[1] 1/(4*x^3) 1/4 Clear[f, g, h] f[x_] := x^2/x + 1 g[x_] := x^4 + 7 h[x_] := Derivative[1][f][x]/ Derivative[1][g][x] h[1] 1/4 Bobby > f:=Function[#1^2/#1+1] > g:=Function[#1^4+7] > h:=D[f]/D[g] > h[1] > Gives > ((#1^2/#1)+1 &)/(#1^4+7 &)[1] > Why doesn't it evaluate by setting #1 to 1 to get 1/4? > h/.#1->1//N sets #1 to 1 and gives > (1 1 + 1 &)/(1 + 7 &) > but still doesn't evaluate to 1/4. > What gives? What's the Right Stuff? -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Failure to Evaluate? > f:=Function[#1^2/#1+1] > g:=Function[#1^4+7] > h:=D[f]/D[g] > h[1] > Gives > ((#1^2/#1)+1 &)/(#1^4+7 &)[1] > Why doesn't it evaluate by setting #1 to 1 to get 1/4? > h/.#1->1//N sets #1 to 1 and gives > (1 1 + 1 &)/(1 + 7 &) > but still doesn't evaluate to 1/4. > What gives? What's the Right Stuff? Mathematica does not implement the algebra of functions so if f an g are a functions, f+g, f*g, and f/g are not. Also, your definition, f=Function[#1^2/#1+1] seems pointless, since this is just Function[#1+1]. Did you mean f=Function[#1^2/(#1+1)]? In addition, there is no point using delayed evaluation in the definitions of f, g and h; the only thing it does is make you code slightly slower. And another thing: what do you think D[f] and D[g] are? Well, whatever you intended they just return f and g. Presumably what you meant was f' and g' (Derivative[1][f],Derivative[1][g])? Anyway, there are two ways to deal with this. One is to unprotected Plus, Times, and Power and overload them to work with functions. I showed how to do this in this list several years ago but it is pretty obvious so I do not want to repeat it. Besides, I do not recommend this approach. A simpler way is simply this: f = #1 + 1 & ; g = #1^4 + 7 & ; h = Function[x, Derivative[1][f][x]/Derivative[1][g][x]]; h[1] 1/4 Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/ === Subject: NonlinearFit I was hoping someone could help me with a problem I'm having with NonlinearFit. I'm trying to fit an exponential function to a set of data using the following command: << Statistics`NonlinearFit` NonlinearFit[Data,theta1 Exp[theta2 x],x,{theta1,theta2}] Data is the following table, where the right column is 3*Exp[.2*x] (Embedded image moved to file: pic13984.pcx) [contact the author to get the file - moderator] NonlinearFit returns (Embedded image moved to file: pic03027.pcx), which is clearly not 3*Exp[.2*x]. I only have this problem when trying to fit exponential functions. Any suggestions? Andy === Subject: Re: NonlinearFit Seems to be no problem here. Copy and paste a representative sample of your real data in the body of your emails (say five well spaced points). In any case here is some synthetic data and solution using NonlinearFit and FindFit (new as of version 5) << Statistics`NonlinearFit` << Graphics`Colors` << Graphics`Graphics` fitted = NonlinearFit[syndat, th1*Exp[th2*x], {x}, {th1, th2}] p2 = Plot[fitted, {x, 0, 6}, PlotStyle -> Red, PlotRange -> All, Epilog -> Prepend[Point /@ syndat, PointSize[0.015]] ]; fittedUsingFindFit = FindFit[syndat, th1*Exp[th2*x], {th1, th2}, x, Method -> LevenbergMarquardt] Yas > I was hoping someone could help me with a problem I'm having with > NonlinearFit. > I'm trying to fit an exponential function to a set of data using the > following command: > << Statistics`NonlinearFit` > NonlinearFit[Data,theta1 Exp[theta2 x],x,{theta1,theta2}] > Data is the following table, where the right column is 3*Exp[.2*x] > (Embedded image moved to file: pic13984.pcx) > [contact the author to get the file - moderator] > NonlinearFit returns (Embedded image moved to file: pic03027.pcx), > which is > clearly not 3*Exp[.2*x]. > I only have this problem when trying to fit exponential functions. Any > suggestions? > Andy === Subject: Re: NonlinearFit > I'm trying to fit an exponential function to a set of data using the > following command: > << Statistics`NonlinearFit` > NonlinearFit[Data,theta1 Exp[theta2 x],x,{theta1,theta2}] > Data is the following table, where the right column is 3*Exp[.2*x] > (Embedded image moved to file: pic13984.pcx) > [contact the author to get the file - moderator] > NonlinearFit returns (Embedded image moved to file: pic03027.pcx), which is > clearly not 3*Exp[.2*x]. > I only have this problem when trying to fit exponential functions. Any > suggestions? << Statistics` data = Table[{x, 3 E^(0.2 x)}, {x, -3, 3, 0.5}] NonlinearFit[data, a E^(b x), x, {a, b}] In Version 5.0 you can use FindFit: FindFit[%, a E^(b x), {a, b}, x] In both cases the original functional form is recovered. Paul -- Paul Abbott Phone: +61 8 9380 2734 School of Physics, M013 Fax: +61 8 9380 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: NonlinearFit Andrew, Can you email me the files you tried to attach to your newsgroup message? cf > I was hoping someone could help me with a problem I'm having with > NonlinearFit. > I'm trying to fit an exponential function to a set of data using the > following command: > << Statistics`NonlinearFit` > NonlinearFit[Data,theta1 Exp[theta2 x],x,{theta1,theta2}] > Data is the following table, where the right column is 3*Exp[.2*x] > (Embedded image moved to file: pic13984.pcx) > [contact the author to get the file - moderator] > NonlinearFit returns (Embedded image moved to file: pic03027.pcx), > which is clearly not 3*Exp[.2*x]. > I only have this problem when trying to fit exponential functions. > Any suggestions? > Andy === Subject: Re: Defining a function For instance: << Calculus`Integration` f[k_] := Sum[a[i, k - i]Boole[1 .89ÅÛ k - i .89ÅÛ n], {i, 1, m}] f /@ Range[13] /. {m -> 10, n -> 3} // ColumnForm 0 a[1, 1] a[1, 2] + a[2, 1] a[1, 3] + a[2, 2] + a[3, 1] a[2, 3] + a[3, 2] + a[4, 1] a[3, 3] + a[4, 2] + a[5, 1] a[4, 3] + a[5, 2] + a[6, 1] a[5, 3] + a[6, 2] + a[7, 1] a[6, 3] + a[7, 2] + a[8, 1] a[7, 3] + a[8, 2] + a[9, 1] a[8, 3] + a[9, 2] + a[10, 1] a[9, 3] + a[10, 2] a[10, 3] Bobby > I want to compute the Sum[a[i, j]] as a function of k when > 1 <= i <= m, 1 <= j <= n and i+j=k. The numbers m, n and > the function a[i, j] are given. Is it possible to define such a > function with Mathematica 4.1? -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: RE: Matrix + Simplify I think Simplify does work on arrays. In any case, you could always Map Simplify to level {2} of your matrix expression. Map[Simplify, matrix, {2}] But simplifing expressions to the form that you want is something of an art. It may be difficult to write a single Simplify command that works the way you want on all elements of the matrix. You may have to combine Simplify with some Rules that perform specific transformations. You may have to use MapAt to transform specific matrix elements. Without seeing your actual matrix expression it is difficult to be more specific. Giving specific examples on MathGroup will almost always elicit a better response. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I have matrix 3 x 3 which contains more complicated expressions. Every expression is long and therefore it is difficult to analisys. I know, there is Simplify[] function but it doesn't work when its parameter is matrix or vector. How can I simplify all elements within this matrix ? -- CYSTERNA++ === Subject: Re: Matrix + Simplify matrix is only 3x3. I thought that something special packet exists (more useful than <<'MatrixManipulation') which help me. CYSTERNA++ UÀytkownik David Park napisaÒ w wiadomo.a6ci > I think Simplify does work on arrays. In any case, you could always Map > Simplify to level {2} of your matrix expression. > Map[Simplify, matrix, {2}] > But simplifing expressions to the form that you want is something of an art. > It may be difficult to write a single Simplify command that works the way > you want on all elements of the matrix. You may have to combine Simplify > with some Rules that perform specific transformations. You may have to use > MapAt to transform specific matrix elements. > Without seeing your actual matrix expression it is difficult to be more > specific. Giving specific examples on MathGroup will almost always elicit a > better response. > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ > I have matrix 3 x 3 which contains more complicated expressions. Every > expression is long and therefore it is difficult to analisys. I know, there > is Simplify[] function but it doesn't work when its parameter is matrix or > vector. How can I simplify all elements within this matrix ? > -- > CYSTERNA++ === Subject: Re: NthPermutation: how to change output format? >> {a, b, 2, c, 3, e, d, 1} >>How do I get directly: >> ab2c3ed1 >>without commas and parentheses? > If you want a string use this > crunch[res_List]:=StringJoin[ToString/@res] > But if you want a symbol, use this instead > crunch[res_List]:=ToExpression[StringJoin[ToString/@res]] > crunch[{a, b, 2, c, 3, e, d, 1}] > ab2c3ed1 > cheers, > Peltio > Invalid address in reply-to. Crafty demunging required to mail me. === Subject: RE: Changing ErrorBar colors but keeping serifs David, I always find MultipleListPlot and all its options very baroque. If you want to wander too far from the established set-piece plot, such as using colored error bars, it becomes a real chore to figure out how to do it. Perhaps someone will supply a simple solution. I would abandon MultipleListPlot altogether, write my own error bar routine and do it this way. Needs[Graphics`Colors`] Here is some sample data. It's a list of {x, y, {down error, up error}}. data = Table[{x, x^2*((1 + x)/200) + Random[Real, {-0.5, 0.5}], {-Random[Real, {0.1, 0.5}], Random[Real, {0.1, 0.5}]}}, {x, 0, 10}]; The points themselves can be extracted from the complete data. coorddata = Take[#, 2] & /@ data; Here is a routine to plot the error bars and points. It's exact form would depend on how you packaged your data. PointWithError[color_, width_][{x_, y_, {neg_, pos_}}] := {color, Line[{{x, y + neg}, {x, y + pos}}], Line[{{x - width/2, y + pos}, {x + width/2, y + pos}}], Line[{{x - width/2, y + neg}, {x + width/2, y + neg}}], Black, Point[{x, y}]} We can then plot the data line and the points with error bars simply by wrapping coorddata in Line, and by mapping PointWithError onto the data. Show[ Graphics[ {Line[coorddata], AbsolutePointSize[4], PointWithError[Red, 0.1] /@ data}], Frame -> True, Background -> Linen, ImageSize -> 400]; If I wanted to plot a fitted line instead of the connected data points, I would use the DrawGraphics package from my web site below. Then we use a similar construction but just substitute a curve for the Line. Needs[DrawGraphics`DrawingMaster`] fitcurve[x_] = Fit[coorddata, {x, x^3}, x] Draw2D[ {Draw[fitcurve[x], {x, 0, 10}], AbsolutePointSize[4], PointWithError[Red, 0.1] /@ data}, Frame -> True, Background -> Linen, ImageSize -> 400]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi there...Wondering if someone could help me with the following issue: I would like to change ONLY the color of the error bars produced by the function MultipleListPlot. The standard answer is to do something like myerrorbar[{x_, y_}, ErrorBar[{0, 0}, {yminus_, yplus_}]] := {Red, Line[{{x, y + yminus}, {x, y + yplus}}]} (See post with subject line Multiplelistplot question for details.) For my purposes this answer is incomplete because it doesn't reproduce the serifs (little lines above and below the error bar). There must be a better way to get the default serifs than to reproduce the work that the creators of the package went through to make the serifs. What I would like to know is how to determine what the default error bar function is so that I can simply add the RGB[1, 0, 0] directive to it and have the serifs and all other aspects of the error bars unchanged (except for the color). Any ideas how to do this? Any help would be very much appreciated. David deo6@prodigy.net === Subject: populate a list with random numbers from normal distribution? hello group. I looked at the help browser but i can't figure this out. I weant to make a list of random numbers sampled from a normal distribution In[90]:= Needs[Statistics`ContinuousDistributions`] l1 = Table[Random[NormalDistribution[50000,25000], Integer, {10000, 99999}], {1000}]; Variance[l1]//N StandardDeviation[l1]//N Random::randt: Type specification NormalDistribution[50000, 25000] in <<1>> should be Real, Integer, or Complex. Out[92]= 0. Out[93]= 0. sean === Subject: Re: Special characters for German One possibility is to use the palette: File | Palettes | International Characters. Another is using the escape key: Esc u Esc will produce the u with umlaut, etc. Both are rather tedious if you want to type long texts. Tomas Garza Mexico City ----- Original Message ----- === Subject: Special characters for German > Can you tell me how to be able to type the umlauts , using an English === Subject: RE: Special characters for German Herr Atsom, Wenn Sie Microsoft Windows 2000 haben, .9affnen Sie das Anfangsmen.9f, ge.9affnete Zusatzger.8ate, ge.9affnetes (not goofiness) System Werkzeuge, benutzen dann das Buchstabe Diagramm, um Alphabete mit umlauts vorzuw.8ahlen. Or you can use the key and the right-side numeric keypad and key must be on! Hold the Alt key and type on the numeric keypad. (Sie verwenden den < Alt > Schl.9fssel und der Rechtseite numerische Tastaturblock- und < numerische Verriegelung > Schl.9fssel mu§ eingeschaltet sein! Halten Sie die ALT-Taste und Art auf dem numerischen Tastaturblock.) For umlaut type Alt 0168 For y umlaut type Alt 0255 or Alt 152 For Y umlaut type Alt 0159 For u umlaut type Alt 0252 or Alt 129 For U umlaut type Alt 0220 or Alt 154 For o umlaut type Alt 0246 or Alt 148 For O umlaut type Alt 0214 or Alt 153 For a umlaut type Alt 0228 or Alt 132 For A umlaut type Alt 0196 or Alt 142 Es ist einfacher jedoch, das Buchstabe Diagramm einfach zu benutzen!! Ihr mathematischer Freund in Boston, Sylvia Hobbs Boston, Massachusetts sylvia.hobbs@state.ma.us -----Original Message----- === Subject: Special characters for German Can you tell me how to be able to type the umlauts , using an English === Subject: Re: Failure to Evaluate? What is the D in the defination of h? D[f, x] gives the partial derivative ?f/?x, but D[f]/D[g] means nothing. Scott Guthery > f:=Function[#1^2/#1+1] > g:=Function[#1^4+7] > h:=D[f]/D[g] > h[1] > Gives > ((#1^2/#1)+1 &)/(#1^4+7 &)[1] > Why doesn't it evaluate by setting #1 to 1 to get 1/4? > h/.#1->1//N sets #1 to 1 and gives > (1 1 + 1 &)/(1 + 7 &) > but still doesn't evaluate to 1/4. > What gives? What's the Right Stuff? === Subject: Re: Failure to Evaluate? >f:=Function[#1^2/#1+1] >g:=Function[#1^4+7] >h:=D[f]/D[g] >h[1] >Gives >((#1^2/#1)+1 &)/(#1^4+7 &)[1] >Why doesn't it evaluate by setting #1 to 1 to get 1/4? Because that would not necessarily be the correct answer. You defined h as the derivative of f divided by the derivative of g but failed to specify what the derivative was with respect to. That is D takes two arguments, the function to differentiate and a variable, i.e., D[x+2 y, x] != D[x+ 2 y, y] Since you didn't supply D with sufficient information, it returned the only argument you supplied it unevaluated, which is exactly what you see in the answer. -- To reply via email subtract one hundred and four === Subject: MLPutFunction : how to put a pure function I am writing a Mathematica FrontEnd in C using Mathlink. How to put a expression such as Function[z,z+1][5] (from C to Mathematica)? The standard C function 'MLPutFunction' can't do that, because the head of the expression is still a compound expression but not a symbol. The same situation happens when such a expression was returned from Mathematica. Obviously, 'MLGetFunction' can't do the job. === Subject: ReadListBinary question Is there any reason why ReadListBinary[stream,type,n] doesn't let me use a variable for n (e.g. If I set nval=5, and ReadListBinary[stream,type,nval] -- it won't work)? Are there any workarounds for this? --j === Subject: Re: ReadListBinary question Evaluate[nval] in the call, which seemed to work well. --j > Is there any reason why ReadListBinary[stream,type,n] doesn't let me use a > variable for n (e.g. If I set nval=5, and ReadListBinary[stream,type,nval] > -- it won't work)? Are there any workarounds for this? > --j === Subject: Re: ReadListBinary question ReadListBinary has attribute HoldRest You can use ClearAttributes for ReadListBinary to pass the value of nval to it. But I don't know what the side effects would be. Instead I would recast reading using SetDelayed fread[nval_] := ReadListBinary[filename, type, nval] In[1]:= < Is there any reason why ReadListBinary[stream,type,n] doesn't let me > use a > variable for n (e.g. If I set nval=5, and > ReadListBinary[stream,type,nval] > -- it won't work)? Are there any workarounds for this? > --j === Subject: Re: ReadListBinary question I've had this problem myself just recently. I've not really figured out why it's happening, but in my code at least, if you wrap an Execute around the nval, things seem to work. Try ReadListBinary[stream,type,Execute[nval]] -MJ Person mjperson@mit.edu greenberg@ucdavis.edu Wrote: > Is there any reason why ReadListBinary[stream,type,n] doesn't let me > use a variable for n (e.g. If I set nval=5, and > ReadListBinary[stream,type,nval] -- it won't work)? Are there any > workarounds for this? === Subject: Re: integral question > I have a simple integral as follows: > Given r^2= x^2+y^2, solve Integral[r^2, dr] from point1 (0,0) to point2 > (1,1), which would be evaluated from r=0 to r=sqrt[2] and gives answer = > 2*sqrt[2]/3. > The above is pretty simple, however, I am not sure how to formulate the > problem when I convert the 'dr' back to cartesian coordinates as follows: > Integrate [x^2+y^2, d????] and the limits??? WHat should 'dr' be in terms > of dx? if my integrand is directly x^2+y^2. You are computing a line integral. See, e.g., http://ltcconline.net/greenl/courses/202/vectorIntegration/lineIntegrals. htm In general, if you parameterize x and y as a function of t then the line integral of f[x,y] from {x[a],y[a]} to {x[b],y[b]} is Integrate[f[x[t], y[t]] Sqrt[x'[t]^2 + y'[t]^2], {t, a, b}] Your function is r[x_,y_] = x^2+y^2; and the (straight line) parameterization is x[t_] = t; y[t_] = t; where a = 0 and b = 1. Then the line integral is Integrate[r[x[t], y[t]] Sqrt[x'[t]^2 + y'[t]^2], {t, 0, 1}] Paul -- Paul Abbott Phone: +61 8 9380 2734 School of Physics, M013 Fax: +61 8 9380 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: RE: integral question Doing this in some detail, we have for the original integral in terms of r... eqn0 = r^2 == x^2 + y^2 Sqrt /@ % Simplify[%, r > 0] eqn1 = Reverse[%] giving r^2 == x^2 + y^2 Sqrt[r^2] == Sqrt[x^2 + y^2] Sqrt[x^2 + y^2] == r r == Sqrt[x^2 + y^2] Now finding the r limits along your line. eqn1 /. Thread[{x, y} -> {0, 0}] eqn1 /. Thread[{x, y} -> {1, 1}] giving r == 0 r == Sqrt[2] Integrate[r^2, {r, 0, Sqrt[2]}] (2*Sqrt[2])/3 Converting into an integral with x and dx. We first solve for dr (== Dt[r]) eqn0 % /. y -> x Dt[%] drrule = Solve[%, Dt[r]][[1,1]] giving r^2 == x^2 + y^2 r^2 == 2*x^2 2 r Dt[r] == 4 x Dt[x] Dt[r] -> (2*x*Dt[x])/r Then calculating the new integral in terms of x and dx... r^2Dt[r] % /. drrule % /. r -> Sqrt[x^2 + y^2] % /. y -> x Simplify[%, x > 0] giving r^2*Dt[r] 2*r*x*Dt[x] 2*x*Sqrt[x^2 + y^2]*Dt[x] 2*Sqrt[2]*x*Sqrt[x^2]*Dt[x] 2*Sqrt[2]*x^2*Dt[x] We can then do the integral over x. Integrate[2*Sqrt[2]*x^2, {x, 0, 1}] (2*Sqrt[2])/3 David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ I have a question and was wondering if someone could help me with it. This is a general vector calculus problem, not specific to Mathematica. I have a simple integral as follows: Given r^2= x^2+y^2, solve Integral[r^2, dr] from point1 (0,0) to point2 (1,1), which would be evaluated from r=0 to r=sqrt[2] and gives answer = 2*sqrt[2]/3. The above is pretty simple, however, I am not sure how to formulate the problem when I convert the 'dr' back to cartesian coordinates as follows: Integrate [x^2+y^2, d????] and the limits??? WHat should 'dr' be in terms of dx? if my integrand is directly x^2+y^2. It cannot be a double integral, since the original problem was a single integral, but then how do you solve this?? Can anyone help? === Subject: Asymmetric quadratic coefficient problem Does any one know how to deal with asymmetric quadratic coefficient in QuadraticFormDistribution[ {A,b,c}, {mu, sigma}] for z'Az+b'z+c? Mathematica assumes A is a symmetric matrix, but I now have an asymmetric and singular matrix A. Also, I'd really appreciate if any expert here can give me some clue/reference about the following problem: how can I calculate different quantiles of a mixture distribution? One way is to do the simulation, but is it possible to use the function Quantile[.] in Mathematica? if yes, how? Xiao _________________________________________________________________ Overwhelmed by debt? Find out how to ÎDig Yourself Out of Debtâ from MSN Money. http://special.msn.com/money/0407debt.armx === Subject: Re: Asymmetric quadratic coefficient problem As to your first question: You can easily convice yourself that the asymmetric part of the matrix A just drops out of the term z'Az. Let S=(A+Transpose[A])/2 (symmetric part of A) N=(A-Transpose[A])/2 (asymmetric part of A) then, obviously A = S+N and we have z'Az = z'Sz + z'Nz but the term x=z'Nz vanishes because (not in strict Mathematica style) x=z'Nz = Sum[ z[i] N[i,k] z[k] ] = Sum[ z[k] N[k,i] z[i] ] (just renaming summation indices) = - Sum [ z[i] N[i,k] z[k] ] (because of N[k,i] = - N[i,k] ) = - x Hences x=0. Hope this helps. Wolfgang > Does any one know how to deal with asymmetric quadratic coefficient in > QuadraticFormDistribution[ {A,b,c}, {mu, sigma}] for z'Az+b'z+c? > Mathematica assumes A is a symmetric matrix, but I now have an asymmetric > and singular matrix A. > Also, I'd really appreciate if any expert here can give me some > clue/reference about the following problem: how can I calculate different > quantiles of a mixture distribution? One way is to do the simulation, but is > it possible to use the function Quantile[.] in Mathematica? if yes, how? > Xiao > _________________________________________________________________ > Overwhelmed by debt? Find out how to 'Dig Yourself Out of Debt' from MSN > Money. http://special.msn.com/money/0407debt.armx === Subject: Re: Asymmetric quadratic coefficient problem > Does any one know how to deal with asymmetric quadratic coefficient in > QuadraticFormDistribution[ {A,b,c}, {mu, sigma}] for z'Az+b'z+c? Use (A + Transpose@A)/2 instead of A. === Subject: Re: Asymmetric quadratic coefficient problem > Does any one know how to deal with asymmetric quadratic coefficient in > QuadraticFormDistribution[ {A,b,c}, {mu, sigma}] for z'Az+b'z+c? > Mathematica assumes A is a symmetric matrix, but I now have an asymmetric > and singular matrix A. > Also, I'd really appreciate if any expert here can give me some > clue/reference about the following problem: how can I calculate different > quantiles of a mixture distribution? One way is to do the simulation, but is > it possible to use the function Quantile[.] in Mathematica? if yes, how? > Xiao Replace your asymmetric matrix A with the symmetric matrix (A + A') / 2. Note that z'[(A + A') / 2]z = z'Az / 2 + z'A'z / 2 = z'Az / 2 + (z'Az)' / 2 = z'Az / 2 + z'Az / 2 = z'Az. Rob === Subject: Re: vector integral If I understand your problem correctly I would restate it as follows. The integral you're looking for is a vector because dr is a vector. Hence it is defined more completely as (denoting vectors by a_ etc.) I_ = { Integrate[ r^2 , x], Integrate [r^2 , y] } You have now to define the path in the x-y plane along which the integral is to be taken, and then express the relation between y and x along that path, so that you have y=y[x] and dy = D[y,x] dx and there remains an integral over x for both components of I_. Alternatively, and more genrally you can express both x and y as function od a parameter, say t, and transform the integrals into ones over t. Here are some simple examples (direct method first) 1) from {0,0} to {a,0} Here we have dy = 0. Furthermore we have y=0 hence r^2 = x^2. Thus I_ = { Integrate[x^2,{x,0,a}], 0 } = { (1/3) a^3, 0 } 2) Your example path is the line from {0,0} to {1,1}. Hence dy=dx, y=x which gives r^2 = x^2 + y^2 = 2 x^2. Thus I_ = { Integrate[2 x^2,{x,0,1}], Integrate[2 x^2,{x,0,1}] } = { (2/3) , 2/3 } 3) Part of the unit circle starting at {1,0} going to angle phi (parameter t) x = Cos[t], y = Sin[t] dx = - Sin[t] dt, dy = Cos[t] dt r^2 = 1 I_ = { Integrate[ -Sin[t],{t,0,phi}], Integrate[ Cos[t], {t,0,phi}] = { Cos[phi] - 1, Sin[phi] } Hope this helps. Wolfgang > I have a question and was wondering if someone could help me with it. This > is a general vector calculus problem, not specific to Mathematica. I have a > simple integral as follows: > Given r^2= x^2+y^2, solve Integral[r^2, dr] along vector defined by point1 > (0,0) to point2 > (1,1), which would be evaluated from r=0 to r=sqrt[2] and gives answer = > 2*sqrt[2]/3. > The above is pretty simple, however, I am not sure how to formulate the > problem when I convert the 'dr' back to cartesian coordinates as follows: > Integrate [x^2+y^2, d????] and the limits??? WHat should 'dr' be in terms > of dx? if my integrand is directly x^2+y^2. It cannot be a double integral, > since the original problem was a single integral, but then how do you solve > this?? > Can anyone help? === Subject: Recursion depth Recursion depth exceeded while trying to solve four simultaneous ODEs. How to fix this? TIA. Clear[s,si2,r2,th2,ph2,si,r,th,ph]; equns={si2''[s]==-Sin[si2[s]]*Sin[ph2[s]], si2'[0]==.2, si2[0]==-1.5, ph2'[s]== -Cos[ph2[s]]*Cos[si2[s]]/r2[s],ph2[0]==-.01, r2'[s]==Cos[si2[s]],r2[0]==1.25, th2'[s]==Sin[si2[s]]/r2[s],th2[0]== 1}; NDSolve[equns,{si2,r2,th2,ph2},{s,0,1}]; === Subject: Re: Recursion depth It works just fine at my machine, using version 5.0.1. Bobby > Recursion depth exceeded while trying to solve four simultaneous ODEs. > How to fix this? TIA. > Clear[s,si2,r2,th2,ph2,si,r,th,ph]; > equns={si2''[s]==-Sin[si2[s]]*Sin[ph2[s]], > si2'[0]==.2, si2[0]==-1.5, > ph2'[s]== -Cos[ph2[s]]*Cos[si2[s]]/r2[s],ph2[0]==-.01, > r2'[s]==Cos[si2[s]],r2[0]==1.25, > th2'[s]==Sin[si2[s]]/r2[s],th2[0]== 1}; > NDSolve[equns,{si2,r2,th2,ph2},{s,0,1}]; === Subject: Re: Recursion depth Mathematica 5.0.1 solves these ODEs using your code. In case it is any help to you here is the FullForm version of the solution {si2[s],r2[s],th2[s],ph2[s]} that I obtained: List[InterpolatingFunction[List[List[0.`,1.`]], List[1,2,True,Real,List[3],List[0]], List[List[0.`,0.00009533963472195465`,0.0001906792694439093`, 0.007298682413533105`,0.014406685557622301`,0.0215146887017115`, 0.04271275658506481`,0.06391082446841811`,0.08510889235177144`, 0.10630696023512475`,0.14870309600183138`,0.191099231768538`, 0.2334953675352446`,0.2758915033019512`,0.31828763906865787`, 0.3997983119521431`,0.48130898483562834`,0.5628196577191136`, 0.6443303306025988`,0.725841003486084`,0.8073516763695694`, 0.9036758381847847`,1.`]], List[List[0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63, 66,69],List[-1.5`,0.2`,-0.004987391808853677`,-1.4999809321637718`, 0.19999904849588407`,-0.004990076366041424`,-1.4999618644183084`, 0.19999809647974534`,-0.004992761622783256`,-1.498540534679022`, 0.19992568253845477`,-0.005194901469456241`,-1.4971197299691923`, 0.19985036740324427`,-0.005400920406781723`,-1.4956994711062206`, 0.19977209599618165`,-0.0056108089743061`,-1.4914672990676239`, 0.19952060702127164`,-0.006259642195934895`,-1.4872407627692799`, 0.19924086669908314`,-0.006942535377643348`,-1.4830204683806087`, 0.19893145727547437`,-0.00765920909935484`,-1.4788070599358991`, 0.19859095285808823`,-0.008409364193681502`,-1.4704036246231706`, 0.19781102053008992`,-0.010008845794748712`,-1.4620362052886506`, 0.19688993397212082`,-0.011738272427899998`,-1.4537110248092326`, 0.1958168013056401`,-0.013594684842870488`,-1.4454347524267483`, 0.19458098780030553`,-0.015574880291918372`,-1.437214505652577`, 0.1931721418980054`,-0.01767541568723259`,-1.421595776690298`, 0.189940724252321`,-0.022038313015607238`,-1.4062703443490072`, 0.18596481931077138`,-0.02680394640153168`,-1.391301491931676`, 0.18118127948598003`,-0.031941340394863016`,-1.3767574501048336`, 0.1755321746152456`,-0.03741729729766833`,-1.3627109451801283`, 0.16896513747865247`,-0.04319690281328978`,-1.3492387364201326`, 0.16143359587115574`,-0.04924407703051103`,-1.33416846999958`, 0.15123474948947963`,-0.0566850536118796`,-1.32015049659536`, 0.1395762062191881`,-0.06438814759908776`]]][s], InterpolatingFunction[List[List[0.`,1.`]], List[1,1,True,Real,List[3],List[0]], List[List[0.`,0.00009533963472195465`,0.0001906792694439093`, 0.007298682413533105`,0.014406685557622301`,0.0215146887017115`, 0.04271275658506481`,0.06391082446841811`,0.08510889235177144`, 0.10630696023512475`,0.14870309600183138`,0.191099231768538`, 0.2334953675352446`,0.2758915033019512`,0.31828763906865787`, 0.3997983119521431`,0.48130898483562834`,0.5628196577191136`, 0.6443303306025988`,0.725841003486084`,0.8073516763695694`, 0.9036758381847847`,1.`]], List[List[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42, 44,46],List[1.25`,0.0707372016677029`,1.2500067458723336`, 0.07075622172593408`,1.2500134935580216`,0.0707752416678537`, 1.2505216026833772`,0.07219293520415954`,1.2510397863996277`, 0.07360995929272424`,1.2515680398647995`,0.07502629042841734`, 1.2532031886311146`,0.07924585060951676`,1.2549277086493238`, 0.08345837270798082`,1.2567414455004713`,0.08766318878502834`, 1.258644228353726`,0.09185958577772692`,1.2627161721753573`, 0.10022414880866037`,1.2671418565808956`,0.10854583205706149`, 1.2719193205040418`,0.11681796558962369`,1.2770463163632537`, 0.12503347835018544`,1.2825202867182963`,0.13318490069382438`, 1.2940084661091313`,0.14864761043319752`,1.3067441796415384`, 0.16378473244679434`,1.3206983062225555`,0.17853254972515142`, 1.3358363890942992`,0.19282353869263702`,1.352118329152839`, 0.2065869637124943`,1.369498148699033`,0.21974940706660878`, 1.3913802649120397`,0.23442579205034605`,1.4146254498944555`, 0.24802966113501462`]]][s], InterpolatingFunction[List[List[0.`,1.`]], List[1,1,True,Real,List[3],List[0]], List[List[0.`,0.00009533963472195465`,0.0001906792694439093`, 0.007298682413533105`,0.014406685557622301`,0.0215146887017115`, 0.04271275658506481`,0.06391082446841811`,0.08510889235177144`, 0.10630696023512475`,0.14870309600183138`,0.191099231768538`, 0.2334953675352446`,0.2758915033019512`,0.31828763906865787`, 0.3997983119521431`,0.48130898483562834`,0.5628196577191136`, 0.6443303306025988`,0.725841003486084`,0.8073516763695694`, 0.9036758381847847`,1.`]], List[List[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42, 44,46],List[1.`,-0.7979959892832436`, 0.9999239198673432`,-0.7979906035796773`, 0.9998478402482894`,-0.7979852164916424`, 0.9941771999100659`,-0.797579732839867`, 0.9885094690099041`,-0.7971665792449575`, 0.9828447019740946`,-0.7967457815057992`, 0.9659688705209264`,-0.7954457115458904`, 0.9491213297754195`,-0.7940786211684414`, 0.9323034722793107`,-0.7926452776403052`, 0.9155166939236691`,-0.7911464952623136`, 0.8820418697026856`,-0.7879560783162229`, 0.8487076552067281`,-0.784514725733165`, 0.8155245177129057`,-0.7808304563915742`, 0.782502576464965`,-0.7769119338400645`, 0.7496515681909222`,-0.7727684451790683`, 0.6870064659220974`,-0.764206925285944`, 0.6250890624800383`,-0.7549267248016657`, 0.5639545942005394`,-0.7450104244498289`, 0.5036513578753655`,-0.7345461299746177`, 0.4442202819845077`,-0.7236261960033303`, 0.3856946389763214`,-0.7123458722340958`, 0.31773423217980873`,-0.6986832012873263`, 0.25110118392406383`,-0.6848119680887575`]]][s], InterpolatingFunction[List[List[0.`,1.`]], List[1,1,True,Real,List[3],List[0]], List[List[0.`,0.00009533963472195465`,0.0001906792694439093`, 0.007298682413533105`,0.014406685557622301`,0.0215146887017115`, 0.04271275658506481`,0.06391082446841811`,0.08510889235177144`, 0.10630696023512475`,0.14870309600183138`,0.191099231768538`, 0.2334953675352446`,0.2758915033019512`,0.31828763906865787`, 0.3997983119521431`,0.48130898483562834`,0.5628196577191136`, 0.6443303306025988`,0.725841003486084`,0.8073516763695694`, 0.9036758381847847`,1.`]], List[List[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42, 44,46],List[-0.01`,-0.05658693186967461`,-0.010005396398620246`,-0. 056601838637037855`,-0.010010794218413816`,-0.05661674506423603`,-0. 010417172515977789`,-0.057727126013509454`,-0.010831436527801497`,-0. 05883557195552481`,-0.011253572342289249`,-0.059942038557714364`,-0. 012559110334902618`,-0.06322965151454743`,-0.013934132766244799`,-0. 06649807007821537`,-0.015378225427221845`,-0.06974610694152882`,-0. 016890943484591383`,-0.0729725525765394`,-0.020120349860873292`,-0. 07935580839909083`,-0.023618277909054523`,-0.08563805091248743`,-0. 027380230645714907`,-0.09180942424617795`,-0.03140130137454962`,-0. 09786006796067681`,-0.0356761630948117`,-0.10378015299772099`,-0. 044586580654758255`,-0.11475959077771011`,-0.05436849937914773`,-0. 1251528235706858`,-0.06497147806727649`,-0.1348952006755518`,-0. 07633996868658957`,-0.1439262663315521`,-0.08841370394320949`,-0. 1521908562073985`,-0.10112816739235099`,-0.15964000122076033`,-0. 11688580643365921`,-0.16733471329358596`,-0.13332466831559348`,-0. 17377638937890727`]]][s]] Steve Luttrell > Recursion depth exceeded while trying to solve four simultaneous ODEs. > How to fix this? TIA. > Clear[s,si2,r2,th2,ph2,si,r,th,ph]; > equns={si2''[s]==-Sin[si2[s]]*Sin[ph2[s]], > si2'[0]==.2, si2[0]==-1.5, > ph2'[s]== -Cos[ph2[s]]*Cos[si2[s]]/r2[s],ph2[0]==-.01, > r2'[s]==Cos[si2[s]],r2[0]==1.25, > th2'[s]==Sin[si2[s]]/r2[s],th2[0]== 1}; > NDSolve[equns,{si2,r2,th2,ph2},{s,0,1}]; === Subject: =?ISO-8859-1?Q?How_to_creat_this_8=D78_images?= I need to creat a 8*8 image in which the pixels are drawn according to a Laplacian or some other heavy tailed distribution. Does anybody know how to code it? === Subject: Re: Select from a list Just use Union. {1, 1, 2, 2, 4, 6, 6, 8, 8, 9} // Union {1, 2, 4, 6, 8, 9} If your elements are not in sorted order and you want to keep them in the same order, then look at the UnsortedUnion example in the Union Help Examples. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi everyone, Does anyone have an idea to drop the repeating elements in one list? The list was built in sequence,fortunately. for example, from a={1,1,2,2,4,6,6,8,8,9} to a1={1,2,4,6,8,9} The purpose is to avoid the one-to-many mapping problem in my case. Feng-Yin Chang, Institute of Physics,NCTU,Taiwan === Subject: Re: Forcing Argument Evaluation Scott, If you want to use operators this way you might want to look at the Algebra`PushThrough package at my web site below. Needs[Algebra`PushThrough`] f[x_] := x^2; {f, f/2}[2] % // PushThrough[] {f, f/2}[2] {4, 2} Whereas if you use the regular Through command you get {f, f/2}[2] // Through {4, (f/2)[2]} Similarly (f/2)[2] // Through 4*(1/2)[2] Through pushed the argument 2 onto f AND onto (1/2). (f/2)[2] // PushThrough[] 2 Also (f/a)[2] // PushThrough[Constants -> {a}] 4/a (f^2 - 2*f)[x]//PushThrough[] -2*x^2 + x^4 but (f^2 - 2f)[x] // Through (-2*f)[x] + (f^2)[x] David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ f[x_] := x^2; a = {f,f/2}; a[[1]][2] 4 a[[2]][[2] f/2[2] I know I'm missing something fundamental. === Subject: New webMathematica Author Provides Authoring Environment for webMathematica New webMathematica Author Provides Authoring Environment for webMathematica To help support the growing webMathematica community, Wolfram Research has made available a new utility called webMathematica Author, which registered users can download at no charge from the company's website. webMathematica Author is a Mathematica application that aids in the creation and development of JavaServer Pages (JSP) for use with webMathematica. It provides Mathematica users with functions and palette options that simplify the construction and layout of commonly used HTML and webMathematica tags, thereby easing the webMathematica development process. Mathematica users who may not be familiar with HTML or with webMathematica's JavaServer Pages syntax will benefit most from the increased accessibility provided by webMathematica Author. The webMathematica Author documentation includes many of the same examples that shipped with webMathematica 2.1, which lets new users see how the creation of the same applications is simplified by the use of webMathematica Author. webMathematica Author is compatible with Mathematica 5 and designed for use with webMathematica 2.1. More information is available at: http://www.wolfram.com/webmathematicaauthor === Subject: Re: Select from a list One way to do it is with ReplaceRepeated (//.): In[1]:= a = {1, 1, 2, 2, 4, 6, 6, 8, 8, 9} Out[1]= {1, 1, 2, 2, 4, 6, 6, 8, 8, 9} In[2]:= a //. {{pre___, x_, x_, post___} : > {pre, x, post}} Out[2]= {1, 2, 4, 6, 8, 9} Ken Levasseur Math. Sci. UMass Lowell > Hi everyone, > Does anyone have an idea to drop the repeating elements in one list? > The list was built in sequence,fortunately. > for example, > from a={1,1,2,2,4,6,6,8,8,9} > to a1={1,2,4,6,8,9} > The purpose is to avoid the one-to-many mapping problem in my case. > Feng-Yin Chang, > Institute of Physics,NCTU,Taiwan === Subject: Re: Select from a list [Other posts that gave this exact answer will not be posted - moderator] > Hi everyone, > Does anyone have an idea to drop the repeating elements in one list? > The list was built in sequence,fortunately. > for example, > from a={1,1,2,2,4,6,6,8,8,9} > to a1={1,2,4,6,8,9} Union[a1] Ssezi === Subject: Select from a list Hi everyone, Does anyone have an idea to drop the repeating elements in one list? The list was built in sequence,fortunately. for example, from a={1,1,2,2,4,6,6,8,8,9} to a1={1,2,4,6,8,9} The purpose is to avoid the one-to-many mapping problem in my case. Feng-Yin Chang, Institute of Physics,NCTU,Taiwan === Subject: Re: Select from a list This does what you want: a={1,1,2,2,4,6,6,8,8,9}; b=Split[a] {{1,1},{2,2},{4},{6,6},{8,8},{9}} Map[First,b] {1,2,4,6,8,9} Steve Luttrell > Hi everyone, > Does anyone have an idea to drop the repeating elements in one list? > The list was built in sequence,fortunately. > for example, > from a={1,1,2,2,4,6,6,8,8,9} > to a1={1,2,4,6,8,9} > The purpose is to avoid the one-to-many mapping problem in my case. > Feng-Yin Chang, > Institute of Physics,NCTU,Taiwan === Subject: Re: Re: Does anybody? I tried sending you a notebook with some examples I had saved up but your email comes back as undeliverable... Jerry blimbaum -----Original Message----- === Subject: Re: Does anybody? > Does anybody here met the problem of soving Integral equations. Maybe > someone would give here link to some examples? Esspecialy of so called > ill-posed problems (Fredholm equations of the FIRS > kind) and Tchonov Reguralizations etc. > Mithras Really nobody have an idea? I found some regularization tools for another system. Is there anything like that for Mathematica? Mithras === Subject: RealDigits rounds sometimes In Mathematica 5.01: RealDigits[Pi,10,5] gives 3.1416 RealDigits[355/113,10,5] gives 3.1415 RealDigits[355./113,10,5] gives 3.1416 Earlier versions, Mathematica 4.1 and 4.2 never round as near as I can tell. Can anyone tell me under what conditions I can expect rounding to occur, and can I stop this behavior in 5.01? === Subject: problem with ExpectedValue[xx-x, PoissonDistribution[m],x] Why can Mathematica not evaluate ExpectedValue[x x - x, PoissonDistribution[m], x] ? It can correctly evaluate all the following: ExpectedValue[x x , PoissonDistribution[m], x] ExpectedValue[x , PoissonDistribution[m], x] ExpectedValue[x x + x , PoissonDistribution[m], x] ExpectedValue[x x + a x , PoissonDistribution[m], x] Is it anticipating to think that I've found a Mathematica bug, in my first hour of using Mathematica? (If so, that's rather good for me and new SW packages). === Subject: Problem with eval. of neg. cube root of neg. # I am having trouble plotting the following function: Plot[x^(1/3)*(x + 4), {x, -10, 10}] Mathematica won't plot this function for negative x, although it is obviously defined for negative x. It seems to be evaluating the negative part of this function to imaginary numbers for some odd reason.If I do: f[x_] := (x^(1/3))*(x + 4) and then: f[-5] // N I get: -0.854988 - 1.48088 [ImaginaryI] when the correct answer is the negative cube root of negative 5, which is approximately - (-1.70998) = 1.70998 I can send a copy of the notebook that shows where this is happening to anyone who requests it... Can anyone explain what is going on here? Is this a bug or am I missing something? === Subject: Re: Does anybody? In electrochemistry the closed form solution for a technique called cyclic voltammetry is a first kind volterra equation. If other reactions are couples to the electrochemical reaction the solution is a 2nd kind volterra or freidholm eqn. (I'm not a mathematician and always get the difference between these mixed up). I solve these in mathematica using a numerical method which seems to be the convention in my field see: Nicholson, R. S. and Shain, I. (1964). Analytical Chemistry, 36, 704-23. Nicholson, R. S. (1965). Analytical Chemistry, 37, 1351-5. Nicholson, R. S. and Olmstead, M. L. (1972). Numerical solution of integral equations. In Electrochemistry; calculations, simulations, and instrumentation, (ed. J. S. Mattson, H. B. Mark jnr., and H. C. MacDonald jnr.), pp. 119-38. Marcel Dekker, New York. Implementation in Mathematica depends on how much you know about mathematica. A procedural implementation based on the methods described in these refs is straight forward but slow. A functional implementation is a bit more complicated but solves in less than a second (in my case the problem must be solved at each potential and typically needs to be solved 400 or so times so less than a second per 400 results is good for me). use of Chebyshev polynomials to solve integral equations. This was based on include the year and volume. Hope that is of some help. Mike > Does anybody here met the problem of soving Integral equations. Maybe > someone would give here link to some examples? > Esspecialy of so called ill-posed problems (Fredholm equations of the FIRS > kind) and Tchonov Reguralizations etc. > Mithras === Subject: Re: Does anybody? > Does anybody here met the problem of soving Integral equations. Maybe > someone would give here link to some examples? latest issue of The Mathematica Journal: http://mathematica-journal.com/issue/v9i2/ Paul -- Paul Abbott Phone: +61 8 9380 2734 School of Physics, M013 Fax: +61 8 9380 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: Does anybody? > Does anybody here met the problem of soving Integral equations. Maybe > someone would give here link to some examples? > Esspecialy of so called ill-posed problems (Fredholm equations of the FIRS > kind) and Tchonov Reguralizations etc. > Mithras Really nobody have an idea? I found some regularization tools for another system. Is there anything like that for Mathematica? Mithras === Subject: Re: Does anybody? > Does anybody here met the problem of soving Integral equations. Maybe > someone would give here link to some examples? > Esspecialy of so called ill-posed problems (Fredholm equations of the FIRS > kind) and Tchonov Reguralizations etc. > Mithras > Really nobody have an idea? > I found some regularization tools for another system. Is there anything like > that for Mathematica? > Mithras Perhaps http://www.dm.unife.it/pn2o/unit2.html is of interest. Paul -- Paul Abbott Phone: +61 8 9380 2734 School of Physics, M013 Fax: +61 8 9380 1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Odd evaluate behavior in notebooks... I get this really odd evaluate situation quite a bit -- I'll go hit alt-enter on a windows box to run a section in a notebook, and it does nothing. However, if I remove some comment lines (literally deleting them), it will suddenly start running again! No, my comment lines are not open (e.g. I didn't leave a *) missing), and the behavior is a bit random... Anyone ever come across this? --j === Subject: Re: populate a list with random numbers from normaldistribution? Check your syntax. Look at the following: In[1]:= << Statistics` In[2]:= dist = NormalDistribution[50000, 25000]; In[4]:= Table[Random[dist], {10}] Out[4]= {26975.950556122647, 58550.03432245862, 90456.47272543506, 73888.28476391576, 52046.50992913155, 72675.80052590193, 48593.27989475152, 78918.83089186646, 96303.52480806905, 69543.82643195332} What, then, do you mean by the variance of the above table? Tomas Garza Mexico City ----- Original Message ----- === Subject: populate a list with random numbers from normal distribution? > hello group. > I looked at the help browser but i can't figure this out. I weant to > make a list of random numbers sampled from a normal distribution > In[90]:= Needs[Statistics`ContinuousDistributions`] > l1 = Table[Random[NormalDistribution[50000,25000], Integer, {10000, > 99999}], {1000}]; > Variance[l1]//N > StandardDeviation[l1]//N > Random::randt: > Type specification NormalDistribution[50000, 25000] in > <<1>> should be Real, Integer, or Complex. > Out[92]= > 0. > Out[93]= > 0. > sean === Subject: Re: populate a list with random numbers from normal distribution? Needs[Statistics`ContinuousDistributions`]; data=RandomArray[NormalDistribution[50000,25000],{1000}]; #[data]& /@ {Mean, Variance, StandardDeviation} // N {49212.297808892145, 6.388327485991619*^8, 25275.140921450107} Since you seem to want Integers data=Round /@ data; #[data]& /@ {Mean, Variance, StandardDeviation} //N {49212.299, 6.388324440996987*^8, 25275.134897754724} Bob Hanlon === > Subject: populate a list with random numbers from normal distribution? > hello group. > I looked at the help browser but i can't figure this out. I weant to > make a list of random numbers sampled from a normal distribution > In[90]:= Needs[Statistics`ContinuousDistributions`] > l1 = Table[Random[NormalDistribution[50000,25000], Integer, {10000, > 99999}], {1000}]; > Variance[l1]//N > StandardDeviation[l1]//N > Random::randt: > Type specification NormalDistribution[50000, 25000] in > <<1>> should be Real, Integer, or Complex. > Out[92]= > 0. > Out[93]= > 0. > sean === Subject: similarity definition between two sets with the different cardinality Given two itemsets T={i1,i2,Á[CapitalEth],im}, TÁø={j1,j2,Á[CapitalEth],jn}, mÁôn also know the distance between any pair of elements from T and T' separately. how to define the similarity between T and T'? === Subject: Re: populate a list with random numbers from normaldistribution? Hi tomas What I wanted to do is to pick sets of random Integers in the ranges {10000, 99999} from the Normal distribution such that, the mean is 50000 and the standard deviation is 25000. or is that not normal distribution? will that be a custom distribution? if that isn't possible, then I want to pick set of random intgers ranging from {10000, 99999} such that the variance and the mean and standard deviation do not change across different runs. I think i'm supposed to use SeedRandom here but this caused me problems also. so I need to design a routine that will pick random integers in a given range with a given distribution different runs or simulations. any insights will be truly appreciated. sean > l1 = Table[Random[NormalDistribution[50000,25000], > Integer, {10000, 99999}], {1000}]; > Check your syntax. Look at the following: > In[1]:= > << Statistics` > In[2]:= > dist = NormalDistribution[50000, 25000]; > In[4]:= > Table[Random[dist], {10}] > Out[4]= > {26975.950556122647, 58550.03432245862, > 90456.47272543506, 73888.28476391576, > 52046.50992913155, 72675.80052590193, > 48593.27989475152, 78918.83089186646, > 96303.52480806905, 69543.82643195332} > What, then, do you mean by the variance of the above > table? > Tomas Garza > Mexico City > ----- Original Message ----- === > Subject: populate a list with random > numbers from normal > distribution? > hello group. > I looked at the help browser but i can't figure > this out. I weant to > make a list of random numbers sampled from a > normal distribution > In[90]:= > Needs[Statistics`ContinuousDistributions`] > l1 = Table[Random[NormalDistribution[50000,25000], > Integer, {10000, > 99999}], {1000}]; > Variance[l1]//N > StandardDeviation[l1]//N > Random::randt: > Type specification NormalDistribution[50000, > 25000] in > <<1>> should be Real, Integer, or Complex. > Out[92]= > 0. > Out[93]= > 0. > sean __________________________________ Do you Yahoo!? Y! Messenger - Communicate in real time. Download now. http://messenger.yahoo.com === Subject: Binomial ratio expectation I have the following problem, I need to compute EXPECTATION[X/(2+X)], where X follows Binomial distribution with n trials and success probability of w. I have tried to solve it with Mathematica (version 4.1) as Sum[((x)/(2 + x))*Binomial[n, x]*w^x*(1 - w)^(n - x), {x, 0, n}] I omit here the result which seems to be okay (according to simulations) for values 0 f[x_] := x^2; > a = {f,f/2}; > a[[1]][2] > a[[2]][[2] > f/2[2] > I know I'm missing something fundamental. It's the same problem again, which I already once explained. The algebra of functions is not implemented in Mathematica so although f is a function f/2 is not a function. So you can't expect f/2[2] to have return anything. If you really want implement the algebra of fucntions you could do something like this: Unprotect[Times,Plus]; (a_?NumericQ * f_)[x_]:=a f[x] (f_+g_)[x_]:=f[x]+g[x] (f_*g_)[x_]:=f[x]*g[x] Protect[Times,Plus] Now f[x_]:=x^2; a={f,f/2}; a[[2]][2] 2 Andrzej Kozlowski Chiba, Japan http://www.mimuw.edu.pl/~akoz/ === Subject: Re: Forcing Argument Evaluation f is a function, in the sense that when Mathematica sees it with an argument--f[2], for instance--your definition matches that pattern, so Mathematica can substitute 2 for x in the right-hand side and get 4. But f/2[2] doesn't match the pattern, so your definition doesn't take effect. If you want the elements of a to be functions, you can do this: f[x_] := x^2 a = {f, f[#1]/2 & , Function[y, f[y]/2]}; a[[2]][2] 2 a[[3]][3] 9/2 Here's a more complicated example: a = NestList[Function[y, Evaluate[#1[y]^3/2]] & , f, 3] {f, Function[y, y^6/2], Function[y, y^18/16], Function[y, y^54/8192]} Last[a][y] y^54/8192 Bobby > f[x_] := x^2; > a = {f,f/2}; >a[[1]][2] >a[[2]][[2] > f/2[2] >I know I'm missing something fundamental. -- DrBob@bigfoot.com www.eclecticdreams.net === Subject: Re: Forcing Argument Evaluation Head[a[[1]]] symbol but Head[a[[2]]] is Times. I guess the problem maybe lies in the symbol feature of funtions? c=a[[2]]; Head[c]@@List@@c[[2]]@5 There should be some simple answer to it daohua > f[x_] := x^2; > a = {f,f/2}; > a[[1]][2] > a[[2]][[2] > f/2[2] > I know I'm missing something fundamental. === Subject: Re: Forcing Argument Evaluation Although it is not needed in your case for a fuller implementation you also need to add rules involving Power: Unprotect[Times,Plus,Power]; (a_?NumericQ*f_.)[x_]:=a f[x]; (f_+g_)[x_]:=f[x]+g[x]; (f_*g_)[x_]:=f[x]*g[x]; (f_^n_?NumericQ)[x_]:=f[x]^n Protect[Times,Plus,Power]; Andrzej >> f[x_] := x^2; >> a = {f,f/2}; >> a[[1]][2] >> 4 >> a[[2]][[2] >> f/2[2] >> I know I'm missing something fundamental. > It's the same problem again, which I already once explained. The > algebra of functions is not implemented in Mathematica so although f > is a function f/2 is not a function. So you can't expect f/2[2] to > have return anything. If you really want implement the algebra of > fucntions you could do something like this: > Unprotect[Times,Plus]; > (a_?NumericQ * f_)[x_]:=a f[x] > (f_+g_)[x_]:=f[x]+g[x] > (f_*g_)[x_]:=f[x]*g[x] > Protect[Times,Plus] > Now > f[x_]:=x^2; > a={f,f/2}; > a[[2]][2] > Andrzej Kozlowski > Chiba, Japan > http://www.mimuw.edu.pl/~akoz/ === Subject: Re: Forcing Argument Evaluation > f[x_] := x^2; > a = {f,f/2}; > a[[1]][2] > a[[2]][[2] > f/2[2] a={f,f[#]/2&} Ssezi === Subject: Forcing Argument Evaluation f[x_] := x^2; a = {f,f/2}; a[[1]][2] 4 a[[2]][[2] f/2[2] I know I'm missing something fundamental. === Subject: Re: Forcing Argument Evaluation >f[x_] := x^2; a = {f,f/2}; a[[1]][2] gives 4 a[[2]][2] gives f/2[2] >I know I'm missing something fundamental. The source of the problem, here, is that in Mathematica any expression can have a head that is itself an expression . expr = head[arg_sequence] The head of the first expression is f and so head[2] matches f[x_]. The head of the second expression is f/2 and head[2] is Times[etc...], hence no match for f[x_]. The evaluation of the head does not carry anywhere, since it is done before the evaluation of the argument and of the expression as a whole. Of course, as you surely already know, you can operate on lists as you wished by defining each function in a 'stand alone' manner: a = { #^2 &, #^2/2 &}; a[[1]][2] gives 4 a[[1]][2] gives 2 You would also want to take a look at the older posts in the Mathgroup on how to implement operator algebra in Mathematica. Peltio Invalid address in reply-to. Crafty demnging required to mail me. === Subject: Simplify or Cancel question The following is a derived expression (using integration and Curl operations in M4.2) In[176]:= bloop ={(dz*(dz^2*(Ee-Ke)-Ke*(rp-rq)^2+Ee*(rp^2+rq^2)))/(2*Pi* rp*(dz^2+(rp-rq)^2)*Sqrt[dz^2+(rp+rq)^2]), 0,(dz^2*(-Ee+Ke)-(rp-rq)*(Ke*(-rp+rq)+Ee*(rp+rq)))/(2*Pi*(dz^2+(rp-rq)^2)* Sqrt[dz^2+(rp+rq)^2])} bcheck is from books In[159]:= bcheck = {(dz/(2*Pi*rp*Sqrt[(rp + rq)^2 + dz^2]))*(-Ke + ((rq^2 + rp^2 + dz^2)/(( rq - rp)^2 + dz^2))*Ee), 0, (1/( 2*Pi*Sqrt[(rp + rq)^2 + dz^2]))*( Ke + ((rq^2 - rp^2 - dz^2)/((rq - rp)^2 + dz^2))*Ee)} They are equivalent In[168]:= bloop - bcheck // FullSimplify Out[168]= {0, 0, 0} Can anyone reduce my expression to the better presented bcheck form? I have tried various options including In[169]:= Collect[bloop, {Ee, Ke}] In[161]:= bcheck // Expand // FullSimplify and dabbled with using elem={rp>0,rq>0,kk>0,Ee>0,Ke>0,Element[rp,Reals],Element[rq,Reals], Element[dz,Reals]} === Subject: Problem with FourierTransform Why doesn't this work: This FT can be computed without problems FourierTransform[Sin[t^2]/2+1/2] But this one FourierTransform[Sin[t^2/c]/2+1/2] gives error: Simplify::fas: Warning: self-contradictory assumptions encountered. Why? Oliver === Subject: 'Mathematica 5 not finding important resource' I'm coming here with some strange kind of problem. I recently upgraded from Mathetmatica 4.2 to 5.0.1. To be more precise, I uninstalled 4.2 and did a fresh install of 5.0.1, but when I start the program (any of the start menu points 'Kernel' or 'GUI'), all I get is a dialog box complaining Mathematica could not find an important resource, which didn't happen with 4.2. After clicking 'Ok', Mathematica exits. I've attached a jpeg image of the dialog box for full reference. I don't run it from a server, I have a normal hard disk installation, and doing a clean reinstall twice didn't help either. I wonder if this could be a known problem, but I could not find any documentation on the net (yet!). Btw, I'm running Mathematica on a German version of Windows 98, a collegue of mine running Windows 2000 English version does not have this problem. And sorry, upgrading to Windows 2000 is not an option... [Contact the author to obtain the jpeg image - moderator] Any help appreciated, Oliver Pfeiffer === Subject: Reduce/Solve I tend to think of Reduce as a more powerful tool than Solve, yet with eq = J == J0 (1 + r/d) Exp[-r/d] ss = Solve[eq, r] tt = Reduce[eq, r] I get useful output from Solve, but Reduce returns the expression unevaluated. What am I missing? Mathematica 5.0.0.0 under Windows XP. Tony Dr A.H. Harker Director of Postgraduate Studies Deputy Head, Condensed Matter and Materials Physics Group Department of Physics and Astronomy University College London Gower Street LONDON WC1E 6BT (44)(0)207 679 3404 a.harker@ucl.ac.uk