mm-4039 === Subject: Re: Problem with Thread over Plus? > Why does this work: > Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] > but this doesn't? > Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] > Vince Virgilio As stated by the error message returned by In[1], both list must be of equal lengths. Therefore, In[2], with three 1s rather than two, works as expected. In[1]:= Thread[{1, 1} + {{1, 1}, {2, 2}, {3, 3}}] Thread::tdlen: Objects of unequal length in {1, 1} + {{1, 1}, {2, 2}, {3, 3}} cannot be combined. Thread::tdlen: Objects of unequal length in {1, 1} + {{1, 1}, {2, 2}, {3, 3}} cannot be combined. Out[1]= {1, 1} + {{1, 1}, {2, 2}, {3, 3}} In[2]:= Thread[{1, 1, 1} + {{1, 1}, {2, 2}, {3, 3}}] Out[2]= {{2, 3, 4}, {2, 3, 4}} JM === Subject: Re: Problem with Thread over Plus? Hi Vincent, The argument of Thread will be evaluated before beeing fed to Thread. You are actually feeding the result of Plus[ {1,1} , { {1,1} , {2,2} } ], namely: List[{1 + a, 2 + b}, {1 + a, 2 + b}] to thread. The function List is then threaded. On the other hand, Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] will produce the error you saw. However, your first attempt does not actually give the correct answer. If you want to thread Plus over {1,1} and { {1,1} , {2,2} } you would use MapThread: MapThread[Plus, {{1, 1}, {{1, 1}, {2, 2}}}] and get: {{2, 2}, {3, 3}} Daniel > Why does this work: > Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] > but this doesn't? > Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] > Vince Virgilio > ************************************ > This e-mail and any files transmitted with it are proprietary and intende > d solely for the use of the individual or entity to whom they are address > ed. If you have received this e-mail in error please notify the sender. P > lease note that any views or opinions presented in this e-mail are solely > those of the author and do not necessarily represent those of ITT Indust > ries, Inc. The recipient should check this e-mail and any attachments for > the presence of viruses. ITT Industries accepts no liability for any dam > age caused by any virus transmitted by this e-mail. > ************************************ === Subject: Re: Problem with Thread over Plus? I wasn't thinking correctly about the original expressions. In fact, Mathematica handles both of them properly. Vince Virgilio -----Original Message----- === Subject: Re: Problem with Thread over Plus? > Why does this work: > Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] > but this doesn't? > Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] > Vince Virgilio Thread evaluates its argument(s) so in the first case you get the equivalent of this Plus[{1, 1}, {{1, 1}, {2, 2}}] {{2, 2}, {3, 3}} Thread[%] {{2, 3}, {2, 3}} while in the second Plus[ {1, 1} , { {1, 1} , {2, 2} , {3, 3} } ] tries to add lists of different lengths and fails. In fact, are you sure that you really meant to get the answer you did get in the case you claim works? Did you not rather mean this: Thread[Unevaluated[Plus[{1, 1} , {{1, 1}, {2, 2}}]]] {{2, 2}, {3, 3}} ? It is a little harder to make the second case work in the same way but of course it can be done: Thread[ Unevaluated[Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ],List,-1] {{2, 2}, {3, 3}, {4, 4}} Andrzej Kozlowski ************************************ This e-mail and any files transmitted with it are proprietary and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Industries, Inc. The recipient should check this e-mail and any attachments for the presence of viruses. ITT Industries accepts no liability for any damage caused by any virus transmitted by this e-mail. ************************************ === Subject: Bug with Series[] - help wanted Hello all! I would really appreciate some help. Mathematica has a built-in function called Series: Series[x,x_0,n], which allows to expand functions into power series where x is the variable, x_0 is the point about which we expand, and n is the desired order of expansion. It also allows x_0 to be infinity, which is very useful when one needs multiple expansion (as in gravitational waves and electromagnetic radiation). (and its powers) in the output, it does not allow this to be entered in the input. To convince yourselves, try it out. Enter in the input, e.g., 1+ 1/r+ (O(1/r))^2, and it will tell you that 1/r is not a variable. If, on the other hand, you entered: In=Series[1/(r+1), {r, Infinity,3}]//Simplify you will get Out=1/r-(1/r)^2+(1/r)^3+(O(1/r))^4 which shows that the output is possible, but the input is impossible. Can anyone offer some assistance? Gideon === Subject: Re: Bug with Series[] - help wanted > Hello all! > I would really appreciate some help. > Mathematica has a built-in function called Series: > Series[x,x_0,n], I suspect you meant to say something like Series[f, {x, x_0, n}]. > which allows to expand functions into power series where x is the > variable, x_0 is the point about which we expand, and n is the desired > order of expansion. > It also allows x_0 to be infinity, which is very useful when one needs > multiple expansion (as in gravitational waves and electromagnetic > radiation). > (and its powers) in the output, it does not allow this to be entered in > the input. To convince yourselves, try it out. Enter in the input, > e.g., 1+ 1/r+ (O(1/r))^2, and it will tell you that 1/r is not a > variable. Cutting and pasting the above input, my Mathematica didn't tell me that. Rather, it gave In[1]:= 1+ 1/r+ (O(1/r))^2 Out[1]= 1 + O^2/r^2 + 1/r But that's really beside the point. See below for what you need. > If, on the other hand, you entered: > In=Series[1/(r+1), {r, Infinity,3}]//Simplify > you will get > Out=1/r-(1/r)^2+(1/r)^3+(O(1/r))^4 > which shows that the output is possible, but the input is impossible. The output above is not what it naively appears to be. To see that, and to see how you'd need to input such a thing, just convert it to InputForm. In[2]:= Series[1/(r + 1), {r, Infinity, 3}]//InputForm Out[2]//InputForm= SeriesData[r, Infinity, {1, -1, 1}, 1, 4, 1] You might then want to look at the documentation for SeriesData. To enter the expression you mentioned earlier, you'd just use SeriesData[r, Infinity, {1, 1}, 0, 2, 1] David === Subject: Re: Problem with Thread over Plus? Use Trace Thread[Plus[{1, 1}, {{1, 1}, {2, 2}}]] // Trace You will see the step-by-step process and why the second example won't work. Bob Hanlon === > Subject: Problem with Thread over Plus? > Why does this work: > Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] > but this doesn't? > Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] > Vince Virgilio > ************************************ > This e-mail and any files transmitted with it are proprietary and intende > d solely for the use of the individual or entity to whom they are address > ed. If you have received this e-mail in error please notify the sender. P > lease note that any views or opinions presented in this e-mail are solely > those of the author and do not necessarily represent those of ITT Indust > ries, Inc. The recipient should check this e-mail and any attachments for > the presence of viruses. ITT Industries accepts no liability for any dam > age caused by any virus transmitted by this e-mail. > ************************************ === Subject: Re: Problem with Thread over Plus? >Why does this work: >Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] This is equivalent to {Plus[1,{1,1}],Plus[1,{2,2}]} >but this doesn't? >Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] The first argument to plus is a list of two elements and the second argument is a list of three elements. What would do expect Mathematica to do when there is no element in the first argument to correspond to the last element of the second argument. Perhaps you want {1,1}+$&/@{{1,1},{2,2},{3,3}} -- To reply via email subtract one hundred and four === Subject: Re: Two independent y axes ? >>I am trying to plot a bunch of functions and some data together. >>Some of the data and some of the functions have *very* different y >>range from the others. How do I create 2 independent y axes (like >>gnuplot - y and y2 axes) to show the data effectively ? > Is something like the following what you are looking for > In[8]:= > x = Sort[Table[Random[], {10}]]; > y = 20*Reverse[Sort[Table[Random[], {10}]]]; > In[10]:= > Show[Block[{$DisplayFunction = Identity}, > {ListPlot[Rescale[x], PlotStyle -> Blue], > ListPlot[Rescale[y], PlotStyle -> Red]}], > Frame -> True, FrameTicks -> {Automatic, > Range[0, 1, 0.2], None, ({#1, 20*#1} & ) /@ > Range[0, 1, 0.2]}]; > -- > To reply via email subtract one hundred and four time. These are physically distinct quantities and cannot share a y axis. Having colorful legends will not cut it. === Subject: Re: Two independent y axes ? > I am trying to plot a bunch of functions and some data together. > Some of the data and some of the functions have *very* different y > range from the others. How do I create 2 independent y axes (like > gnuplot - y and y2 axes) to show the data effectively ? >> Is something like the following what you are looking for >> In[8]:= >> x = Sort[Table[Random[], {10}]]; >> y = 20*Reverse[Sort[Table[Random[], {10}]]]; >> In[10]:= >> Show[Block[{$DisplayFunction = Identity}, >> {ListPlot[Rescale[x], PlotStyle -> Blue], >> ListPlot[Rescale[y], PlotStyle -> Red]}], >> Frame -> True, FrameTicks -> {Automatic, >> Range[0, 1, 0.2], None, ({#1, 20*#1} & ) /@ >> Range[0, 1, 0.2]}]; >> -- >> To reply via email subtract one hundred and four > time. These are physically distinct quantities and cannot share a y axis. > Having colorful legends will not cut it. I guess it was exacly that point, which caused Bill to propose a plot with 2 distinct y-axes (as you asked for) and not with any legend at all (as you see there). Have you got some kind of unruly Mathematica? ;-) Unfortunately, Bill's scaling is not correct: He rescales the random values from - say - [0.05,0.87]/[1.89,18.24] to [0,1], but scales the ticks from [0,1] to [0,1]/[0,20]. x = Sort[Table[Random[], {10}]]; y = 20*Reverse[Sort[Table[Random[], {10}]]]; With[{rg=Range[0, 1, 0.2], scal = Function[{v,r,n,f}, {#, NumberForm[Min[v] + #*(Max[v] - Min[v]), {n,f}]}&/@r]}, Show[Block[{$DisplayFunction = Identity}, {ListPlot[Rescale[x], PlotStyle -> {AbsolutePointSize[1], Blue}, PlotJoined -> True], ListPlot[Rescale[y], PlotStyle -> {AbsolutePointSize[1], Red}, PlotJoined -> True]}], Frame -> True, FrameTicks -> {Automatic, scal[x,rg,3,2], None, scal[y,rg,4,2]}, FrameStyle -> List /@ {Black, Blue, Black, Red}, PlotRange -> {All, {-0.05, 1.05}}, Axes -> None]]; Peter === Subject: Re: Problem with Infinite products > Maxim Rytin, > On that you are probably right, > I picked the default 1/2 to work at Zeta one, > It doesn't work at Zeta[2]. > It still should give a better answer. > I arranged it so it missed a singularity each time. > That got it: I used another If and it works: > f[n_, 1] := If[Mod[Prime[n], 12] - 1 == 0, Prime[n], 0] > f[n_, 2] := If[Mod[Prime[n], 12] - 5 == 0, Prime[n], 0] > f[n_, 3] := If[Mod[Prime[n], 12] - 7 == 0, Prime[n], 0] > f[n_, 4] := If[Mod[Prime[n], 12] - 11 == 0, Prime[n], 0] > zeta[x_, m_] := Product[If[f[n, m] == 0, 1, f[n, m]^(x)/(-1 + f[n, > m]^(x))], {n, 1, Infinity}] > The results look like the results I got from the sums. > Product values: > baa={1.00734,1.04776,1.02578,1.01143} > error is: > (3/2)*Apply[Times, baa] - Pi^2/6 > -0.00238175 > Sum values at 1000000 terms assuming equal populations: > ebb={1.02912,1.01745,1.0216,1.02518} > (3/2)*Apply[Times, ebb] - Pi^2/6 > 0.0000108624 > In any case it has been demonstrated that such product function factors > do exit. As far as I know this is a new unique approach to the Zeta > function. You've correctly reproduced the Euler product formula for the zeta function (only you split it into four separate products). Here's one way to improve the accuracy: In[1]:= NProduct[1/(1 - Prime[k]^-2), {k, Infinity}, Method -> Fit, NProductFactors -> 10^4, NProductExtraFactors -> 10^5] - Zeta[2] Out[1]= -7.5461329*^-8 It's interesting to note that Mathematica complains that the argument of Prime isn't integer, but still gives a numerical answer. This means that at some points it first tries evaluating the function with numericized values of k and then reverts to using the exact value. If we add Round, we don't get warnings but the computation takes much longer: In[2]:= Developer`ClearCache[]; NProduct[1/(1 - Prime[k]^-2), {k, Infinity}, Method -> Fit] // Timing Out[3]= {0.141*Second, 1.6435712} In[4]:= Developer`ClearCache[]; NProduct[1/(1 - Prime[Round[k]]^-2), {k, Infinity}, Method -> Fit] // Timing Out[5]= {8.546*Second, 1.6435712} Sometimes this 'numericizing' can be an issue, particularly if expressions of the form k[1] are used as variables and the index is left unchanged in one place and is converted to a machine number in another place: NIntegrate[1, {x[1], 0, 1}, {x[2], 0, x[1]}] This doesn't work (in Mathematica 5.2) because x[1] in the second iterator becomes x[1.], which is treated as a different variable. One way to make it work is to set the attribute NHoldAll: In[6]:= Block[{x}, Attributes[x] = NHoldAll; NIntegrate[1, {x[1], 0, 1}, {x[2], 0, x[1]}]] Out[6]= 0.5 Maxim Rytin m.r@inbox.ru === Subject: Re: How to use NMinimize with a numerical function Marco Gabiccini === Subject: Implicit integration of finite alternating series of hypergeometric (2F1) functions I am having a problem with Mathematica in determining a closed form analytical solution for the implicit integral of the following: -(a/Pi)*Cos[Pi*(t-b)/a]*Hypergeometric2F1[0.5,0.5*(1-n),1.5,(Cos[Pi*(t-b)/a] )^2]*c + d In this equation the terms a, b, c and d are fixed constants for the problem. The term n is also a constant with value greater than zero. The term t is is the variable. Mathematica returns the input line, as an output line, without an evaluation. When I specify n, a priori, with respect to the integration operation, Mathematica has no problem with performing the integration. I would, however, like a closed form analytical solution or a family of solutions without the a priori specification of n. Any help would be greatly appreciated. === Subject: Re: Implicit integration of finite alternating series of hypergeometric (2F1) functions > I am having a problem with Mathematica in determining a closed form > analytical solution for the implicit integral of the following: What do you mean by an implicit integral? > -(a/Pi)*Cos[Pi*(t-b)/a]*Hypergeometric2F1[0.5,0.5*(1-n),1.5,(Cos[Pi*(t-b)/a] ) ^ > 2]*c + d Note that, as far as Mathematica is concerned, the floating point number 0.5 is _not_ the same as the exact rational number 1/2. If you want to compute an integral _exactly_ you should use _exact_ input. > In this equation the terms a, b, c and d are fixed constants for the > problem. The term n is also a constant with value greater than zero. > The term t is is the variable. So I assume that you computing an indefinite integral with respect to t? Note that > Mathematica returns the input line, as an output line, without an evaluation. Which means that it _cannot_ compute this integral (not directly, anyway). It can compute the indefinite integral of Integrate[Cos[Pi (t-b)/a]^(2m+1), t] which appears in the m-th term of the Hypergeometric2F1 function -- but this integral is another Hypergeometric2F1 function. > When I specify n, a priori, with respect to the integration operation, > Mathematica has no problem with performing the integration. This is usually the case. > I would, however, like a closed form analytical solution or a family of > solutions without the a priori specification of n. This is, generally, a much harder problem. Your integrand can be expressed as a Beta function (using FunctionExpand) but, because of the complexity of this expression, I would be surpised if closed-form integrals for general n can be obtained. A change of variables, y == Cos[Pi (t-b)/a], formally leads to (part of) the integral being expressed as a MeijerG function: Integrate[y Hypergeometric2F1[1/2, 1/2 - n/2, 3/2, y^2]/Sqrt[1-y^2], y] but I'm not sure if that will be useful for you. 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 === Subject: Re: solving Why do you think the answer is incorrect? All the Mathematica code seems to work. I'm not an expert on differential equations and suggest you post your question to MathGroup: mathgroup@smc.vnet.net Copy your statements, in InputForm, to the posting. Also explain why you think the results are incorrect. There are people there who are much better at differential equation solving than I am. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ i am trying to solve 3 coupled second order differential equations.But i am not getting the right answer.i am attaching the mathemetica prog. with this mail.please help with necessary steps. animesh ..................................................... Mr. Animesh Goswami Scientific Officer Variable energy cyclotron centre(ADSS Lab) 1/AF , Bidhan Nagar Kolkata-64 , India phone no:- 033-23371230(ext-2109) mobile no:-09434311233 .................................................... === Subject: again: roots of transcendental function... I'm wondering that i didn't find Union by myself in the Help Browser...;-) The RootSearch Package is very useful for my application as well! Anyway, i didn't fix my problem yet! I need to fit this model which includes the roots of this transcendental function Cot[x] == x/a - a/(4*x) to experimental data. I'm using FindMinimum and that works fine with other models. The problem now is that i need to define the function which needs to be minimized with the mentioned model. The parameter a is one of the fitting parameters. In previous cases where the objective function contained more steps and numerical operations, I defined a module including all steps. Doing this with FindRoot (or RootSearch) made me a lot of difficulties. For every iteration step in FindMinimum the roots for the predicted parameter a have to be determined and then used for the calculation of the model. Therefore i defined a module in which a list of the roots for a predicted a should be construct. The values of this list should than be used for calculating the model. At present i get error messages because there is no numerical value for the parameter a given. In case this sounds confusing, i've attached the code (in this case with FindRoot). i hope somebody can give me a hint... time = Range[0.2, 30, 0.2]; model[a_, i.b3_, t_] := Module[{e, x, gl}, e = x /. Union[Table[FindRoot[Cot[x] == x/a - a/(4*x), {x, i}], {i, 1, 50}]]; gl = Exp[a/2 (1 - (t/ i.b3)/2)] Sum[(e[[ i]] (a Sin[e[[i]]] + 2 e[[i]] Cos[ e[[i]]]) Exp[-(e[[i]])^2*(t/i.b3)/a])/(([EDouble Dot][[ i]])^2 + (a/2)^2 + a), {i, 1, Length[e]}]; gl ] hju = Map[model[a, i.b3, t] /. {Pe -> 50, i.b3 -> 5} /. {t -> #} &, time] === Subject: Re: again: roots of transcendental function... > I'm wondering that i didn't find Union by myself in the Help > Browser...;-) The RootSearch Package is very useful for my application > as well! > Anyway, i didn't fix my problem yet! I need to fit this model which > includes the roots of this transcendental function Cot[x] == x/a - > a/(4*x) to experimental data. I'm using FindMinimum and that works fine > with other models. The problem now is that i need to define the function > which needs to be minimized with the mentioned model. The parameter a > is one of the fitting parameters. In previous cases where the objective > function contained more steps and numerical operations, I defined a > module including all steps. > Doing this with FindRoot (or RootSearch) made me a lot of difficulties. > For every iteration step in FindMinimum the roots for the predicted > parameter a have to be determined and then used for the calculation of > the model. Therefore i defined a module in which a list of the roots for > a predicted a should be construct. The values of this list should than > be used for calculating the model. At present i get error messages > because there is no numerical value for the parameter a given. > In case this sounds confusing, i've attached the code (in this case with > FindRoot). > i hope somebody can give me a hint... > time = Range[0.2, 30, 0.2]; > model[a_, i.b3_, t_] := Module[{e, x, gl}, > e = x /. Union[Table[FindRoot[Cot[x] == x/a - a/(4*x), {x, i}], {i, > 1, 50}]]; > gl = Exp[a/2 (1 - (t/ > i.b3)/2)] Sum[(e[[ > i]] (a Sin[e[[i]]] + 2 e[[i]] Cos[ > e[[i]]]) Exp[-(e[[i]])^2*(t/i.b3)/a])/(([EDouble Dot][[ > i]])^2 + (a/2)^2 + a), {i, 1, Length[e]}]; > gl > ] > hju = Map[model[a, i.b3, t] /. {Pe -> 50, i.b3 -> 5} /. {t -> #} &, time] I won't be answering your question here. Sorry. But I think you must to be warned about something. You had mentioned earlier that 0 < a < 200, and so parameter a might be 0.01, for example. But if you use, as you do above, Union[Table[FindRoot[Cot[x] == x/a - a/(4*x), {x, i}], {i, 1, 50}]] you will get _only three_ out of the 16 positive roots less than 50. In[1]:= a = 0.01; Union[Table[FindRoot[Cot[x] == x/a - a/(4*x), {x, i}], {i, 1, 50}]] Out[1]= {{x -> 0.0999584}, {x -> 0.0999584}, {x -> 0.0999584}, {x -> 0.0999584}, {x -> 0.0999584}, {x -> 0.0999584}, {x -> 0.0999584}, {x -> 0.0999584}, {x -> 0.0999584}, {x -> 0.0999584}, {x -> 6.28478}, {x -> 21.9916}} As I mentioned in your previous thread, it is much nicer to use simple facts about the nature of the roots. We can get _all_ the roots in this case very easily using just a slight modification of your code (and Union then becomes superfluous). In[2]:= a = 0.01; Table[FindRoot[Cot[x] == x/a - a/(4*x), {x, i}], {i, 10^-6, 50, Pi}] Out[2]= {{x -> 0.0999584}, {x -> 3.14477}, {x -> 6.28478}, {x -> 9.42584}, {x -> 12.5672}, {x -> 15.7086}, {x -> 18.8501}, {x -> 21.9916}, {x -> 25.1331}, {x -> 28.2747}, {x -> 31.4162}, {x -> 34.5578}, {x -> 37.6994}, {x -> 40.8409}, {x -> 43.9825}, {x -> 47.1241}} Alternatively, one could use RootSearch effectively, if its options are set correctly. Please see Ted Ersek's recent posting RootSearch options. David === Subject: Re: Problem with Thread over Plus? Threading { {1,1} , {2,2} , {3,3} } will produce { {1,2,3}, {1,2,3} } to which you can't add {1,1}, because they are of different lengths. You could, however, add {1,1,1}, which does work. Mark Link to the forum page for this post: http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageName=Speci al:Forum_ViewTopic&pid=9307#p9307 === Subject: Recursive issue Group, Recently I've been working on diffraction propagation problems inside passive laser cavities. The standard approach was pioneered by Fox and Li (Bell Systems Journal 1961) which is a numerical Fresnel propagator that the solution is fed back into the kernel for each pass. Numerically (which is how Fox and Li did it), the Mathematica solution is: The solution is for a one dimensional infinite strip mirror in 1 D. The inital parameters and the kernel are given by: l = 0.6328 w = 2*25*l z = 100*l Kmat = Table[(l/5)*(Exp[I*(((2*Pi)/l)*z)]/ Sqrt[I*l*z])*Exp[((-I)*((2*Pi)/l)*(x - y)^2)/ (2*z)], {x, -400*(l/5), 400*(l/5), l/5}, {y, -400*(l/5), 400*(l/5), l/5}]; Do[f[n] =. , {n, 0, 20}] ( * This sets the recursive terms to zero to start another run *) f[0] = Table[If[Abs[x] < 25*l, 1, 0], {x, -400*(l/5), 400*(l/5), l/5}]; (* This defines the initial intensity we set it to 1 *) f[n_] := f[n] = Kmat . (f[n - 1]*f[0]); (* This is the recursive equation where we use f[0] to normalize the recurring propagation at each mirror *) (* The next bit is various cases from f[1] to f[200] which show that the solution conveges to a Inormala mode solution after enough passes *) ListPlot[Abs[f[0]], PlotRange -> All, PlotJoined -> True]; ListPlot[Abs[f[1]], PlotRange -> All, PlotJoined -> True]; ListPlot[Abs[f[2]], PlotRange -> All, PlotJoined -> True]; ListPlot[Abs[f[5]], PlotRange -> All, PlotJoined -> True]; ListPlot[Abs[f[10]], PlotRange -> All, PlotJoined -> True]; ListPlot[Abs[f[20]], PlotRange -> All, PlotJoined -> True]; ListPlot[Abs[f[200]], PlotRange->All, PlotJoined->True]; This works well and as expected. Now for the problem (Sorry for the long set up!) This is Mathematica, I thought, so I can write the integral propator explicity without worrying about numerics . So using the same values of lamda, w and z, I write the initial intensity and the iterative kernel as an integral equation and recursively: f[0, x_] = 1 f[n_, x_] := (Exp[I*(((2*Pi)/l)*z)]/Sqrt[I*l*z])* Integrate[Exp[((-I)*((2*Pi)/l)*(q - x)^2)/(2*z)]* f[n - 1, q], {q, -w/2, w/2}] If you look at the first pass the solution is correct exactly matching the numerical solution but subsequent passes give the same solution as in pass 1 multiplied by a constant. In other words, the recursion is not working to feed the solution back into the kernel for the next step. When you look at the solution explicity (algebraicly ) for the first step itas a bunch of Erf functions with some constants. When you look at the second pass itas the same set of Erf functions multiplied by a larger constant. It looks like the recursion is working outside in somehow. Is there something Iam doing wrong in the explicit integral equation vs. the numerical one? Or is there a better way to do the explicit recursive integral equation? Itas not that I canat solve this other ways. Iave built a Fourier propagator and of course the numerical Fox-Li solution. What Iam trying to understand is what is going wrong with the explicit algebraic recursive solution. If any more detail is needed I can write anyone off line and provide more details. Cliff === Subject: Re: Problem with Thread over Plus? > Why does this work: > Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] > but this doesn't? > Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] In the first case the argument lists are the same length Thread[Plus[{1,1},{{1,1},{2,2}}]] = Thread[{{2,2},{3,3}}] (since the argument to thread is evaluated first) = Thread[List[{2,2},{3,3}] (I'm just explicitly listing the head here to make what happens clear) = {List[2,3],List[2,3]} (This is the result of threading List over its arguments) = {{2,3},{2,3}} I suspect this is not what you intended even though the result is equivalent, I believe you wanted to thread Plus over its arguments, but remember it got evaluated before Thread was applied. There was a recent mailing list discussion of the interaction of Thread and the evaluator starting here http://forums.wolfram.com/mathgroup/archive/ 2006/Feb/msg00323.html. At any rate In the second case the argument lists are not the same length. Thread[Plus[{1,1},{{1,1},{2,2},{3,3}}]] gives two warning messages the first of which is due to the expression Plus[{1,1}, {{1,1},{2,2},{3,3}}] which issues a warning message upon evaluation because you cannot add {1,1} to {{1,1},{2,2},{3,3}}. The second warning message is due to the attempt to evaluate Thread[Plus[{1,1}, {{1,1},{2,2},{3,3}}]]. Ssezi === Subject: Re: Problem with Thread over Plus? > Why does this work: > Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] One way to think of it is that you are attempting to add a vector of length 2 to each column vector of a 2x2 matrix. (e.g., consider that Thread[Plus[{a, b, c}, Transpose[{{1, 1, c}, {2, 2, d}}]]]//MatrixForm does not give an error, but Thread[Plus[{a, b, c}, {{1, 1, c}, {2, 2, d}}]]//MatrixForm does give an error.) Another way to think of it is that: It adds: a) the list {1,1} to the list of first elements of the second list {1,2} producing {2,3} b) the list {1,1} to the list of second elements of the second list {1,2} producing {2,3} > but this doesn't? > Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] This attempts to add: a) the list {1,1} to the list of first elements {1,2,3} and incurs an error. It is not clear what you wanted---do you wish to add a 1 to each element of a list? Then 1 + { {a,b},{c,d}} would do the trick. === Subject: Re: Problem with Thread over Plus? > Why does this work: > Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] > but this doesn't? > Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] > Vince Virgilio Thread evaluates its argument(s) so in the first case you get the equivalent of this Plus[{1, 1}, {{1, 1}, {2, 2}}] {{2, 2}, {3, 3}} Thread[%] {{2, 3}, {2, 3}} while in the second Plus[ {1, 1} , { {1, 1} , {2, 2} , {3, 3} } ] tries to add lists of different lengths and fails. In fact, are you sure that you really meant to get the answer you did get in the case you claim works? Did you not rather mean this: Thread[Unevaluated[Plus[{1, 1} , {{1, 1}, {2, 2}}]]] {{2, 2}, {3, 3}} ? It is a little harder to make the second case work in the same way but of course it can be done: Thread[ Unevaluated[Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ],List,-1] {{2, 2}, {3, 3}, {4, 4}} Andrzej Kozlowski === Subject: Re: How to use NMinimize with a numerical function The behavior you have noticed is described in the following Technical Support FAQ. http://support.wolfram.com/mathematica/mathematics/numerics/nsumerror.html NumericQ constraints can be imposed on its arguments to keep f from evaluating before the arguments are numeric, and the FindMinimum call will evaluate as expected. In[1]:= f[a_?NumericQ,b_?NumericQ,c_?NumericQ]:= Module[{x}, NMinimize[{(a x^2 + b x + c)^2}, x][[2, 1, 2]]] In[2]:= FindMinimum[(f[r, s, t] + 2.0)^2, {{r, -5, 5}, {s, -5, 5}, {t, -5, 5}}] NMinimize::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. -23 Out[2]= {2.08333 10 , {r -> -1.25, s -> -5., t -> -5.14745}} Darren Glosemeyer Wolfram Research >Hi all, >I wanted to test NMinimize[] with a numerical function whose return value >is the result of another NMinimize. >I defined the intersection with the abscissa of the parabola y=ax^2+bx+c as >f[a,b,c] >and I want to find one set of values {a,b,c} for which that intersection is >reached at x=-2. >I defined >f[a_, b_, c_] := > Module[{x}, NMinimize[{(a x^2 + b x + c)^2}, x][[2, 1, 2]]] >and I would like to find that particular value of {a,b,c} for which >f[a,b,c]=-2, that is why I call >FindMinimum[(f[r, s, t] + 2.0)^2, {{r, -5, 5}, {s, -5, 5}, {t, -5, 5}}] >but I get this error message >1760692.jpg >[Attachments are not permitted. Please contact the author to >obtain this - moderator] >It seems that the latter FindMinimum[] keeps the r,s,t unevaluated when >calling f in the first FindMinimum. Is there a way to switch the order of >evaluation? >Can anybody help me? >Marco === Subject: Re: How to use NMinimize with a numerical function > The behavior you have noticed is described in the following Technical > Support FAQ. > http://support.wolfram.com/mathematica/mathematics/numerics/nsumerror.html > NumericQ constraints can be imposed on its arguments to keep f from > evaluating before the arguments are numeric, and the FindMinimum call will > evaluate as expected. > In[1]:= f[a_?NumericQ,b_?NumericQ,c_?NumericQ]:= > Module[{x}, NMinimize[{(a x^2 + b x + c)^2}, x][[2, 1, 2]]] > In[2]:= FindMinimum[(f[r, s, t] + 2.0)^2, {{r, -5, 5}, {s, -5, 5}, {t, -5, 5}}] > NMinimize::cvmit: Failed to converge to the requested accuracy or precision > within 100 > iterations. > -23 > Out[2]= {2.08333 10 , {r -> -1.25, s -> -5., t -> -5.14745}} > Darren Glosemeyer > Wolfram Research >> Hi all, >> I wanted to test NMinimize[] with a numerical function whose return value >> is the result of another NMinimize. >> I defined the intersection with the abscissa of the parabola y=ax^2+bx+c as >> f[a,b,c] >> and I want to find one set of values {a,b,c} for which that intersection is >> reached at x=-2. >> I defined >> f[a_, b_, c_] := >> Module[{x}, NMinimize[{(a x^2 + b x + c)^2}, x][[2, 1, 2]]] >> and I would like to find that particular value of {a,b,c} for which >> f[a,b,c]=-2, that is why I call >> FindMinimum[(f[r, s, t] + 2.0)^2, {{r, -5, 5}, {s, -5, 5}, {t, -5, 5}}] >> but I get this error message >> 1760692.jpg >> [Attachments are not permitted. Please contact the author to >> obtain this - moderator] >> It seems that the latter FindMinimum[] keeps the r,s,t unevaluated when >> calling f in the first FindMinimum. Is there a way to switch the order of >> evaluation? >> Can anybody help me? >> Marco Hi Marco isn't it faster in this case to use the capabilities of Reduce[]? please have a look at http://people.freenet.de/Peter_Berlin/Mathe/reduceToPiecewise.nb Peter === Subject: Re: Plotting independent quantities > function of time on the same plot. I need two y axes for this purpose (each > with their units, etc.). Is such a plot possible in Mathematica ? Mathematica Technical Support FAQ, at http://support.wolfram.com/mathematica/graphics/2d/twoaxisgraph.html : The functions TwoAxisPlot and TwoAxisListPlot, as documented in this FAQ, enable the creation of plots with two vertical axes having different scales. Also, as of today, Google returns 256 results for _two y axes_ and 254 results for _two y axis_ searched in comp.soft-sys.math.mathematica. Some of these posts may be of interest... JM === Subject: Re: Plotting independent quantities >> function of time on the same plot. I need two y axes for this purpose >> (each with their units, etc.). Is such a plot possible in Mathematica ? > Mathematica Technical Support FAQ, at > http://support.wolfram.com/mathematica/graphics/2d/twoaxisgraph.html : > The functions TwoAxisPlot and TwoAxisListPlot, as documented in this > FAQ, enable the creation of plots with two vertical axes having > different scales. > Also, as of today, Google returns 256 results for _two y axes_ and 254 > results for _two y axis_ searched in comp.soft-sys.math.mathematica. > Some of these posts may be of interest... > JM Ok. So, it is not a Mathematica built in. I am using Mathematica 5.0 here and I could not find it in help. Then I realized that I needed to create my own .m file and put it in the path. be included in a future version. Seems too common and useful a kind of plot for it not to be a built in. === Subject: Re: Problem with Thread over Plus? Thread is expecting the list to be of equal length. In the first case {1,1} is a list of length 2 and {{1,1},{2,2}} is also a list of length 2. Obviously in the second case {{1,1},{2,2},{3,3}} is a list of length 3 and Thread generates an error message yehuda > Why does this work: > Thread[ Plus[ {1,1} , { {1,1} , {2,2} } ] ] > but this doesn't? > Thread[ Plus[ {1,1} , { {1,1} , {2,2} , {3,3} } ] ] > Vince Virgilio > ************************************ > This e-mail and any files transmitted with it are proprietary and intende > d solely for the use of the individual or entity to whom they are address > ed. If you have received this e-mail in error please notify the sender. P > lease note that any views or opinions presented in this e-mail are solely > those of the author and do not necessarily represent those of ITT Indust > ries, Inc. The recipient should check this e-mail and any attachments for > the presence of viruses. ITT Industries accepts no liability for any dam > age caused by any virus transmitted by this e-mail. > ************************************ === Subject: Re: solving i am trying to solve 3 coupled second order differential equations.But i am not getting the right answer.i am attaching the mathemetica prog with this mail. [contact the author to get this attachment - moderator] The initial conditions of these equations are:- alpha=.004,alpha'=0 beta=0,beta'=0 gama=0,gama'=0 b renges from 0 to pi/2 Please check the prog. and help me to find out the actual procedure to solve the equations. please help with necessary steps. animesh ..................................................... Mr. Animesh Goswami Scientific Officer Variable energy cyclotron centre(ADSS Lab) 1/AF , Bidhan Nagar Kolkata-64 , India .................................................... ----- Original Message ----- === Subject: Re: solving > Why do you think the answer is incorrect? All the Mathematica code > seems to > work. > I'm not an expert on differential equations and suggest you post your > question to MathGroup: > mathgroup@smc.vnet.net > Copy your statements, in InputForm, to the posting. Also explain > why you > think the results are incorrect. There are people there who are > much better > at differential equation solving than I am. > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ ..................................................... > Mr. Animesh Goswami > Scientific Officer > Variable energy cyclotron centre(ADSS Lab) > 1/AF , Bidhan Nagar > Kolkata-64 , India > phone no:- 033-23371230(ext-2109) > mobile no:-09434311233 > .................................................... === Subject: Re: - help wanted To enter the input 1+1/r+O((1/r)^2), use Series[1+1/r,{r,Infinity,1}] Another example, Series[1/(r+1),{r,Infinity,3}]//Simplify %//Normal Series[%,{r,Infinity,3}] Bob Hanlon === > Subject: - help wanted > Hello all! > I would really appreciate some help. > Mathematica has a built-in function called Series: > Series[x,x_0,n], > which allows to expand functions into power series where x is the > variable, x_0 is the point about which we expand, and n is the desired > order of expansion. > It also allows x_0 to be infinity, which is very useful when one needs > multiple expansion (as in gravitational waves and electromagnetic > radiation). > (and its powers) in the output, it does not allow this to be entered in > the input. To convince yourselves, try it out. Enter in the input, > e.g., 1+ 1/r+ (O(1/r))^2, and it will tell you that 1/r is not a > variable. > If, on the other hand, you entered: > In=Series[1/(r+1), {r, Infinity,3}]//Simplify > you will get > Out=1/r-(1/r)^2+(1/r)^3+(O(1/r))^4 > which shows that the output is possible, but the input is impossible. > Can anyone offer some assistance? > Gideon === Subject: Re: Bug with Series[] - help wanted For a series at infinity, you need to use O[x, Infinity] rather than O[1/x]. Bhuvanesh, Wolfram Research. === Subject: simplify a trig expression A direct substitution (with paper and pencil) gives that the integral of Cos[x]/(Sin[x] + 1) is Log[Sin[x] + 1]. This is valid provided Sin[x] is not -1. Mathematica gives: Integrate[Cos[x]/(Sin[x] + 1), x] 2 Log[Cos[x/2] + Sin[x/2]] Is there some simple way to coerce the latter Mathematica-supplied result into the paper-and-pencil answer? The closest I could get is: Log[TrigExpand[Expand[(Cos[x/2] + Sin[x/2])^2]]] /. {Sin[x/2] -> Sqrt[(1 - Cos[x])/2], Cos[x/2] -> Sqrt[(1 + Cos[x])/2]} Log[1 + Sqrt[1 - Cos[x]]*Sqrt[1 + Cos[x]]] Am I not seeing some easier TrigExpand or TrigReduce method? -- Murray Eisenberg murray@math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305 === Subject: Re: simplify a trig expression > This is one of those cases where FullSimplify will not work because it > lacks a suitable transformation function. In this particular case the > transformation function is of the form: > f[n_*Log[a_]] := Log[a^n] > Of course this is only valid with various assumptions on n and a, but I > won't bother with this here. Indeed, the two expressions are not equal for all values of x. In[1]:= {2 Log[Cos[x/2] + Sin[x/2]], Log[Sin[x] + 1]} /. x->5Pi/2 Log[2] Out[1]= {2 (I Pi + ------), Log[2]} 2 If we assume that 2 Log[Cos[x/2] + Sin[x/2]] is real we can use the following transformation to simplify it. In[2]:= g[x_]:=Log[TrigReduce[E^x]] In[3]:= g[2 Log[Cos[x/2] + Sin[x/2]]] Out[3]= Log[1 + Sin[x]] > Anyway, observe that: > FullSimplify[Integrate[Cos[x]/(Sin[x] + 1), x], > TransformationFunctions -> {Automatic, f}] > Log[Sin[x] + 1] > Note also that Simplify will not work even when you add f. This is because f itself does not make the expression simpler. Simplify does not use TrigReduce, FullSimplify does. Adam Strzebonski Wolfram Research > I am not sure if there are good reasons for adding a version of f > (taking account of suitable assumptions) to the default transformation > functions of FullSimplify. It may however be a good idea to have > another possible value for the option TransformationFunctions besides > only Automatic and user defined ones. In fact I have suggested in the > past one or two other useful TransformationFunctions; perhaps it might > be a good idea to define more and collect them into a single option > value or maybe several. > Andrzej Kozlowski >> A direct substitution (with paper and pencil) gives that the integral of >> Cos[x]/(Sin[x] + 1) is Log[Sin[x] + 1]. This is valid provided Sin[x] >> is not -1. >> Mathematica gives: >> Integrate[Cos[x]/(Sin[x] + 1), x] >> 2 Log[Cos[x/2] + Sin[x/2]] >> Is there some simple way to coerce the latter Mathematica-supplied >> result into the paper-and-pencil answer? >> The closest I could get is: >> Log[TrigExpand[Expand[(Cos[x/2] + Sin[x/2])^2]]] /. >> {Sin[x/2] -> Sqrt[(1 - Cos[x])/2], >> Cos[x/2] -> Sqrt[(1 + Cos[x])/2]} >> Log[1 + Sqrt[1 - Cos[x]]*Sqrt[1 + Cos[x]]] >> Am I not seeing some easier TrigExpand or TrigReduce method? >> -- >> Murray Eisenberg murray@math.umass.edu >> Mathematics & Statistics Dept. >> Lederle Graduate Research Tower phone 413 549-1020 (H) >> University of Massachusetts 413 545-2859 (W) >> 710 North Pleasant Street fax 413 545-1801 >> Amherst, MA 01003-9305 === Subject: Re: simplify a trig expression This is one of those cases where FullSimplify will not work because it lacks a suitable transformation function. In this particular case the transformation function is of the form: f[n_*Log[a_]] := Log[a^n] Of course this is only valid with various assumptions on n and a, but I won't bother with this here. Anyway, observe that: FullSimplify[Integrate[Cos[x]/(Sin[x] + 1), x], TransformationFunctions -> {Automatic, f}] Log[Sin[x] + 1] Note also that Simplify will not work even when you add f. I am not sure if there are good reasons for adding a version of f (taking account of suitable assumptions) to the default transformation functions of FullSimplify. It may however be a good idea to have another possible value for the option TransformationFunctions besides only Automatic and user defined ones. In fact I have suggested in the past one or two other useful TransformationFunctions; perhaps it might be a good idea to define more and collect them into a single option value or maybe several. Andrzej Kozlowski > A direct substitution (with paper and pencil) gives that the > integral of > Cos[x]/(Sin[x] + 1) is Log[Sin[x] + 1]. This is valid provided > Sin[x] > is not -1. > Mathematica gives: > Integrate[Cos[x]/(Sin[x] + 1), x] > 2 Log[Cos[x/2] + Sin[x/2]] > Is there some simple way to coerce the latter Mathematica-supplied > result into the paper-and-pencil answer? > The closest I could get is: > Log[TrigExpand[Expand[(Cos[x/2] + Sin[x/2])^2]]] /. > {Sin[x/2] -> Sqrt[(1 - Cos[x])/2], > Cos[x/2] -> Sqrt[(1 + Cos[x])/2]} > Log[1 + Sqrt[1 - Cos[x]]*Sqrt[1 + Cos[x]]] > Am I not seeing some easier TrigExpand or TrigReduce method? > -- > Murray Eisenberg murray@math.umass.edu > Mathematics & Statistics Dept. > Lederle Graduate Research Tower phone 413 549-1020 (H) > University of Massachusetts 413 545-2859 (W) > 710 North Pleasant Street fax 413 545-1801 > Amherst, MA 01003-9305 === Subject: Re: simplify a trig expression > A direct substitution (with paper and pencil) gives that the integral of > Cos[x]/(Sin[x] + 1) is Log[Sin[x] + 1]. This is valid provided Sin[x] > is not -1. > Mathematica gives: > Integrate[Cos[x]/(Sin[x] + 1), x] > 2 Log[Cos[x/2] + Sin[x/2]] > Is there some simple way to coerce the latter Mathematica-supplied > result into the paper-and-pencil answer? > The closest I could get is: > Log[TrigExpand[Expand[(Cos[x/2] + Sin[x/2])^2]]] /. > {Sin[x/2] -> Sqrt[(1 - Cos[x])/2], > Cos[x/2] -> Sqrt[(1 + Cos[x])/2]} > Log[1 + Sqrt[1 - Cos[x]]*Sqrt[1 + Cos[x]]] > Am I not seeing some easier TrigExpand or TrigReduce method? Doesn't TrigReduce do whatyou want? In[2]:= Log[TrigReduce[(Cos[x/2] + Sin[x/2])^2]] Out[2]= Log[1+Sin[x]] Carl Woll WolframResearch === Subject: Re: simplify a trig expression > A direct substitution (with paper and pencil) gives that the integral of > Cos[x]/(Sin[x] + 1) is Log[Sin[x] + 1]. This is valid provided Sin[x] > is not -1. > Mathematica gives: > Integrate[Cos[x]/(Sin[x] + 1), x] > 2 Log[Cos[x/2] + Sin[x/2]] > Is there some simple way to coerce the latter Mathematica-supplied > result into the paper-and-pencil answer? In[] Integrate[Cos[x]/(Sin[x] + 1), x] // Times[#, 1/2] & // Map[Power[#, 2] &, #] & // FullSimplify Out[] Log[1 + Sin[x]] -- Roland Franzius === Subject: Re: - help wanted The order notation O[1/r] is part of how the output of Series is formatted. It does not closely correspond to the internal form of a series. In[1]:= $VersionNumber Out[1]= 5.2 In[2]:= s=Series[1/(r+1), {r, Infinity,3}] Out[2]= 1 -2 -3 1 4 - - r + r + O[-] r r Look at the internal structure of the Series output: In[3]:= FullForm[s] Out[3]//FullForm= SeriesData[r, DirectedInfinity[1], List[1, -1, 1], 1, 4, 1] Turn it into a polynomial. Note that the O term goes away. In[4]:= Normal[s] Out[4]= -3 -2 1 r - r + - r In[5]:= FullForm[%] Out[5]//FullForm= Plus[Power[r, -3], Times[-1, Power[r, -2]], Power[r, -1]] I hope this is helpful. Bruce Miller Technical Support Wolfram Research, Inc. support@wolfram.com > Hello all! > I would really appreciate some help. > Mathematica has a built-in function called Series: > Series[x,x_0,n], > which allows to expand functions into power series where x is the > variable, x_0 is the point about which we expand, and n is the desired > order of expansion. > It also allows x_0 to be infinity, which is very useful when one needs > multiple expansion (as in gravitational waves and electromagnetic > radiation). > (and its powers) in the output, it does not allow this to be entered in > the input. To convince yourselves, try it out. Enter in the input, > e.g., 1+ 1/r+ (O(1/r))^2, and it will tell you that 1/r is not a > variable. > If, on the other hand, you entered: > In=Series[1/(r+1), {r, Infinity,3}]//Simplify > you will get > Out=1/r-(1/r)^2+(1/r)^3+(O(1/r))^4 > which shows that the output is possible, but the input is impossible. > Can anyone offer some assistance? > Gideon === Subject: Re: - help wanted > Hello all! > I would really appreciate some help. > Mathematica has a built-in function called Series: > Series[x,x_0,n], > which allows to expand functions into power series where x is the > variable, x_0 is the point about which we expand, and n is the desired > order of expansion. > It also allows x_0 to be infinity, which is very useful when one needs > multiple expansion (as in gravitational waves and electromagnetic > radiation). > (and its powers) in the output, it does not allow this to be entered in > the input. To convince yourselves, try it out. Enter in the input, > e.g., 1+ 1/r+ (O(1/r))^2, and it will tell you that 1/r is not a > variable. > If, on the other hand, you entered: > In=Series[1/(r+1), {r, Infinity,3}]//Simplify > you will get > Out=1/r-(1/r)^2+(1/r)^3+(O(1/r))^4 > which shows that the output is possible, but the input is impossible. > Can anyone offer some assistance? > Gideon Gideon, Use the 2-argument form of O: In[1]:= O[r,Infinity]^4 Out[1]= O[1/r]^4 Carl Woll Wolfram Research === Subject: Re: How to use NMinimize with a numerical function > [...] > I defined the intersection with the abscissa of the parabola > y=ax^2+bx+c as f[a,b,c] and I want to find one set of values > for which that intersection is reached at x=-2. > [...] With[{x = -2}, FindInstance[a x^2 + b x + c == 0, {a,b,c}, Reals, 2]] {a -> 1/10, b -> 16/5, c -> 6} {a -> 16/5, b -> 33/5, c -> 2/5} === Subject: Re: How to use NMinimize with a numerical function > Hi all, > I wanted to test NMinimize[] with a numerical function whose return value > is the result of another NMinimize. > I defined the intersection with the abscissa of the parabola y=ax^2+bx+c as > f[a,b,c] > and I want to find one set of values {a,b,c} for which that intersection is > reached at x=-2. > I defined > f[a_, b_, c_] := > Module[{x}, NMinimize[{(a x^2 + b x + c)^2}, x][[2, 1, 2]]] > and I would like to find that particular value of {a,b,c} for which > f[a,b,c]=-2, that is why I call > FindMinimum[(f[r, s, t] + 2.0)^2, {{r, -5, 5}, {s, -5, 5}, {t, -5, 5}}] > but I get this error message > 1760692.jpg > [Attachments are not permitted. Please contact the author to > obtain this - moderator] > It seems that the latter FindMinimum[] keeps the r,s,t unevaluated when > calling f in the first FindMinimum. Is there a way to switch the order of > evaluation? > Can anybody help me? > Marco Checking that the arguments of the function f are numerics should help. In[1]:= f[(a_)?NumericQ, (b_)?NumericQ, (c_)?NumericQ] := Module[{x}, NMinimize[{(a*x^2 + b*x + c)^2}, x][[2,1,2]]] JM === Subject: Rescale InputForm@{#,Rescale@#}&@Sort@Table[Random[],{3}] {{0.1495146427525807, 0.9032356867418898, 0.9803938132050517}, {2.7755575615628914*^-17, 0.9071367664432557, 1.0000000000000002}} What is Rescale doing, that it does not always give N@0 and N@1 for the first and last elements? === Subject: Re: Rescale > InputForm@{#,Rescale@#}&@Sort@Table[Random[],{3}] > {{0.1495146427525807, 0.9032356867418898, 0.9803938132050517}, > {2.7755575615628914*^-17, 0.9071367664432557, 1.0000000000000002}} > What is Rescale doing, that it does not always give N@0 and N@1 > for the first and last elements? These are the usual roundoffs. Do[v=Rescale@Sort@Table[Random[Real,{0,1},$MachinePrecision],{3}]; If[v[[{1,3}]]=!={0.,1.},Return[{i,v}]],{i,10^6}] didn't report a single triple with other values as 0. and 1. at the beginning/end. === Subject: Re: Two independent y axes ? >I am trying to plot a bunch of functions and some data together. >Some of the data and some of the functions have *very* different >y range from the others. How do I create 2 independent y axes >(like gnuplot - y and y2 axes) to show the data effectively ? >>Is something like the following what you are looking for >>In[8]:= x = Sort[Table[Random[], {10}]]; y = >>20*Reverse[Sort[Table[Random[], {10}]]]; >> In[8]:= >> x = Sort[Table[Random[], {10}]]; >> y = 20*Reverse[Sort[Table[Random[], {10}]]]; >> In[10]:= >> Show[Block[{$DisplayFunction = Identity}, >> {ListPlot[Rescale[x], PlotStyle -> Blue], >> ListPlot[Rescale[y], PlotStyle -> Red]}], >> Frame -> True, FrameTicks -> {Automatic, >> Range[0, 1, 0.2], None, ({#1, 20*#1} & ) /@ >> Range[0, 1, 0.2]}]; >function of time. These are physically distinct quantities and >cannot share a y axis. Having colorful legends will not cut it. Either you did not bother to try the example code or you gave the resulting plot and code a very superficial review. There are two vertical scales in the resulting plot. The left hand scale runs from 0 to 1 representing the values of the x data which is a sorted list of random values between 0 and 1. The right scale runs from 0 to 20 representing the values of the y data which is a reverse sorted list of random values between 0 and 20. The only purpose of using color was to clearly separate the y data from the x data. Rescale was used with both data sets to cause each set to be have a common scale for plotting purposes. The option Frame was set to True as a simple means to get Mathematica to put an axis on both the right and left hand sides of the plot. FrameTicks was then set to show the correct range of values for each data set. If this were intended for a publication rather than as a simple example, I would have added many additional features to the plot such as labels and something to clearly indicate which data points were associated with which scale. I assumed this was something you would work out for yourself. I also intentionally made this example with functions found in the standard Mathematica distribution. For similar plots I produce intended for publication, I make use of a couple of third party packages to allow me to easily customize the plot to a greater degree than the standard built in commands. -- To reply via email subtract one hundred and four === Subject: Re: Bug with Series- help wanted >Mathematica has a built-in function called Series: Series[x,x_0,n], >which allows to expand functions into power series where x is the >variable, x_0 is the point about which we expand, and n is the >desired order of expansion. >It also allows x_0 to be infinity, which is very useful when one >needs multiple expansion (as in gravitational waves and >electromagnetic radiation). >O(1/x) (and its powers) in the output, it does not allow this to be >entered in the input. To convince yourselves, try it out. Enter in >the input, e.g., 1+ 1/r+ (O(1/r))^2, and it will tell you that 1/r >is not a variable. >If, on the other hand, you entered: In=Series[1/(r+1), {r, >Infinity,3}]//Simplify you will get >Out=1/r-(1/r)^2+(1/r)^3+(O(1/r))^4 >which shows that the output is possible, but the input is >impossible. Input of a series is very possible. However, as is the case with other things in Mathematica, you cannot simply type an output expression as an input since the displayed output often does not show the entire expression. To see how to input something equivalent to a given output display the output in either InputForm or FullForm. To input a series use SeriesData. For example, In[1]:= s = SeriesData[x, 0, {1, 1, 1/2, 1/6}, 0, 4, 1]; In[2]:= s == Series[Exp[x], {x, 0, 3}] Out[2]= True -- To reply via email subtract one hundred and four === Subject: ColorFunction gradient for vector field based on *data* I'm trying to make a plot of 3D spins/vectors on a 2D disc. I do this with : ListPlotVectorField3D[array, ColorFunction -> Hue, VectorHeads -> True, PlotRange -> All]; where array is an appropriate -for the ListPlotVectorField3D- list. However, the coloring of the vectors is a bit random. I saw that people use constructs like : ColorFunction -> (Hue[1 - #] &) but I'm not sure of where the # symbol refers to. When plotting a function, then the # represents the z value. But when plotting a list, how can I tell ColorFunction and e.g. Hue to make a color-gradient based on the value of a all the z-components of my vectors? My data are groups of lists { {{x,y,x},{x-component,y-component,z-component}}, ....} stating the position where the vector will be placed and then the vector itself. How can I tell ColorFunction to for each vector base it's Hue value on the z-component each time? Sorry, if I didn't explain it clear enough, I'm a beginner on this. Would be thankful to read a reply on this. Best === Subject: Re: Beginner--problem with typesetting Ooops. Instead of the URL below, look in http://documents.wolfram.com/v5/GettingStarted/System- SpecificInformation/Troubleshooting/index.html Bruce > If things were working fine and then started misbehaving the next > session, > it might be that a front-end initialization file became corrupted. > Try holding down the SHIFT key as Mathematica launches to rebuild the > cache files to default values. If that does not help, there is an > operating-system-dependent bigger hammer -- see the Help Browser, > Getting > Started, System-Specific Information, Troubleshooting or > http://support.wolfram.com/mathematica/interface/customize/ > corruptpreferencescache.html > for suggestions. > Bruce Miller > Technical Support > Wolfram Research, Inc. > support@wolfram.com > http://support.wolfram.com/ >> I'm using Mathematica write a paper and everything was working fine >> until I started working today. Now whenever I need to use a >> mathematica character (for example greater than or equal to sign) the >> text automatically shifts to a new line and switches font from Times >> New Roman to Courier New. It also happens anytime I add a comma into >> a sentence. Any idea what is going on or how to change it? >> Stephen >> Link to the forum page for this post: >> http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp? >> pageName=Special:Forum_ViewTopic&pid=9264#p9264 === Subject: Re: Beginner--problem with typesetting If things were working fine and then started misbehaving the next session, it might be that a front-end initialization file became corrupted. Try holding down the SHIFT key as Mathematica launches to rebuild the cache files to default values. If that does not help, there is an operating-system-dependent bigger hammer -- see the Help Browser, Getting Started, System-Specific Information, Troubleshooting or http://support.wolfram.com/mathematica/interface/customize/ corruptpreferencescache.html for suggestions. Bruce Miller Technical Support Wolfram Research, Inc. support@wolfram.com http://support.wolfram.com/ > I'm using Mathematica write a paper and everything was working fine > until I started working today. Now whenever I need to use a > mathematica character (for example greater than or equal to sign) the > text automatically shifts to a new line and switches font from Times > New Roman to Courier New. It also happens anytime I add a comma into > a sentence. Any idea what is going on or how to change it? > Stephen > Link to the forum page for this post: > http://www.mathematica-users.org/webMathematica/wiki/wiki.jsp? > pageName=Special:Forum_ViewTopic&pid=9264#p9264 === Subject: Convex Hull 3D Today I installed Mathematica 5.2 and although there are many enhancements I was disappointed that it still does not have a convex hull function for 3 dimensional objects. In earlier contacts with Wolfram Research (several years ago), I was given the impression that such a function would be part of the next release; but, this has not happened. Before sending this email, I checked Wolfram Research Forums, including Documentation Center, Mathematica Information Center, and MathGroup which were not very useful on finding a Mathematica implementation for finding the convex hull of 3D objects. However, I did do a search through the MathGroup archives and found that there was a discussion on this topic, e.g. Follow up: 3D Convex Hull , find a site that had an experimental Mathematical implementation for Mathematica 3.0 and tried to get this running in Mathematica 5.2; but, was unsuccessful. I would appreciate greatly Mathematica code for finding the convex hull of 3D objects. V. Stokes === Subject: Transformstion to canonical form The following rather simple problem led my to some genral questions of how to proceed in symbolic transformations which I would do on paper within Mathematica. I'm sure you can give useful hints which I apreciate in advance. Consider a slight generalization of the Thales circle: In a triangle ABC, let g be the fixed angle in vertex C. (In the Thales case we have g = Pi/2). What is the equation for the coordinates (x,y) of the point C? The immediate statement is derived from the scalar product of the two vectors (C-A) and (C-B): (1) (C-A).(C-B)== Sqrt[(C-A).C-A)] Sqrt[(C-B).(C-A)] where (2) G = Cos[g] Putting A={0,0}; B={b,0};C={x,y} we obtain the equation: eq1 = x^2 - b*x + y^2 == G*Sqrt[x^2 + y^2]*Sqrt[(x - b)^2 + y^2] Now: what is a useful procedure in Mathematica to transform eq1 into an equation of the form eq2 = (x - u)^2 + (y - v)^2 == w and to find the parameters u, v, and w in terms of b and G? Wolfgang === Subject: Re: A test with options > Below I create a test with an option and a function dependant upon the > test. As I see it the function fails to operate as I anticipated. So I > am missing something and need help understanding. > In[1]:= > ClearAll[TestQ]; > Options[TestQ] = {EvaluationRequired -> False}; > TestQ[a_] := EvaluationRequired /. Options[TestQ]; > In[4]:= > ClearAll[f]; > f[(a_)?TestQ] := {100*a} > In[6]:= > a1 = f[Cos[0]] > Out[6]= > f[1] > In[7]:= > (* This is as expected the function input fails the test. Now change the > test option.*) > In[8]:= > SetOptions[TestQ, EvaluationRequired -> True]; > In[9]:= > a2 = f[Cos[0]] > Out[9]= > {100} > In[10]:= > (* This is as expected the function input passes the test. *) > In[11]:= > b = a1 > Out[11]= > f[1] > (* Now I am lost. Why in a new evaluation did the function input not get > retested and pass the test? *) You need to use Update: In[10]:= Update[f] b=a1 Out[11]= {100} > In[13]:= > c = 100 + 100 + a1 > Out[13]= > 200 + f[1] > Here are my questions > 1. Can anyone explain why the function f is not evaluated again with the > new version of TestQ when I write b = a1 ? > 2. How can I make this work so that a function that does not evaluate, > because the test fails, can be made to work once the test has been > changed? > This is a toy example the background is that I wish to construct a > function where the degree of evaluation that takes place is > controllable. > Hugh Goyder Carl Woll Wolfram Research === Subject: A test with options Below I create a test with an option and a function dependant upon the test. As I see it the function fails to operate as I anticipated. So I am missing something and need help understanding. In[1]:= ClearAll[TestQ]; Options[TestQ] = {EvaluationRequired -> False}; TestQ[a_] := EvaluationRequired /. Options[TestQ]; In[4]:= ClearAll[f]; f[(a_)?TestQ] := {100*a} In[6]:= a1 = f[Cos[0]] Out[6]= f[1] In[7]:= (* This is as expected the function input fails the test. Now change the test option.*) In[8]:= SetOptions[TestQ, EvaluationRequired -> True]; In[9]:= a2 = f[Cos[0]] Out[9]= {100} In[10]:= (* This is as expected the function input passes the test. *) In[11]:= b = a1 Out[11]= f[1] (* Now I am lost. Why in a new evaluation did the function input not get retested and pass the test? *) In[13]:= c = 100 + 100 + a1 Out[13]= 200 + f[1] Here are my questions 1. Can anyone explain why the function f is not evaluated again with the new version of TestQ when I write b = a1 ? 2. How can I make this work so that a function that does not evaluate, because the test fails, can be made to work once the test has been changed? This is a toy example the background is that I wish to construct a function where the degree of evaluation that takes place is controllable. Hugh Goyder -- This message has been scanned for viruses and dangerous content by the Cranfield MailScanner, and is believed to be clean. === Subject: BasicInput Palette - Restoring Original Size I maximized the BasicInput palette and it appears full screen. How do I get it back to its original (small) display? LW === Subject: Re: Plot Truncation in RealTime3D 1) While attempting to rotate with mouse Range limited plots Shown below obtained without ReallTime3D, pos=ParametricPlot3D[ {Cosh[th] Cos[th+al], th, Cosh[th]Sin[th+al]}, {th,-1.2, 1.2 }, {al,0, 2 Pi} ,PlotRange-> { { -2,2},{2,0},{0,2} } ]; neg=ParametricPlot3D[ {Cosh[th] Cos[th+al], th, -Cosh[th]Sin[th+al]}, {th,-1.2, 1.2 }, {al,0, 2 Pi} ,PlotRange-> { { -2,2},{2,0},{0,2} } ] ; Show[pos,neg] ; .. the PlotRange option cannot be implementable in < This appears to be two different parametrizations of the same surface. When > you Show them together Mathematica has difficulty in rendering them because > it has to keep determining which surface is 'in front'. > I don't understand what you are trying to illustrate in your plot. > David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ > a) How to make ParametricPlot3D to plot in the required PlotRange for > top half surface only? > b) How to omit/hide circumferential circles or parameter lines of al > in Show[pos,neg] ? TIA > < pos=ParametricPlot3D[ {Cosh[th] Cos[th+al], th, Cosh[th]Sin[th+al]}, > {th,-1.2, 1.2 }, {al,0, 2 Pi} ,PlotRange-> { { -2,2},{2,0},{0,2} } ]; > neg=ParametricPlot3D[ {Cosh[th] Cos[th+al], th, -Cosh[th]Sin[th+al]}, > {th,-1.2, 1.2 }, {al,0, 2 Pi} ,PlotRange-> { { -2,2},{2,0},{0,2} } ]; > Show[pos,neg] ; > <: > Hello all, > I have a question about using the nonlinear regression function on a > large data set. Perhaps some of you have suggestions, and can point me > in another direction if this is not the best way to solve this problem. > Basically I have ~100 data sets of ~200 points each, and I'd like to > fit each set to the following function: > G(t) = 1/N * [ y / (1+t/m1) + (1-y) / (1+t/m2) ] > For each data set, the numbers N and y are different, but the numbers > m1 and m2 are the same for all data sets. The problem is that I only > know m1, and not m2. I am hoping to simultaneously solve all these > data sets to come up with a value for m2, but I'm not entirely sure how > to code it. I can come up with a reasonable m2 to start any > regression. > Any thoughts? -- Department of Chemistry and Biochemistry University of Colorado Chemistry 76 Boulder, CO 80309-0215 (303) 492-0579 === Subject: simultaneous nonlinear regression of a lot of data Hello all, I have a question about using the nonlinear regression function on a large data set. Perhaps some of you have suggestions, and can point me in another direction if this is not the best way to solve this problem. Basically I have ~100 data sets of ~200 points each, and I'd like to fit each set to the following function: G(t) = 1/N * [ y / (1+t/m1) + (1-y) / (1+t/m2) ] For each data set, the numbers N and y are different, but the numbers m1 and m2 are the same for all data sets. The problem is that I only know m1, and not m2. I am hoping to simultaneously solve all these data sets to come up with a value for m2, but I'm not entirely sure how to code it. I can come up with a reasonable m2 to start any regression. Any thoughts? === Subject: Re: simultaneous nonlinear regression of a lot of data One possibility is to construct the model as a Piecewise function using an index variable to determine which model to use for each data point. As a shortened example, here is some data and a model comprised of 5 sub data sets and models. In[1]:= g[nn_, y_, m1_, m2_, t_] = 1/nn(y / (1 + t/m1) + (1 - y) / (1 + t/m2) ); In[2]:= datafun[y_, nn_, m1_, m2_] := Table[{y, t, g[nn, y, m1, m2, t]}, {t, 1, 6}] In[3]:= {modelfuns, data} = With[{datasets = Table[{g[nn = Random[Integer, {5, 10}], y, 1.3, m2, t], datafun[y, nn, 1.3, 5 + Random[Real, {-.1, .1}]]}, {y, 5}]}, {datasets[[All, 1]], Flatten[datasets[[All, 2]], 1]}]; This is the model we will fit. In[4]:= InputForm[ model[m2_, i_, t_] = Piecewise[Transpose[{modelfuns, Thread[i == Range[Length[modelfuns]]]}]]] Out[4]//InputForm= Piecewise[{{1/(5*(1 + 0.7692307692307692*t)), i == 1}, {(2/(1 + 0.7692307692307692*t) - (1 + t/m2)^(-1))/6, i == 2}, {(3/(1 + 0.7692307692307692*t) - 2/(1 + t/m2))/9, i == 3}, {(4/(1 + 0.7692307692307692*t) - 3/(1 + t/m2))/7, i == 4}, {(5/(1 + 0.7692307692307692*t) - 4/(1 + t/m2))/10, i == 5}}, 0] For a problem of this size, FindFit will work just fine for computing m2. NonlinearRegress could also be used in this case. In[5]:= FindFit[data, model[m2, i, t], {{m2, 4.5, 5.5}}, {i, t}] Out[5]= {m2 -> 5.00695} For a problem of the magnitude you described, the approach above will be very time and memory consuming. A better approach is to construct the error sum of squares and minimize it using FindMinimum. Here we construct a data set and model based on 100 sub models and sub data sets containing 200 points each. In[6]:= datafun2[y_, nn_, m1_, m2_] := Table[{y, t, g[nn, y, m1, m2, t]}, {t, 1, 200}] In[7]:= {modelfuns, data} = With[{datasets = Table[{g[nn = Random[Integer, {5, 10}], y, 1.3, m2, t], datafun2[y, nn, 1.3, 5 + Random[Real, {-.1, .1}]]}, {y, 100}]}, {datasets[[All, 1]], Flatten[datasets[[All, 2]], 1]}]; In[8]:= model2[m2_, i_, t_] = Piecewise[ Transpose[{modelfuns, Thread[i == Range[Length[modelfuns]] + 1]}]]; The following constructs the sum of squared errors, and shows the optimum value for m2 obtaining by minimizing the sum of squared errors. In[9]:= ssq = Total[Map[(#[[-1]] - model2[m2, #[[1]], #[[2]]]) &, data]^2]; In[10]:= FindMinimum[ssq, {m2, 5}] // Timing Out[10]= {12.187 Second, {914.043, {m2 -> 4.87829}}} Darren Glosemeyer Wolfram Research >Hello all, >I have a question about using the nonlinear regression function on a >large data set. Perhaps some of you have suggestions, and can point me >in another direction if this is not the best way to solve this problem. >Basically I have ~100 data sets of ~200 points each, and I'd like to >fit each set to the following function: >G(t) = 1/N * [ y / (1+t/m1) + (1-y) / (1+t/m2) ] >For each data set, the numbers N and y are different, but the numbers >m1 and m2 are the same for all data sets. The problem is that I only >know m1, and not m2. I am hoping to simultaneously solve all these >data sets to come up with a value for m2, but I'm not entirely sure how >to code it. I can come up with a reasonable m2 to start any >regression. >Any thoughts? === Subject: Typing special symbols in text mode? I'm writing a problem set and would like to use special mathematical notation such as vector arrows, the special R for reals, subscripts and superscripts, and so on (both in equations and in English regular text comments). This would be easy to do in LaTeX, but can it be done in Mathematica? (I know about the export to TeX feature, but it would be nice not to have to go back and change notation after exporting to TeX.) Rex === Subject: Re: Rescale >InputForm@{#,Rescale@#}&@Sort@Table[Random[],{3}] >{{0.1495146427525807, 0.9032356867418898, 0.9803938132050517}, >{2.7755575615628914*^-17, 0.9071367664432557, 1.0000000000000002}} >What is Rescale doing, that it does not always give N@0 and N@1 for >the first and last elements? I would *guess* it is doing exactly as advertised using floating point arithmetic and what you are seeing for some inputs is due to the usual vagaries of floating point arithmetic. -- To reply via email subtract one hundred and four