D-59 Subject: Re: Integrating a complicated expression involving Sign[...] etc. Hi Daniel, > Hi Christian, > I can not answer all your questions, try to be a bit more specific. > Daniel I agree that I am vague but that is because I am at a point where I don't really know what to do. > 2) I would like to understand the structure of some of the intermediate > results (Thetaintegrant in particular) to see if Mathematica might need > a little help (see my earlier post and the kludge below). Is there any > good way to do that? Using TreeForm, for example if I could just look at > the upper most levels of the expression tree? > try the following: > Shallow[TreeForm[ expr ], depth ] > with depth you can control how deep your tree is displayed. of idea about the structure of the intermediate expression before deciding how to handle it. Your suggestion pointed me to the functions short and skeleton which I will study further. Hopefully, I can make some progress now. Christian === Subject: Re: Integrating a complicated expression involving Sign[...] etc. Hi Christian, I can not answer all your questions, try to be a bit more specific. Daniel > I want to ask some general questions. I get some very complicated > intermediate results (see expressions below) that Mathematica does not > proces (Integrate) within a day or two. > 1) Does it normally pay off just leaving it to it? If Mathematica is still > running does it mean that it is doing meaningful transformations and > calculations? > 2) I would like to understand the structure of some of the intermediate > results (Thetaintegrant in particular) to see if Mathematica might need > a little help (see my earlier post and the kludge below). Is there any > good way to do that? Using TreeForm, for example if I could just look at > the upper most levels of the expression tree? try the following: Shallow[TreeForm[ expr ], depth ] with depth you can control how deep your tree is displayed. > 3) My problem seems to have a lot of structure so I am hopeful that > something can be done to help Mathematica a little. > Oh, and a easy one... :-) > 4) How do I use $Assumptions to tell Mathematica that A is real etc. > globally? Wrap your calculations into Assuming[assumptions, expr ] > ----- > (* This is actually a spherical Bessel-function *) > j[k_, n_] = ((-I)^n*Sqrt[2*Pi]*BesselJ[1/2 + n, k])/Sqrt[k] > (* A, B, C are to substituted by sines and cosines to make up polar > coordinates *) > StorMatrix = {{B^2+C^2, A B, A C}, > {B A, A^2+C^2, B C}, > {C A, C B, A^2+B^2}}; > (* My integrant in the case (0, 0) *) > Integrant = Simplify[StorMatrix j[k A, n] j[k B, m] j[k a, 0] Exp[I k (A > x + B y + C z)]/.{n->0, m->0}, > Assumptions -> {A [Element] Reals, B [Element] Reals, > C [Element] Reals, a > 0, > x [Element] Reals, y [Element] Reals, > z [Element] Reals}]; > (* Mathematica refuses to do the definite integral but happily does the > indefinite one *) > KIntegral = Integrate[Integrant, k, > Assumptions -> {A [Element] Reals, B [Element] Reals, > C [Element] Reals, a > 0, > x [Element] Reals, y [Element] Reals, > z [Element] Reals}]; > (* I calculate the lower limit, no problems here *) > Klowlimit = Limit[KIntegral, k -> 0, > Assumptions -> {A [Element] Reals, B [Element] Reals, > C [Element] Reals, a > 0, > x [Element] Reals, y [Element] Reals, > z [Element] Reals}]//Simplify; > (* Upper limit, with ComplexExpand and cheating. True? *) > KinfIntegral = ComplexExpand[KIntegral] /. > {ExpIntegralEi[ I A_ k] -> Sign[ I A] Pi, > ExpIntegralEi[-I A_ k] -> Sign[-I A] Pi}; > Kinflimit = Limit[KinfIntegral, k -> [Infinity], > Assumptions -> {A [Element] Reals, B [Element] Reals, > C [Element] Reals, a > 0, > x [Element] Reals, y [Element] Reals, > z [Element] Reals}]; > Thetaintegrant = (Kinflimit-Klowlimit)/.{A->Sqrt[1-w^2] P, B->Sqrt[1-w^2] > Q, C-> w}; > (* Warning: Mathematica 5.1 gets stuck on this integral : *) > Thetaintegral = > Integrate[Thetaintegrant, {w, -1, 1}, > Assumptions -> {P >= -1, P <= 1, Q >= -1, Q <= 1, a > 0}] === Subject: Re : plot on condition Hello ! Simple way : In[1]:= pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; cnd={7,3,5,8,3}; In[2]:= liste = Transpose[{pnts, cnd}]; In[3]:= Show[Graphics /@ liste /. {a_, c_} -> If[c == 3, {RGBColor[0, 0, 1], PointSize[0.02], Point[a]}, {RGBColor[0, 1, 0], PointSize[0.02], Point[a]}]]; F.Jaccard -----Message d'origine----- hello my question about plotting a list of points but with some condition depends on the status of points in other list; pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; cnd={7,3,5,8,3}; the condition is: plot a point in list pnts in Blue if the corresponding element in list cnd is 3 else plot in Green === Subject: Re: assigning functions Hello ! First way : fprime[x_] = D[f[x], x] Works fine... Or : fprime[x_] := Evaluate[D[f[x], x]] But you can also just write f'[2] ! F.Jaccard -----Message d'origine----- DeÊ: juejung [mailto:juejung@indiana.edu] Envoy.8eÊ: mardi, 19. avril 2005 10:55 ËÊ: mathgroup@smc.vnet.net ObjetÊ: assigning functions dear all, i would like to do the following. assign a function: f[x_] := x^2; take its derivate: D[f[x], x] and assign the result of this to a new function, like fprime[x]: fprime[x_] := D[f[x], x] unfortunately that doesn't work. when i try to evaluate fprime[2] i get an error message. can somebody please help, this haunts me for a while now. juergen === Subject: Precision/FullSimplify Gentle beings, I hope the method of cutting and pasting from Mathematica shown below is acceptable. If not I would appreciate instructions on how to do it in a more acceptable fashion. Consider the likelihood equations for two parameters x and y, based on experimental data (a,b,c,d,e,f,g) that are observed numbers (integers). The likelihood and derivatives are defined in Ma by: L:=(b+d+f)*Log[x]+(e+g)*Log[y]-(a+b)*Log[1+x]-(f+g)*Log[x+y]-(c+d+e)*Log[1+2 *x+y] D[L,x] D[L,y] Yielding the likelihood equations: eq1=(b+d+f)/x-(a+b)/(1+x)-2*(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 eq2=(e+g)/y-(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 which I would like to solve for the maximum likelihood estimates of the parameters and then evaluate for different data sets. Firstly define the information matrix: m11:=-D[D[L,x],x] m12:=-D[D[L,x],y] m21:=-D[D[L,y],x] m22:=-D[D[L,y],y] m:={{m11,m12},{m21,m22}}//MatrixForm m which can be inverted when the equations are solved to give the variances of the estimates. To solve the equations I tried Sols=Solve[{eq1,eq2},{x,y}] Which gives me the answers I want, however the expressions are quite large. By inspection I find that the last solution is the one that corresponds to the maximum likelihood. However I run into problems evaluating the resulting expression. If I try to evaluate the last solution numerically I get a complex number, I assume due to rounding errors. e.g. N[Sols] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2,g->100} produces !({{y [Rule] (-5.336646740150529`) + 1.2546145287986817`*^-14 [ImaginaryI], x [Rule] ((3.8558775093812896`)([InvisibleSpace])) - 2.220446049250313`*^-16 [ImaginaryI]}, {y [Rule] (-1.067199413695643`) - 3.6306168234410265`*^-14 [ImaginaryI], x [Rule] (-0.4135698170735974`) - 6.661338147750939`*^-16 [ImaginaryI]}, {y [Rule] ((50.`)( [InvisibleSpace])) + 1.1823875212257917`*^-14 [ImaginaryI], x [Rule] ((1.`)([InvisibleSpace])) + 6.661338147750939`*^-16 [ImaginaryI]}}) The last solution is the correct one but without the addition of the small complex part. I then tried N[Sols, $MaxPrecision] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, g->100} Which gives me presumably exact expressions, but it is still not clear that they are real. So I tried FullSimplify[ N[Sols, $MaxPrecision] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, g->100}] N[%] {{y[Rule]-5.33665,x[Rule]3.85588},{y[Rule]-1.0672, x[Rule]-0.41357},{y[Rule]50.,x[Rule]1.}} and the last solution appears to be the one I want, but it takes a long time. Now let's try this with a different data set. FullSimplify[ N[Sols, $MaxPrecision] /.{a[Rule]42,b[Rule]90,c[Rule]5,d[Rule]29, e[Rule]49,f[Rule]6,g[Rule]17}] This one seems to hang forever. In any case there must be a better way of evaluating the solutions for different data sets. Should I be telling Mathematica to look for real solutions, using NSolve, substituting in eq1 and eq2 before solving?? It is preferable to generate all the solutions before choosing the one that gives the maximum likelihood. Any suggestions, observations, help will be greatly appreciated. Leigh (Inexperienced User) === Subject: Re: Precision/FullSimplify > Gentle beings, > I hope the method of cutting and pasting from Mathematica shown below is > acceptable. If not I would appreciate instructions on how to do it in a > more acceptable fashion. > Consider the likelihood equations for two parameters x and y, based on > experimental data (a,b,c,d,e,f,g) that are observed numbers (integers). > The likelihood and derivatives are defined in Ma by: > L:=(b+d+f)*Log[x]+(e+g)*Log[y]-(a+b)*Log[1+x]-(f+g)*Log[x+y]-(c+d+e)*Log[1+2* x+y] > D[L,x] > D[L,y] > Yielding the likelihood equations: > eq1=(b+d+f)/x-(a+b)/(1+x)-2*(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 > eq2=(e+g)/y-(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 > which I would like to solve for the maximum likelihood estimates of the > parameters and then evaluate for different data sets. Firstly define the > information matrix: > m11:=-D[D[L,x],x] > m12:=-D[D[L,x],y] > m21:=-D[D[L,y],x] > m22:=-D[D[L,y],y] > m:={{m11,m12},{m21,m22}}//MatrixForm > which can be inverted when the equations are solved to give the > variances of the estimates. To solve the equations I tried > Sols=Solve[{eq1,eq2},{x,y}] > Which gives me the answers I want, however the expressions are quite > large. By inspection I find that the last solution is the one that > corresponds to the maximum likelihood. However I run into problems > evaluating the resulting expression. If I try to evaluate the last > solution numerically I get a complex number, I assume due to rounding > errors. e.g. > N[Sols] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2,g->100} > produces > !({{y [Rule] (-5.336646740150529`) + > 1.2546145287986817`*^-14 [ImaginaryI], > x [Rule] ((3.8558775093812896`)([InvisibleSpace])) - > 2.220446049250313`*^-16 [ImaginaryI]}, {y [Rule] > (-1.067199413695643`) - 3.6306168234410265`*^-14 [ImaginaryI], > x [Rule] (-0.4135698170735974`) - > 6.661338147750939`*^-16 [ImaginaryI]}, {y [Rule] ((50.`)( > [InvisibleSpace])) + 1.1823875212257917`*^-14 [ImaginaryI], > x [Rule] ((1.`)([InvisibleSpace])) + > 6.661338147750939`*^-16 [ImaginaryI]}}) > The last solution is the correct one but without the addition of the > small complex part. I then tried You first approximate exact numbers which appear in Sols and _after_ that replace the variables by exact numbers. This can't be the optimum strategy... N[Sols]/.{a->50,...}//Chop should work here, but it is IMHO better to do exact calculations as long as possible: subs = {a -> 50, b -> 50, c -> 2, d -> 4, e -> 100, f -> 2, g -> 100}; sols = Solve[eq1 && eq2, {x, y}]; nsol = Simplify[RootReduce[sols /. subs]] which will give you three real solutions: {{y -> (1/104)*(-333 - Sqrt[49289]), x -> (1/104)*(179 + Sqrt[49289])}, {y -> (1/104)*(-333 + Sqrt[49289]), x -> (1/104)*(179 - Sqrt[49289])}, {y -> 50, x -> 1}} You want the solution(s) resulting in real L: L0=Select[L/.subs/.nsol,Im[#]==0&] Here is your extremal value of L: {-100 Log[2]+200 Log[50]-102 Log[51]-106 Log[53]} which is approx. N[L0,16] -108.8072743447715 > N[Sols, $MaxPrecision] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, > g->100} $MaxPrecision is usually set to Infinity and its use is to no avail in this context. > Which gives me presumably exact expressions, but it is still not clear > that they are real. So I tried > FullSimplify[ N[Sols, $MaxPrecision] > /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, g->100}] > N[%] > {{y[Rule]-5.33665,x[Rule]3.85588},{y[Rule]-1.0672, > x[Rule]-0.41357},{y[Rule]50.,x[Rule]1.}} > and the last solution appears to be the one I want, but it takes a long > time. Now let's try this with a different data set. > FullSimplify[ > N[Sols, $MaxPrecision] /.{a[Rule]42,b[Rule]90,c[Rule]5,d[Rule]29, > e[Rule]49,f[Rule]6,g[Rule]17}] > This one seems to hang forever. In any case there must be a better way > of evaluating the solutions for different data sets. Should I be telling > Mathematica to look for real solutions, using NSolve, substituting in > eq1 and eq2 before solving?? It is preferable to generate all the > solutions before choosing the one that gives the maximum likelihood. Any > suggestions, observations, help will be greatly appreciated. > Leigh > (Inexperienced User) -- Peter Pein Berlin === Subject: Re: Precision/FullSimplify >> Gentle beings, >> I hope the method of cutting and pasting from Mathematica shown below >> is acceptable. If not I would appreciate instructions on how to do it >> in a more acceptable fashion. >> Consider the likelihood equations for two parameters x and y, based >> on experimental data (a,b,c,d,e,f,g) that are observed numbers >> (integers). The likelihood and derivatives are defined in Ma by: >> L:=(b+d+f)*Log[x]+(e+g)*Log[y]-(a+b)*Log[1+x]-(f+g)*Log[x+y]-(c+d+e)*Log[1+2* x+y] >> D[L,x] >> D[L,y] >> Yielding the likelihood equations: >> eq1=(b+d+f)/x-(a+b)/(1+x)-2*(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 >> eq2=(e+g)/y-(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 >> which I would like to solve for the maximum likelihood estimates of >> the parameters and then evaluate for different data sets. Firstly >> define the information matrix: >> m11:=-D[D[L,x],x] >> m12:=-D[D[L,x],y] >> m21:=-D[D[L,y],x] >> m22:=-D[D[L,y],y] >> m:={{m11,m12},{m21,m22}}//MatrixForm >> m >> which can be inverted when the equations are solved to give the >> variances of the estimates. To solve the equations I tried >> Sols=Solve[{eq1,eq2},{x,y}] >> Which gives me the answers I want, however the expressions are quite >> large. By inspection I find that the last solution is the one that >> corresponds to the maximum likelihood. However I run into problems >> evaluating the resulting expression. If I try to evaluate the last >> solution numerically I get a complex number, I assume due to rounding >> errors. e.g. >> N[Sols] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2,g->100} >> produces >> !({{y [Rule] (-5.336646740150529`) + >> 1.2546145287986817`*^-14 [ImaginaryI], >> x [Rule] ((3.8558775093812896`)([InvisibleSpace])) - >> 2.220446049250313`*^-16 [ImaginaryI]}, {y [Rule] >> (-1.067199413695643`) - 3.6306168234410265`*^-14 [ImaginaryI], >> x [Rule] (-0.4135698170735974`) - >> 6.661338147750939`*^-16 [ImaginaryI]}, {y [Rule] >> ((50.`)( >> [InvisibleSpace])) + 1.1823875212257917`*^-14 [ImaginaryI], >> x [Rule] ((1.`)([InvisibleSpace])) + >> 6.661338147750939`*^-16 [ImaginaryI]}}) >> The last solution is the correct one but without the addition of the >> small complex part. I then tried >> N[Sols, $MaxPrecision] >> /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, >> g->100} >> Which gives me presumably exact expressions, but it is still not >> clear that they are real. So I tried >> FullSimplify[ N[Sols, $MaxPrecision] >> /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, g->100}] >> N[%] >> {{y[Rule]-5.33665,x[Rule]3.85588},{y[Rule]-1.0672, >> x[Rule]-0.41357},{y[Rule]50.,x[Rule]1.}} >> and the last solution appears to be the one I want, but it takes a >> long time. Now let's try this with a different data set. >> FullSimplify[ >> N[Sols, $MaxPrecision] /.{a[Rule]42,b[Rule]90,c[Rule]5,d[Rule]29, >> e[Rule]49,f[Rule]6,g[Rule]17}] >> This one seems to hang forever. In any case there must be a better >> way of evaluating the solutions for different data sets. Should I be >> telling Mathematica to look for real solutions, using NSolve, >> substituting in eq1 and eq2 before solving?? It is preferable to >> generate all the solutions before choosing the one that gives the >> maximum likelihood. Any suggestions, observations, help will be >> greatly appreciated. >> Leigh >> (Inexperienced User) > If you first do > SetOptions[Roots,Cubics->False,Quartics->False]; > you will get solutions in a form that is not subject to vagaries of > cancellation of small imaginary parts. > Here is a related recent discussion in this forum. > http://forums.wolfram.com/mathgroup/archive/2005/Feb/msg00811.html > Daniel Lichtblau > Wolfram Research Leigh === Subject: Re: Precision/FullSimplify Hi Leigh, by using N[..] you are using approximate numbers. Whats wrong if you get an imaginary part that has to be considered zero if one takes into account the precision of the result. Here is a simple example that may clarify the problem. Sqrt[-10^2 3.] - 10 Sqrt[-3.] gives 0. + 3.552713678800501*^-15*I this is zero with an accuracy of approx 15 digits after the decimal separator. Considering machine precision of 16, this result seems quit reasonable. > Gentle beings, > I hope the method of cutting and pasting from Mathematica shown below is > acceptable. If not I would appreciate instructions on how to do it in a > more acceptable fashion. > Consider the likelihood equations for two parameters x and y, based on > experimental data (a,b,c,d,e,f,g) that are observed numbers (integers). > The likelihood and derivatives are defined in Ma by: > L:=(b+d+f)*Log[x]+(e+g)*Log[y]-(a+b)*Log[1+x]-(f+g)*Log[x+y]-(c+d+e)*Log[1+2* x+y] > D[L,x] > D[L,y] > Yielding the likelihood equations: > eq1=(b+d+f)/x-(a+b)/(1+x)-2*(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 > eq2=(e+g)/y-(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 > which I would like to solve for the maximum likelihood estimates of the > parameters and then evaluate for different data sets. Firstly define the > information matrix: > m11:=-D[D[L,x],x] > m12:=-D[D[L,x],y] > m21:=-D[D[L,y],x] > m22:=-D[D[L,y],y] > m:={{m11,m12},{m21,m22}}//MatrixForm > which can be inverted when the equations are solved to give the > variances of the estimates. To solve the equations I tried > Sols=Solve[{eq1,eq2},{x,y}] > Which gives me the answers I want, however the expressions are quite > large. By inspection I find that the last solution is the one that > corresponds to the maximum likelihood. However I run into problems > evaluating the resulting expression. If I try to evaluate the last > solution numerically I get a complex number, I assume due to rounding > errors. e.g. > N[Sols] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2,g->100} > produces > !({{y [Rule] (-5.336646740150529`) + > 1.2546145287986817`*^-14 [ImaginaryI], > x [Rule] ((3.8558775093812896`)([InvisibleSpace])) - > 2.220446049250313`*^-16 [ImaginaryI]}, {y [Rule] > (-1.067199413695643`) - 3.6306168234410265`*^-14 [ImaginaryI], > x [Rule] (-0.4135698170735974`) - > 6.661338147750939`*^-16 [ImaginaryI]}, {y [Rule] ((50.`)( > [InvisibleSpace])) + 1.1823875212257917`*^-14 [ImaginaryI], > x [Rule] ((1.`)([InvisibleSpace])) + > 6.661338147750939`*^-16 [ImaginaryI]}}) > The last solution is the correct one but without the addition of the > small complex part. I then tried > N[Sols, $MaxPrecision] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, > g->100} > Which gives me presumably exact expressions, but it is still not clear > that they are real. So I tried > FullSimplify[ N[Sols, $MaxPrecision] > /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, g->100}] > N[%] > {{y[Rule]-5.33665,x[Rule]3.85588},{y[Rule]-1.0672, > x[Rule]-0.41357},{y[Rule]50.,x[Rule]1.}} > and the last solution appears to be the one I want, but it takes a long > time. Now let's try this with a different data set. > FullSimplify[ > N[Sols, $MaxPrecision] /.{a[Rule]42,b[Rule]90,c[Rule]5,d[Rule]29, > e[Rule]49,f[Rule]6,g[Rule]17}] > This one seems to hang forever. In any case there must be a better way > of evaluating the solutions for different data sets. Should I be telling > Mathematica to look for real solutions, using NSolve, substituting in > eq1 and eq2 before solving?? It is preferable to generate all the > solutions before choosing the one that gives the maximum likelihood. Any > suggestions, observations, help will be greatly appreciated. > Leigh > (Inexperienced User) === Subject: Re: Precision/FullSimplify As a general advice, you can always use Chop to get rid of small rounding errors. for your case it eliminates the small complex parts. Since Chop[] is listable you can operate it directly on lists (the solution of your case) I hope this helps yehuda > Gentle beings, > I hope the method of cutting and pasting from Mathematica shown below is > acceptable. If not I would appreciate instructions on how to do it in a > more acceptable fashion. > Consider the likelihood equations for two parameters x and y, based on > experimental data (a,b,c,d,e,f,g) that are observed numbers (integers). > The likelihood and derivatives are defined in Ma by: > L:=(b+d+f)*Log[x]+(e+g)*Log[y]-(a+b)*Log[1+x]-(f+g)*Log[x+y]-(c+d+e)*Log[1+2* x+y] > D[L,x] > D[L,y] > Yielding the likelihood equations: > eq1=(b+d+f)/x-(a+b)/(1+x)-2*(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 > eq2=(e+g)/y-(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 > which I would like to solve for the maximum likelihood estimates of the > parameters and then evaluate for different data sets. Firstly define the > information matrix: > m11:=-D[D[L,x],x] > m12:=-D[D[L,x],y] > m21:=-D[D[L,y],x] > m22:=-D[D[L,y],y] > m:={{m11,m12},{m21,m22}}//MatrixForm > which can be inverted when the equations are solved to give the > variances of the estimates. To solve the equations I tried > Sols=Solve[{eq1,eq2},{x,y}] > Which gives me the answers I want, however the expressions are quite > large. By inspection I find that the last solution is the one that > corresponds to the maximum likelihood. However I run into problems > evaluating the resulting expression. If I try to evaluate the last > solution numerically I get a complex number, I assume due to rounding > errors. e.g. > N[Sols] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2,g->100} > produces > !({{y [Rule] (-5.336646740150529`) + > 1.2546145287986817`*^-14 [ImaginaryI], > x [Rule] ((3.8558775093812896`)([InvisibleSpace])) - > 2.220446049250313`*^-16 [ImaginaryI]}, {y [Rule] > (-1.067199413695643`) - 3.6306168234410265`*^-14 [ImaginaryI], > x [Rule] (-0.4135698170735974`) - > 6.661338147750939`*^-16 [ImaginaryI]}, {y [Rule] ((50.`)( > [InvisibleSpace])) + 1.1823875212257917`*^-14 [ImaginaryI], > x [Rule] ((1.`)([InvisibleSpace])) + > 6.661338147750939`*^-16 [ImaginaryI]}}) > The last solution is the correct one but without the addition of the > small complex part. I then tried > N[Sols, $MaxPrecision] /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, > g->100} > Which gives me presumably exact expressions, but it is still not clear > that they are real. So I tried > FullSimplify[ N[Sols, $MaxPrecision] > /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, g->100}] > N[%] > {{y[Rule]-5.33665,x[Rule]3.85588},{y[Rule]-1.0672, > x[Rule]-0.41357},{y[Rule]50.,x[Rule]1.}} > and the last solution appears to be the one I want, but it takes a long > time. Now let's try this with a different data set. > FullSimplify[ > N[Sols, $MaxPrecision] /.{a[Rule]42,b[Rule]90,c[Rule]5,d[Rule]29, > e[Rule]49,f[Rule]6,g[Rule]17}] > This one seems to hang forever. In any case there must be a better way > of evaluating the solutions for different data sets. Should I be telling > Mathematica to look for real solutions, using NSolve, substituting in > eq1 and eq2 before solving?? It is preferable to generate all the > solutions before choosing the one that gives the maximum likelihood. Any > suggestions, observations, help will be greatly appreciated. > Leigh > (Inexperienced User) === Subject: Re: Precision/FullSimplify what many Chop[] do ?? Jens leigh pascoe schrieb im > Gentle beings, > I hope the method of cutting and pasting from > Mathematica shown below is > acceptable. If not I would appreciate > instructions on how to do it in a > more acceptable fashion. > Consider the likelihood equations for two > parameters x and y, based on > experimental data (a,b,c,d,e,f,g) that are > observed numbers (integers). > The likelihood and derivatives are defined in Ma > by: > L:=(b+d+f)*Log[x]+(e+g)*Log[y]-(a+b)*Log[1+x]-(f+g)*Log[x+y]-(c+d+e)*Log[1+2* x+y] > D[L,x] > D[L,y] > Yielding the likelihood equations: > eq1=(b+d+f)/x-(a+b)/(1+x)-2*(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 > eq2=(e+g)/y-(c+d+e)/(1+2*x+y)-(f+g)/(x+y)[Equal]0 > which I would like to solve for the maximum > likelihood estimates of the > parameters and then evaluate for different data > sets. Firstly define the > information matrix: > m11:=-D[D[L,x],x] > m12:=-D[D[L,x],y] > m21:=-D[D[L,y],x] > m22:=-D[D[L,y],y] > m:={{m11,m12},{m21,m22}}//MatrixForm > which can be inverted when the equations are > solved to give the > variances of the estimates. To solve the > equations I tried > Sols=Solve[{eq1,eq2},{x,y}] > Which gives me the answers I want, however the > expressions are quite > large. By inspection I find that the last > solution is the one that > corresponds to the maximum likelihood. However I > run into problems > evaluating the resulting expression. If I try to > evaluate the last > solution numerically I get a complex number, I > assume due to rounding > errors. e.g. > N[Sols] > /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2,g->100} > produces > !({{y [Rule] (-5.336646740150529`) + > 1.2546145287986817`*^-14 > [ImaginaryI], > x [Rule] > ((3.8558775093812896`)([InvisibleSpace])) > - > 2.220446049250313`*^-16 > [ImaginaryI]}, {y [Rule] > (-1.067199413695643`) - > 3.6306168234410265`*^-14 [ImaginaryI], > x [Rule] (-0.4135698170735974`) - > 6.661338147750939`*^-16 > [ImaginaryI]}, {y [Rule] ((50.`)( > [InvisibleSpace])) + > 1.1823875212257917`*^-14 [ImaginaryI], > x [Rule] ((1.`)([InvisibleSpace])) > 6.661338147750939`*^-16 > [ImaginaryI]}}) > The last solution is the correct one but without > the addition of the > small complex part. I then tried > N[Sols, $MaxPrecision] > /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, > g->100} > Which gives me presumably exact expressions, but > it is still not clear > that they are real. So I tried > FullSimplify[ N[Sols, $MaxPrecision] > /.{a->50,b->50,c[Rule]2,d[Rule]4,e->100,f[Rule]2, > g->100}] > N[%] > {{y[Rule]-5.33665,x[Rule]3.85588},{y[Rule]-1.0672, > x[Rule]-0.41357},{y[Rule]50.,x[Rule]1.}} > and the last solution appears to be the one I > want, but it takes a long > time. Now let's try this with a different data > set. > FullSimplify[ > N[Sols, $MaxPrecision] > /.{a[Rule]42,b[Rule]90,c[Rule]5,d[Rule]29, > e[Rule]49,f[Rule]6,g[Rule]17}] > This one seems to hang forever. In any case > there must be a better way > of evaluating the solutions for different data > sets. Should I be telling > Mathematica to look for real solutions, using > NSolve, substituting in > eq1 and eq2 before solving?? It is preferable to > generate all the > solutions before choosing the one that gives the > maximum likelihood. Any > suggestions, observations, help will be greatly > appreciated. > Leigh > (Inexperienced User) === Subject: Re: does not simplify to 0 > Mathematica 4.0 for Linux > Copyright 1988-1999 Wolfram Research, Inc. > -- Motif graphics initialized -- > Considering that > In[1]:= FullSimplify[x DiracDelta[x]] > Out[1]= 0 > I was surprised about this one: > In[2]:= FullSimplify[(x-y) DiracDelta[x-y]] > Out[2]= (x - y) DiracDelta[x - y] > whereas: > In[3]:= FullSimplify[(x-y) DiracDelta[x-y]/.x-y->z] > Out[3]= 0 > Is it simply that Mathematica is a little weak on Out[2], or does it have a > good reason for not simplifying, i.e., am I missing something at the > mathematics level? > Alain On the one hand I think the Mathematica implementation of DiracDelta (and KroneckerDelta) leaves a lot to be desired... and that is putting it mildly. (That means I have plenty of much worse examples...). On the other hand, I am not convinced that Mathematica ought to perform this sort of simplification at all. DiracDelta is a generalised function. The statement x DiracDelta[x] == 0 needs a lot of interpreting to make sense of (I prefer to think of it as nonsense). However Integrate[(x-y) DiracDelta[x-y], {x,-Infinity,Infinity}] 0 is correct. Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/andrzej/index.html http://www.mimuw.edu.pl/~akoz/ === Subject: Re: does not simplify to 0 As I remember, DiracDelta is singular and has a meaning only under integration. Anyway the properties of the DiracDelta are kept by Mathematica i.e., Integrate[(x - y)DiracDelta[x - y], {x, -1, 1}, {y, -1, 1}] returns 0 as expected yehuda > Mathematica 4.0 for Linux > Copyright 1988-1999 Wolfram Research, Inc. > -- Motif graphics initialized -- > Considering that > In[1]:= FullSimplify[x DiracDelta[x]] > Out[1]= 0 > I was surprised about this one: > In[2]:= FullSimplify[(x-y) DiracDelta[x-y]] > Out[2]= (x - y) DiracDelta[x - y] > whereas: > In[3]:= FullSimplify[(x-y) DiracDelta[x-y]/.x-y->z] > Out[3]= 0 > Is it simply that Mathematica is a little weak on Out[2], or does it have a > good reason for not simplifying, i.e., am I missing something at the > mathematics level? > Alain === Subject: Re: assigning functions Hi juergen, see below: > dear all, > i would like to do the following. > assign a function: > f[x_] := x^2; > take its derivate: > D[f[x], x] > and assign the result of this to a new function, like fprime[x]: > fprime[x_] := D[f[x], x] := tells Mathematica to delay evaluation of the derivative. If you later use e.g. fprime[2], Mathematica replace x by 2 in your expression giving: D[f[2], 2] what is wrong. What you want is to evaluate the derivative at define-time, d.h.: fprime[x_] = D[f[x], x] > unfortunately that doesn't work. > when i try to evaluate fprime[2] i get an error message. > can somebody please help, this haunts me for a while now. > juergen === Subject: Re: assigning functions You don't need to define a separate function just use f'[x] f[x_]:=x^2; {f'[x],f'[2]} {2 x,4} Nonetheless, you can use Set ( = ) Clear[fprime]; fprime[x_]=D[f[x],x]; {fprime[x],fprime[2]} {2 x,4} or Evaluate the RHS of the SetDelayed ( := ) Clear[fprime]; fprime[x_]:=Evaluate[D[f[x],x]]; {fprime[x],fprime[2]} {2 x,4} Bob Hanlon === > Subject: assigning functions > dear all, > i would like to do the following. > assign a function: > f[x_] := x^2; > take its derivate: > D[f[x], x] > and assign the result of this to a new function, like fprime[x]: > fprime[x_] := D[f[x], x] > unfortunately that doesn't work. > when i try to evaluate fprime[2] i get an error message. > can somebody please help, this haunts me for a while now. > juergen === Subject: Re: match 1, replace 2 right pattern to do some substitution like yours is: In[..]:= ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}}; In[..]:= ls /. {n___Integer, m_Integer} :> {f[n], m} Out[..]:= {{f[1, 2], 3}, {f[4], 5}, {f[6, 7, 8], 9}} (which means to modifiy all but the last element by some function f...) On Tue, 19 Apr 2005 04:54:55 -0400 (EDT) > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. -- Christoph Lhotka -- University of Vienna Institute for Astronomy Tuerkenschanzstr. 17 1180 Vienna, Austria fon. +43.1.4277.518.41 mail. lhotka@astro.univie.ac.at === Subject: Guide to get tex-stuff working in Suse 9.2 I hope someone here has some hint for me. I have written a bigger Mathematica-Module with Mathematica 4.1 . Now the code shall appear as Appendix in a latex document, using tetex under Suse Linux 9.2. For first, I would be content, do save it as tex document, process Latex and pdflatex on the resulting File and get dvips, xdvi, acroread working with the results. (next step would be coexistence of different styles and own defs with the notebook2e.sty etc. to build the Book with Mathematica-generated Texsequences in it) I would like to find just a cooking reciept, what files to get and where to copy them such that everything works. But I didn't find these informations. Is there any howto for this - refering to tetex-2.0 (and Suse 9.2, acroread 7, X11R6) Here, what I did so far: I copied the Directory /usr/local/mathematica/SystemFiles/IncludeFiles/TeX/texmf somewhere, where tetex finds it (in my case $HOME/texmf), als described for tetex1 in the technical support FAQ of Wolfram Research. Unfortunately in tetex2 some files/locations/configs seem to be different, so some of the hints were not aplicable. Now latex gererates a dvifile, then xdvi launches kpathsea-messages like kpathsea: Running mktexpk --mfmode ljfour --bdpi 600 --mag 0+480/600 --dpi 480 Math1Mono-Bold mktexpk: don't know how to create bitmap font for Math1Mono-Bold. and, viewing the result, it seems, that there is no pagebreak inside a cell. pdflatex warns: Warning: pdflatex (file Math1Mono-Bold): Font Math1Mono-Bold at 480 not found viewing the result with acroread (7) pops up Messages: Could not find a font in the resources dictionary - using Helvetica instead. Could not find or create font 'Helvetica'. Some characters may not display or print correctly (indeed this happens). Detlef === Subject: Re: Guide to get tex-stuff working in Suse 9.2 a) switch to the newer and better 4.2 Mathematica fonts b) you *must* include the wolfram.map (for dvips) or the pdfwolfram.map (for pdftex) in the corresponing configuration files. The 4.1 fonts have no pdfwolfram.map map file and you can't use the fonts with pdflatex Jens Detlef M.9fller <=?ISO-8859-1?Q?Detlef_M=FCller?=> schrieb im Newsbeitrag > I hope someone here has some hint for me. > I have written a bigger Mathematica-Module with > Mathematica 4.1 . > Now the code shall appear as Appendix in a latex > document, using > tetex under Suse Linux 9.2. > For first, I would be content, do save it as tex > document, > process Latex and pdflatex on the resulting File > and get > dvips, xdvi, acroread working with the results. > (next step would be coexistence of different > styles > and own defs with the notebook2e.sty etc. to > build > the Book with Mathematica-generated > Texsequences in > it) > I would like to find just a cooking reciept, > what files > to get and where to copy them such that > everything > works. But I didn't find these informations. > Is there any howto for this - refering to > tetex-2.0 (and Suse 9.2, acroread 7, X11R6) > Here, what I did so far: > I copied the Directory > /usr/local/mathematica/SystemFiles/IncludeFiles/TeX/texmf > somewhere, where tetex finds it > (in my case $HOME/texmf), als described for > tetex1 in > the technical support FAQ of Wolfram Research. > Unfortunately > in tetex2 some files/locations/configs seem to > be different, > so some of the hints were not aplicable. > Now latex gererates a dvifile, then > xdvi launches kpathsea-messages like > kpathsea: Running mktexpk --mfmode > ljfour --bdpi 600 --mag 0+480/600 > --dpi 480 Math1Mono-Bold > mktexpk: don't know how to create bitmap font > for Math1Mono-Bold. > and, viewing the result, it seems, that there is > no pagebreak > inside a cell. > pdflatex warns: > Warning: pdflatex (file Math1Mono-Bold): Font > Math1Mono-Bold at 480 not > found > viewing the result with acroread (7) pops up > Messages: > Could not find a font in the resources > dictionary - using > Helvetica instead. > Could not find or create font 'Helvetica'. Some > characters may > not display or print correctly > (indeed this happens). > Detlef === Subject: Re: match 1, replace 2 Trevor, Here is one solution. ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}}; ls /. s_?VectorQ :> Module[{first = Drop[s, -1], last = Last[s]}, Join[Flatten[{# + 100, -1} & /@ first], {last}]] {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ hi mathgroup, what rule takes ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} to {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} ie, matches all integers but the last in each list and then replaces each matched integer n with the 2-element sequence Sequence[100 + n, -1]? trevor. === Subject: Re: plot on condition Needs[Graphics`Colors`] pnts = {{1, 2}, {5, 4}, {3, 2}, {2, 6}, {5, 3}}; cnd = {7, 3, 5, 8, 3}; plotpoints = MapThread[{If[#2 == 3, Blue, Green], Point[#1]} &, {pnts, cnd}] Show[Graphics[ {AbsolutePointSize[5], plotpoints}], Axes -> True, PlotRange -> {{0, 6}, {0, 7}}, ImageSize -> 400, Background -> Linen]; David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ hello my question about plotting a list of points but with some condition depends on the status of points in other list; pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; cnd={7,3,5,8,3}; the condition is: plot a point in list pnts in Blue if the corresponding element in list cnd is 3 else plot in Green === Subject: Re: assigning functions Clear@x f[x_]:=x^2; fprime[x_]=D[f[x],x] 2 x Bobby > dear all, > i would like to do the following. > assign a function: > f[x_] := x^2; > take its derivate: > D[f[x], x] > and assign the result of this to a new function, like fprime[x]: > fprime[x_] := D[f[x], x] > unfortunately that doesn't work. > when i try to evaluate fprime[2] i get an error message. > can somebody please help, this haunts me for a while now. > juergen -- DrBob@bigfoot.com === Subject: Re: assigning functions All you need is to assign the value of x AFTER applying the function, so do as follows fprime[x]/.x->2 Or define the function differently such as fprime1[f_,x_]:=Module[{y},D[f[y],y]/.y->x] and then call it with fprime1[f,2] and get the desired results. Please note that I modified fprime1 a little bit so it would be more general and can be applied for other functions and not only on the globally defined f[x_]:=x^2 as you did good luck yehuda > dear all, > i would like to do the following. > assign a function: > f[x_] := x^2; > take its derivate: > D[f[x], x] > and assign the result of this to a new function, like fprime[x]: > fprime[x_] := D[f[x], x] > unfortunately that doesn't work. > when i try to evaluate fprime[2] i get an error message. > can somebody please help, this haunts me for a while now. > juergen === Subject: Re: plot on condition >-----Original Message----- === >Subject: plot on condition >hello >my question about plotting a list of points but with some >condition depends on >the status of points in other list; >pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; >cnd={7,3,5,8,3}; >the condition is: plot a point in list pnts in Blue if the >corresponding >element in list cnd is 3 else plot in Green Define a function for the graphics directives gd[3] = Sequence[PointSize[.025], Hue[2/3, 1, .7]]; gd[_] = Sequence[PointSize[.015], Hue[1/3, 1, .7]]; ...and MapThread Show[Graphics[{PointSize[.025], MapThread[{gd[#2], Point[#1]} &, {pnts, cnd}]}]] Of course, in case of only a single graphics directive you need no Sequence, in case of none, {} is good as well as Sequence[], e.g.: gd[3] = Sequence[PointSize[.025], Hue[2/3, 1, .7]]; gd[_] = {}; Show[Graphics[{PointSize[.015], Hue[1/3, 1, .7], MapThread[{gd[#2], Point[#1]} &, {pnts, cnd}]}]] -- Hartmut Wolf === Subject: Re: plot on condition Needs[Graphics`Colors`] (* not needed as of 5.1 *) pnts = {{1, 2}, {5, 4}, {3, 2}, {2, 6}, {5, 3}}; cnd = {7, 3, 5, 8, 3}; coloredPoints = {If[#2 == 3, Blue, Green], Point@#1} & @@@ Transpose@{pnts, cnd}; Show[Graphics@{AbsolutePointSize[7], coloredPoints}, Frame -> True]; or coloredPoints = Transpose@{ cnd /. {3 -> Blue, x_Integer -> Green}, Point /@ pnts}; Show[Graphics@{AbsolutePointSize[7], coloredPoints}, Frame -> True] Bobby > hello > my question about plotting a list of points but with some condition depends on > the status of points in other list; > pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; > cnd={7,3,5,8,3}; > the condition is: plot a point in list pnts in Blue if the corresponding > element in list cnd is 3 else plot in Green -- DrBob@bigfoot.com === Subject: Re: plot on condition I'm not sure if you can do it directly under ListPlot, but with combination graphics primitives and some basic programming IT IS POSSIBLE the following will do Graphics[{PointSize[0.05], {If[Last[#] == 3, Green, Red], Point[First[#]]} & /@ Thread[{pnts, cnd}]}, Axes -> True, PlotRange -> All] // Show This may also be generated as a function that take the data and conditions as arguments yehuda > hello > my question about plotting a list of points but with some condition depends on > the status of points in other list; > pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; > cnd={7,3,5,8,3}; > the condition is: plot a point in list pnts in Blue if the corresponding > element in list cnd is 3 else plot in Green === Subject: Re: match 1, replace 2 >-----Original Message----- === >Subject: match 1, replace 2 >hi mathgroup, >what rule takes >ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} >ie, matches all integers but the last in each list and then replaces >each matched integer n with the 2-element sequence Sequence[100 + n, >-1]? >trevor. (Didn't appear this very same question already some time ago?) Replace[ls , {x__, y_} :> Flatten@Append[Transpose[{{x} + 100, PadLeft[{}, Length[{x}], -1]}], y], {1}] Replace[ls , {x__, y_} :> {Apply[Sequence, Transpose[{{x} + 100, PadLeft[{}, Length[{x}], -1]}], {0, 1}], y}, {1}] Replace[ls , {xx__, y_} :> Append[Replace[{xx}, x_ :> Sequence[x + 100, -1], {1}], y], {1}] Replace[Replace[ls, x_ :> Sequence[x + 100, -1], {2}], {xx__, y_, z_} :> {xx, y - 100}, {1}] etc. -- Hartmut Wolf === Subject: How to run multiple sessions on Mac OS X? Is it possible to run multiple sessions of Mathematica simultaneously under Mac OS X? Under Windows, you can do this by clicking the Mathematica icon multiple times, each click opens one instance of front end. But under Mac OS X, clicking the icon only leads to the already running front end without creating a new one. K. Zhang === Subject: Re: How to run multiple sessions on Mac OS X? This is possible if you launch Mathematica from the command line: /Applications/Mathematica 5.1.app/Contents/MacOS/Mathematica but there may be a license limit to the number of processes you are allowed to run. -Rob === Subject: Re: Eigensystem Bug? OS-X On my old G4 laptop running MacOS, and calling your matrix A: Print[Timing[Eigenvalues[Rationalize[A]]//InputForm]]; {0.133333 Second, {-6, -6, -6, -6, 0, 0, 6, 6, 6, 6, -3*Sqrt[2], -3*Sqrt[2], -3*Sqrt[2], -3*Sqrt[2], 3*Sqrt[2], 3*Sqrt[2], 3*Sqrt[2], 3*Sqrt[2]}} Note that all eigenvalues of the rationalized matrix are real. In floating form and using Chop to get rid of tiny scraps: Print[Timing[Chop[Eigenvalues[A]]//InputForm]]; {0. Second, {-6.000000000000011, 6.000000000000005, -6.0000000000000036, -6.000000000000003, 6.000000000000001, 5.999999999999999, 5.999999999999997, -5.999999999999993, -4.242640687119292, -4.2426406871192865, 4.242640687119285, 4.242640687119285, 4.242640687119284, -4.242640687119283, 4.242640687119282, -4.242640687119281, 0, 0}} === Subject: webMathematica 2.2 Released Wolfram Research has just released webMathematica 2.2, which builds on Mathematica 5.1's many new capabilities--especially for working with large-scale, diverse types of data--to provide expanded web development options. Support for new 64-bit architectures means webMathematica 2.2 opens the door to new kinds of application development on a wider range of platforms. Industrial-strength string manipulation in Mathematica 5.1 makes webMathematica a good fit for data mining and bioinformatics applications, while support for web services makes it easy for users to harness financial, environmental, language translation, and other information resources. For further connectivity, the new built-in DatabaseLink provides a ready-made solution for integrating webMathematica with any standard SQL database. This makes webMathematica an ideal web-based environment for analysis, computation, and reporting, which complements the storage and searching capabilities of databases and helps make them accessible at any time from anywhere. webMathematica continues to answer the problem of how to create and distribute technical computing application solutions in today's networked environment. Built on platform-independent standards such as HTML, Java, and Java Servlet technology, webMathematica 2.2 seamlessly integrates the advances of Mathematica 5.1 into virtually any infrastructure. For more information, visit: http://www.wolfram.com/webmathematica === Subject: Exact Symbolic Notation It is a pleasure talk to you all again. My plain question is: I want to use some exact notation with Mathematica. For instance, I want to use variables like p' instead of pline (or something like that). Also I want to use P2 (with the 2 underlined). The last option works in some calculations but not in all of them (Why?). Finally I want to define f1[x] as a function with the 1 underlined(Why is not working?). Any enlightment on these subject are very welcome. Alex === Subject: Re: Exact Symbolic Notation and you have not found the Notation` package ? And you can't setup a definition like P2 /: MakeBoxes[P2, fmt_:StandardForm] := RowBox[{P, [NegativeVeryThinSpace], StyleBox[2, FontVariations -> {Underline -> True}]}] f1 /: MakeBoxes[f1, fmt_:StandardForm] := RowBox[{f, [NegativeVeryThinSpace], StyleBox[1, FontVariations -> {Underline -> True}]}] that's too bad. Jens Alexandre Costa schrieb im > It is a pleasure talk to you all again. > My plain question is: > I want to use some exact notation with > Mathematica. For instance, > I want to use variables like p' instead of > pline (or something like that). > Also I want to use P2 (with the 2 underlined). > The last option works in some > calculations but not in all of them (Why?). > Finally I want to define f1[x] as a function > with the 1 underlined(Why > is not working?). > Any enlightment on these subject are very > welcome. > Alex === Subject: Re: plot on condition >hello my question about plotting a list of points but with some >condition depends on the status of points in other list; >pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; cnd={7,3,5,8,3}; the >condition is: plot a point in list pnts in Blue if the One way to do this in version 5.1 would be Show[Block[{$DisplayFunction = Identity}, {ListPlot[Pick[pnts, (3 == #1 & ) /@ cnd], PlotStyle -> Blue], ListPlot[Pick[pnts, (3 != #1 & ) /@ cnd], PlotStyle -> Green]}]]; -- To reply via email subtract one hundred and four === Subject: Re: match 1, replace 2 >what rule takes >ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} >{{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, >9}} >ie, matches all integers but the last in each list and then >replaces each matched integer n with the 2-element sequence >Sequence[100 + n, -1]? One way to get this result would be Flatten@{Transpose@ {100 + Most@#1, Table[-1, {Length@#1 - 1}]}, Last@#1}&/@ ls {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} -- To reply via email subtract one hundred and four === Subject: Re: assigning functions > sorry, i just found the solution myself. yes, the help file is helpful ;-) > f[x_] := x^2; > fprime[x_] = D[f[x], x] > works just fine! > the set delayed assignment rule for the second part was wrong. Why not just use: f[x_]=x^2; f'[x] -- Helen Read University of Vermont === Subject: Re: assigning functions > sorry, i just found the solution myself. yes, the help file is helpful ;-) > f[x_] := x^2; > fprime[x_] = D[f[x], x] > works just fine! > the set delayed assignment rule for the second part was wrong. > best > juergen >>dear all, >>i would like to do the following. >>assign a function: >>f[x_] := x^2; >>take its derivate: >>D[f[x], x] >>and assign the result of this to a new function, like fprime[x]: >>fprime[x_] := D[f[x], x] >>unfortunately that doesn't work. >>when i try to evaluate fprime[2] i get an error message. >>can somebody please help, this haunts me for a while now. >>juergen Just to remind you: In[1]:= f[x_] := x^2; fprime[x_] = D[f[x], x]; fprime[z] f[x_] := x^3; fprime[z] Out[3]= 2*z Out[5]= 2*z fprime didn't recognize the change of f. f[x_] := x^2; fprimeDelayed[x_] := Derivative[1][f][x] fprimeDelayed[z] f[x_] := x^3; fprimeDelayed[z] Out[8]= 2*z Out[10]= 3*z^2 this one did. -- Peter Pein Berlin === Subject: Re: assigning functions Hi! In[1]:= f[x_]:= x^2 In[2]:=fprime[x0_]:=D[f[x],x]/.x->x0 In[3]:= f[8] Out[3]:= 64 In[4]:= fprime[8] Out[4]:= 16 On Tue, 19 Apr 2005 04:55:01 -0400 (EDT) > dear all, > i would like to do the following. > assign a function: > f[x_] := x^2; > take its derivate: > D[f[x], x] > and assign the result of this to a new function, like fprime[x]: > fprime[x_] := D[f[x], x] > unfortunately that doesn't work. > when i try to evaluate fprime[2] i get an error message. > can somebody please help, this haunts me for a while now. > juergen -- Christoph Lhotka -- University of Vienna Institute for Astronomy Tuerkenschanzstr. 17 1180 Vienna, Austria fon. +43.1.4277.518.41 mail. lhotka@astro.univie.ac.at === Subject: Reduce bug report I am sending this to MathGroup first in the hope that I am wrong. In the code below, I give two sets of equations. On Mathematica 5.0 for Windows, the Reduce command does not finish evaluation if Most@ is removed from the second equation set. I have done my best to make sure the problem is well posed by making sure there are exactly as many equations as unknowns (less unit variables) and by telling Mathematica that all units are nonzero. Reduce can easily handle it if the last equation of the defining equations (prob2[defineqns]) is separate system from the rest of the equations, but this should be unnecessary. I realize that it is possible I have made a mistake in posing the problem to Mathematica; if so, please enlighten me. prob2[given]={[ScriptCapitalN][3600][Equal](3600*Circle)/Minute, BT[max,3600][Equal](236*Meter*Newton)/Radian,[ScriptCapitalN][ 5500][Equal](5500*Circle)/Minute,BP[max,5500][Equal]100*Kilo*Watt, z[Equal](2*Circle)/Cycle,Vd[Equal]3*Liter,[Eta][mech][Equal]9/10, sfc[Equal](9*Kilogram)/(100*Joule*Mega), LHV[Equal](44*Joule*Mega)/Kilogram,CR[Equal]89/10,k[Equal]7/5} prob2[defineqns]= Most@{BP[max,3600][Equal]BT[max,3600]*[ScriptCapitalN][3600], BP[max,5500][Equal]BT[max,5500]*[ScriptCapitalN][5500], BMEP[max,3600][Equal](2*Pi*Radian*z*BT[max,3600])/(Circle*Vd), BMEP[max,3600]/IMEP[max,3600][Equal][Eta][mech], BMEP[max,5500][Equal](2*Pi*Radian*z*BT[max,5500])/(Circle*Vd), BMEP[max,5500]/IMEP[max,5500][Equal][Eta][mech],[Eta][ ind][Equal]1/(LHV*sfc),[Eta][otto][Equal]1-(CR^(-1))^(-1+k)} prob2[units]={Circle,Cycle,Joule,Kilo,Kilogram,Liter,Mega,Meter,Minute,Newto n, Radian,Watt} prob2[redvars]={CR,k,LHV,sfc,Vd,z,BMEP[max,3600],BMEP[max,5500],BP[max,3600] , BP[max,5500],BT[max,3600],BT[max,5500],IMEP[max,3600], IMEP[max,5500],[ScriptCapitalN][3600],[ScriptCapitalN][5500],[Eta][ ind],[Eta][mech],[Eta][otto]} prob2[numsoln]= Refine[Reduce[Flatten@{prob2[given],prob2[defineqns]},prob2[redvars], Backsubstitution->True],#!=0&/@prob2[units]] -- Chris Chiasson Kettering University Mechanical Engineering Graduate Student 1 810 265 3161 === Subject: Re: Reduce bug report Andrzej Kozlowski: Your point about Reduce requiring more time to work through the more complicated equations is taken. It is unfortunate that Mathematica does not recognize that the extra equation is almost trivial to solve. I was using reduce to be rigorous with the solution; I suppose that is a step I am no longer patient enough to take. elimination feature in Solve. > *This message was transferred with a trial version of CommuniGate(tm) Pro* > *This message was transferred with a trial version of CommuniGate(tm) > Pro* > I am sending this to MathGroup first in the hope that I am wrong. > In the code below, I give two sets of equations. On Mathematica 5.0 > for Windows, the Reduce command does not finish evaluation if Most@ is > removed from the second equation set. > I have done my best to make sure the problem is well posed by making > sure there are exactly as many equations as unknowns (less unit > variables) and by telling Mathematica that all units are nonzero. > Reduce can easily handle it if the last equation of the defining > equations (prob2[defineqns]) is separate system from the rest of the > equations, but this should be unnecessary. > I realize that it is possible I have made a mistake in posing the > problem to Mathematica; if so, please enlighten me. > prob2[given]={[ScriptCapitalN][3600][Equal](3600*Circle)/Minute, > BT[max,3600][Equal](236*Meter*Newton)/Radian,[ScriptCapitalN][ > 5500][Equal](5500*Circle)/Minute,BP[max,5500][Equal]100*Kilo*Watt, > z[Equal](2*Circle)/Cycle,Vd[Equal]3*Liter,[Eta][mech][Equal]9/10, > sfc[Equal](9*Kilogram)/(100*Joule*Mega), > LHV[Equal](44*Joule*Mega)/Kilogram,CR[Equal]89/10,k[Equal]7/5} > prob2[defineqns]= > Most@{BP[max,3600][Equal]BT[max,3600]*[ScriptCapitalN][3600], > BP[max,5500][Equal]BT[max,5500]*[ScriptCapitalN][5500], > BMEP[max,3600][Equal](2*Pi*Radian*z*BT[max,3600])/(Circle*Vd), > BMEP[max,3600]/IMEP[max,3600][Equal][Eta][mech], > BMEP[max,5500][Equal](2*Pi*Radian*z*BT[max,5500])/(Circle*Vd), > BMEP[max,5500]/IMEP[max,5500][Equal][Eta][mech],[Eta][ > ind][Equal]1/(LHV*sfc),[Eta][otto][Equal]1-(CR^(-1))^(-1+k)} > prob2[units]={Circle,Cycle,Joule,Kilo,Kilogram,Liter,Mega,Meter,Minute, > Newton, > Radian,Watt} > prob2[redvars]={CR,k,LHV,sfc,Vd,z,BMEP[max,3600],BMEP[max,5500],BP[max, > 3600], > BP[max,5500],BT[max,3600],BT[max,5500],IMEP[max,3600], > IMEP[max,5500],[ScriptCapitalN][3600],[ScriptCapitalN][5500],[Eta][ > ind],[Eta][mech],[Eta][otto]} > prob2[numsoln]= > Refine[Reduce[Flatten@{prob2[given],prob2[defineqns]},prob2[redvars], > Backsubstitution->True],#!=0&/@prob2[units]] > -- > Chris Chiasson > Kettering University > Mechanical Engineering > Graduate Student > 1 810 265 3161 > In my opinion it is a bad idea to use Reduce in such cases. Reduce > attempts to give you a complete solution, which will means it will > try to obtain all conditions on your parameters and variables and while > doing so it may try to use algorithms such as Cylindrical Algebraic > Decomposition (for some strange reason renamed in Mathematica 5.1 as > CylindircalDecomposition) or Quantifier Elimination which have very > high complexity in the naumber of variables. The result is that Reduce > may take a very long time to deal with expressions involving many > unknowns, even if they are actually very simple ones. Actually, on my 1 > Gigaherz Powerbook G4 I can't get an answer to your system in > reasonable time even if Most is present. > However, I think the way to deal with your system is by using Solve and > not Reduce. The problem is that you can't use Solve directly, because > it will notice not algebraic equations in your system and without > checking that actually the variables in which the equations are > non-algebraic can be easily eliminated, Solve will refuse to proceed > further. The way to avoid this is to tell Solve to eliminate these > variables as follows: > prob2[numsoln] = Solve[Flatten[{prob2[given], prob2[defineqns]}], > prob2[redvars], First /@ prob2[given]] > {{BP[max, 3600] -> (849600*Circle*Meter*Newton)/(Minute*Radian), > .8d[otto] -> 1 - (10/89)^(2/5), > BP[max, 5500] -> 100*Kilo*Watt, .8d[ind] -> 25/99, > [ScriptCapitalN][3600] -> (3600*Circle)/Minute, > [ScriptCapitalN][5500] -> (5500*Circle)/Minute, BMEP[max, 3600] -> > (944*Meter*Newton*Pi)/(3*Cycle*Liter), > BMEP[max, 5500] -> > (4*Kilo*Minute*Pi*Radian*Watt)/(165*Circle*Cycle*Liter), > IMEP[max, 3600] -> (9440*Meter*Newton*Pi)/(27*Cycle*Liter), > IMEP[max, 5500] -> > (8*Kilo*Minute*Pi*Radian*Watt)/(297*Circle*Cycle*Liter), > BT[max, 5500] -> (Kilo*Minute*Watt)/(55*Circle), LHV -> > (44*Joule*Mega)/Kilogram, > BT[max, 3600] -> (236*Meter*Newton)/Radian, sfc -> > (9*Kilogram)/(100*Joule*Mega), Vd -> 3*Liter, > z -> (2*Circle)/Cycle}} > There may be some other reason why you wanted to use Reduce, but the > above seems to me to give as complete an answer as you could hope to > get. > Andrzej Kozlowski > Chiba, Japan > http://www.akikoz.net/andrzej/index.html > http://www.mimuw.edu.pl/~akoz/ -- Chris Chiasson Kettering University Mechanical Engineering Graduate Student 1 810 265 3161 === Subject: Re: Reduce bug report I am sending this to MathGroup first in the hope that I am wrong. .be.be Éî ôècode below, I give two sets of equations. On Mathematica 5.0 for Windows, the Reduce command does not finish evaluation if Most@ is removed from the second equation set. .be.be have done my best to make sure the problem is well posed by making sure there are exactly as many equations as unknowns (less unit variables) and by telling Mathematica that all units are nonzero. .be.be Òåäõãå ãáeasily handle it if the last equation of the defining equations (prob2[defineqns]) is separate system from the rest of the equations, but this should be unnecessary. .be.be realize that it is possible I have made a mistake in posing the problem to Mathematica; if so, please enlighten me. .be.be [Eth]òïâ.b2Ûçé[OD oubleDot]åî[CapitalYAcute].bdûÜ[Capi talUHat]Óãòé[Eth]ô[CapitalATil de]á[Eth]éôáìÎ[CapitalYA cute]Û.b3¶°°[CapitalYAcute][Capita lUDoubleDot]ÛÅñõáì [CapitalYAcute]¨.b3¶°°ªÃ[E Acute]òãì婯Í[EA cute]îõôå¬ BT[max,3600][Equal](236*Meter*Newton)/Radian,[ScriptCapitalN][ 5500][Equal](5500*Circle)/Minute,BP[max,5500][Equal]100*Kilo*Watt, z[Equal](2*Circle)/Cycle,Vd[Equal]3*Liter,[Eta][mech][Equal]9/10, sfc[Equal](9*Kilogram)/(100*Joule*Mega), LHV[Equal](44*Joule*Mega)/Kilogram,CR[Equal]89/10,k[Equal]7/5} .be.be [Eth]òïâ.b2Ûäå[A E]éîåñîó[CapitalYAcute] .bd.be ÍïóôÀû[Capital AHat][CapitalEth]Ûíáø¬.b3[Paragr aph]°°[CapitalYAcute]ÜÛ[Cap italARing]ñõáì[CapitalYAcute] ÔÛíáø¬.b3¶ °°[CapitalYAcute]ªÜÛ[Cap italOAcute]ãòé[Eth]ôÃá [Eth]éôáìÎ[CapitalYAcute][Capit alUHat].b3¶°°[CapitalYAcute] ¬.be Â[CapitalEth]Ûíáø¬[M icro][Micro]°°[CapitalYAcute]Ü[CapitalU Hat]Åñõáì[CapitalYAcute][Capi talAHat]ÔÛíáø¬[Micro] [Micro]°°[CapitalYAcute]ªÜ[CapitalUH at]Óãòé[Eth]ôÃ[ AAcute][Eth]éôáìÎ[CapitalYAcute] Û[Micro][Micro]°°[CapitalYAcute] ¬.be ÂÍÅ[CapitalEth]Û[IAc ute]áø¬.b3¶°°[CapitalYAcute ]ÜÛÅñõá ì[CapitalYAcute]¨.b2ª[CapitalEth]éª[CapitalOGrav e]áäéáîªúª[CapitalAH at]ÔÛíáø¬.b3[Paragra ph]°°[CapitalYAcute]©¯¨Ã[EA cute]òãìåªÖä © ¬.be ÂÍÅ[CapitalEth]Û[IAc ute]áø¬.b3¶°°[CapitalYAcute ]¯ÉÍÅ[CapitalEth][CapitalUHa t]íáø¬.b3¶°°[Capita lYAcute]ÜÛÅñõ[ AAcute]ì[CapitalYAcute]ÜÛ[CapitalAR ing]ôá[CapitalYAcute]Ûíåã è[CapitalYAcute]¬ BMEP[max,5500][Equal](2*Pi*Radian*z*BT[max,5500])/(Circle*Vd), BMEP[max,5500]/IMEP[max,5500][Equal][Eta][mech],[Eta][ ind][Equal]1/(LHV*sfc),[Eta][otto][Equal]1-(CR^(-1))^(-1+k)} .be.be [Eth]òïâ.b2Ûõî[EAcute ]ôó[CapitalYAcute].bdûÃé[OGrave ]ãìå¬Ãùãì å¬Êïõìå¬[Ca pitalEDoubleDot]éìï¬Ë[EA cute]ìïçòáí¬[Capi talIGrave]éôåò¬Íå[CC edilla]á¬Íåôåò¬ Íéîõôå Newton, Radian,Watt} .be.be [Eth]òïâ.b2Ûòå[ADoub leDot]öáòó[CapitalYAcute].bdû[Ca pitalATilde]Ò¬ë¬Ì[Capita lEGrave]Ö¬óæã¬[CapitalODoub leDot]ä¬ú¬ÂÍ[Capit alARing][CapitalEth]Ûíáø¬.b3[Par agraph]°°[CapitalYAcute]¬ÂÍ Å[CapitalEth]Ûíáø¬[ Micro][Micro]°°[CapitalYAcute]¬Â[Capital Eth]Ûíáø 3600], BP[max,5500],BT[max,3600],BT[max,5500],IMEP[max,3600], IMEP[max,5500],[ScriptCapitalN][3600],[ScriptCapitalN][5500],[Eta][ ind],[Eta][mech],[Eta][otto]} .be.be [Eth]òïâ.b2Ûîõ[IAcute ]óïìî[CapitalYAcute] .bd.be ÒåæéîåÛ[CapitalO Grave]åäõãåÛ[CapitalA E]ìáôôåîÀû[Eth ]òïâ.b2Ûçé[ODouble Dot]åî[CapitalYAcute]¬[Eth]òïâ 262Ûäåæéîåñ îó[CapitalYAcute][YAcute]¬[Eth]òï[ AHat].b2Ûòåäöá[ OGrave]ó[CapitalYAcute] ¬.be Âáãëóõâ[OAcut e]ôéôõôéïî[Hyphe n].beÔòõå[CapitalYAcute]¬[Sterlin g]¡.bd°.a6¯À[Eth]ò[IDo ubleDot]â.b2Ûõîéôó[C apitalYAcute][CapitalYAcute] .be.be Òåçáòäó[ Not] -- Chris Chiasson Kettering University Mechanical Engineering Graduate Student 1 810 265 3161 Éî íù ï[Eth]éîéïit is a bad idea to use Reduce in such cases. Reduce áôôåí[Eth]ôó ôï çéöå ùïa complete solution, which will means it will ôòto obtain all conditions on your parameters and variables and while äïéîso it may try to use algorithms such as Cylindrical Algebraic Äåãïí[Eth][IDoubleDo t]óéôéï(for some strange reason renamed in Mathematica 5.1 as Ãùìéîäé[OG rave]ãáìÄåã[IDoubl eDot]í[Eth]ïóéôé[IDoubleD ot]îor Quantifier Elimination which have very èéçè ãïí[Eth]ìåøé[OHa t]ù éî ôènaumber of variables. The result is that Reduce íátake a very long time to deal with expressions involving many õîëîï÷îóev en if they are actually very simple ones. Actually, on my 1 Çéçáèåò[U Acute] [CapitalEth]ï÷åòâï[IDo ubleDot]G4 I can't get an answer to your system in òåáóïîáâ[IGr ave]å ôéíå åöåî éæ Íïóô éó [Eth]òåóåîô® Èï÷åöåò ¬ think the way to deal with your system is by using Solve and îïReduce. The problem is that you can't use Solve directly, because éô ÷éìì îïôéãå ¢îïô áìçåâòáéequati ons in your system and without ãèåãëéîç ôèáô áãôõáììù ôèvariables in which the equations are îïî[Hyphen]áìçå[A Hat]òáécan be easily eliminated, Solve will refuse to proceed æõòôèåò[RegisteredTrademar k] Ôèway to avoid this is to tell Solve to eliminate these öáòéáâìåas follows: [Eth]òïâ.b2Ûîõ[IAcut e]óïìî[CapitalYAcute] Solve[Flatten[{prob2[given], prob2[defineqns]}], [Eth]òïâ.b2Ûòå[ADou bleDot]öáòó[CapitalYAcute]First /@ prob2[given]] ûûÂ[CapitalEth]Ûíá[O Slash]3600] -> (849600*Circle*Meter*Newton)/(Minute*Radian), ¤Â.a6ǨÂ[Capital UHat]ïôôï[CapitalYAcute] [Hyphen].be - (10/89)^(2/5), Â[CapitalEth]Ûíáø5500] -> 100*Kilo*Watt, $B&G(B[ind] -> 25/99, ÜÛÓãò[EAcute ][Eth]ôÃá[Eth]éôá[IGrav e]Î[CapitalYAcute]Û.b3¶°[Degr ee]-> (3600*Circle)/Minute, ÜÛÓãòé [Eth]ôÃá[Eth]éôá[IGrave ]Î[CapitalYAcute]Û[Micro][Micro]°[Degre e]-> (5500*Circle)/Minute, BMEP[max, 3600] -> ¨.b9´´ªÍåôåòª[Ca pitalIHat]å÷ôïîª[CapitalEth][EAcu te]©¯¨.b3ªÃùãì[A Ring]ªÌéôåò©¬ ÂÍÅ[CapitalEth]Û[IAc ute]áø5500] -> ¨´ªËéìïª[Capital IAcute]éîõôåª[CapitalEth]éª Òáäéáîª[Times][ AAcute]ôô©¯¨±¶[Micro]ª Ãéòãìåª[CapitalATil de]ùãìåªÌéô[A Ring]ò©¬ ÉÍÅ[CapitalEth]Û[I Acute]áø3600] -> (9440*Meter*Newton*Pi)/(27*Cycle*Liter), ÉÍÅ[CapitalEth]Û[I Acute]áø5500] -> ¨¸ªËéìïª[Capital IAcute]éîõôåª[CapitalEth]éª Òáäéáîª[Times][ AAcute]ôô©¯¨.b2.b9·ª[CapitalATi lde]éòãìåªÃù ãìåªÌéôå[OGrav e]©¬ ÂÔÛíáø5500] -> (Kilo*Minute*Watt)/(55*Circle), LHV -> ¨´´ªÊïõìåª[C apitalIAcute]åçá©¯Ë éìïçòáí BT[max, 3600] -> (236*Meter*Newton)/Radian, sfc -> ¨.b9ªËéìïç[ OGrave]áí©¯¨±°°2 52ÊïõìåªÍ[ ARing]çᩬ Öä [Hyphen].be .b3ªÌéôåò¬ -> (2*Circle)/Cycle}} Ôèåòmay be some other reason why you wanted to use Reduce, but the áâïöseems to me to give as complete an answer as you could hope to çåô® ÁîäòúåKozlowski ÃèéâᬠÊá[Eth]á îèôô[Eth]º¯¯÷÷÷ ®áëéë[IDoubleDo t]ú®îåô¯áî[ ADoubleDot]òúåê¯éîä åø®èôí ìèôô[Eth]º¯¯÷÷[Divide ]®íéíõ÷[Registe redTrademark]åäõ®[Eth][IGra ve]¯[Thorn]áëïú === Subject: Re: Reduce bug report > I am sending this to MathGroup first in the hope that I am wrong. > In the code below, I give two sets of equations. On Mathematica 5.0 > for Windows, the Reduce command does not finish evaluation if Most@ is > removed from the second equation set. > I have done my best to make sure the problem is well posed by making > sure there are exactly as many equations as unknowns (less unit > variables) and by telling Mathematica that all units are nonzero. > Reduce can easily handle it if the last equation of the defining > equations (prob2[defineqns]) is separate system from the rest of the > equations, but this should be unnecessary. > I realize that it is possible I have made a mistake in posing the > problem to Mathematica; if so, please enlighten me. > prob2[given]={[ScriptCapitalN][3600][Equal](3600*Circle)/Minute, > BT[max,3600][Equal](236*Meter*Newton)/Radian,[ScriptCapitalN][ > 5500][Equal](5500*Circle)/Minute,BP[max,5500][Equal]100*Kilo*Watt, > z[Equal](2*Circle)/Cycle,Vd[Equal]3*Liter,[Eta][mech][Equal]9/10, > sfc[Equal](9*Kilogram)/(100*Joule*Mega), > LHV[Equal](44*Joule*Mega)/Kilogram,CR[Equal]89/10,k[Equal]7/5} > prob2[defineqns]= > Most@{BP[max,3600][Equal]BT[max,3600]*[ScriptCapitalN][3600], > BP[max,5500][Equal]BT[max,5500]*[ScriptCapitalN][5500], > BMEP[max,3600][Equal](2*Pi*Radian*z*BT[max,3600])/(Circle*Vd), > BMEP[max,3600]/IMEP[max,3600][Equal][Eta][mech], > BMEP[max,5500][Equal](2*Pi*Radian*z*BT[max,5500])/(Circle*Vd), > BMEP[max,5500]/IMEP[max,5500][Equal][Eta][mech],[Eta][ > ind][Equal]1/(LHV*sfc),[Eta][otto][Equal]1-(CR^(-1))^(-1+k)} > prob2[units]={Circle,Cycle,Joule,Kilo,Kilogram,Liter,Mega,Meter,Minute,Newton , > Radian,Watt} > prob2[redvars]={CR,k,LHV,sfc,Vd,z,BMEP[max,3600],BMEP[max,5500],BP[max,3600], > BP[max,5500],BT[max,3600],BT[max,5500],IMEP[max,3600], > IMEP[max,5500],[ScriptCapitalN][3600],[ScriptCapitalN][5500],[Eta][ > ind],[Eta][mech],[Eta][otto]} > prob2[numsoln]= > Refine[Reduce[Flatten@{prob2[given],prob2[defineqns]},prob2[redvars], > Backsubstitution->True],#!=0&/@prob2[units]] Hi Chris, Reduce does too much work and uses too much time and memory in this case. Simply try in place of your assignment to prob2[numsoln]: prob2[presoln] = Solve[Flatten[{prob2[given], Most[prob2[defineqns]]}], Most[prob2[redvars]]]; prob2[numsoln] = {Join[prob2[presoln][[1]], Simplify[First[Solve[Last[prob2[defineqns] /. prob2[presoln]], Last[prob2[redvars]]]]]]} This ends almost immediately and the memory usage is moderate compared to Refine/Reduce. -- Peter Pein Berlin === Subject: Lists of equations. Again In version 5.0 FindRoot[{{x, y} == {1, 1}}, {x, 2}, {y, 2}] failed: it complained about the non-numerical jacobian and just returned the starting point. This now works in version 5.1; however, there is still exactly the same problem with higher-dimensional lists: FindRoot[Array[a, {2, 2}] == IdentityMatrix[2], Evaluate[Sequence@@ (Flatten[#, 1]&)@ Array[{a[##], 0}&, {2, 2}]]] This generates Thread::tdlen and FindRoot::njnum messages, indicating that there is again something wrong with the processing of lists. Strangely, FindRoot[Array[a, {2, 2}] - IdentityMatrix[2], Evaluate[Sequence@@ (Flatten[#, 1]&)@ Array[{a[##], 0}&, {2, 2}]]] works without a problem (another possible way to resolve this issue is to specify Jacobian -> IdentityMatrix[4]). If the specified form of the jacobian doesn't have the correct structure, this often results in the kernel crash: FindRoot[x == {1, 2}, {x, {0, 0}}, Jacobian -> {{{1}, {1}}}] (*crashes the kernel*) This may happen even if the structure is correct: FindMinimum[x^2, {x, 1}, Method -> {Newton, Hessian -> {{2}}}] (*crashes the kernel*) Here the hessian is specified correctly, but unless the gradient is also given explicitly as Gradient -> {2x}, all the other settings (Automatic, Symbolic, FiniteDifference) lead to the kernel crash. Maxim Rytin m.r@inbox.ru === Subject: Re: Lists of equations. Again Hi Maxim, the problem is that your expression has syntax errors. 1) It look like FindRoot does not like tensor equations. You must expand the equations like e.g.: eq=MapThread[Equal,{Array[a, {2, 2}],IdentityMatrix[2]},2]; 2) The second argument to FindRoot must contain a list of variables and start values. Sequence[..] is not a list. E.g. wrap your expression in a list: var={Sequence @@ (Flatten[#, 1] &)@Array[{a[##], 0} &, {2, 2}]} This then finally works: FindRoot[eq,var] > In version 5.0 FindRoot[{{x, y} == {1, 1}}, {x, 2}, {y, 2}] failed: it > complained about the non-numerical jacobian and just returned the starting > point. This now works in version 5.1; however, there is still exactly the > same problem with higher-dimensional lists: > FindRoot[Array[a, {2, 2}] == IdentityMatrix[2], > Evaluate[Sequence@@ (Flatten[#, 1]&)@ Array[{a[##], 0}&, {2, 2}]]] > This generates Thread::tdlen and FindRoot::njnum messages, indicating that > there is again something wrong with the processing of lists. Strangely, > FindRoot[Array[a, {2, 2}] - IdentityMatrix[2], > Evaluate[Sequence@@ (Flatten[#, 1]&)@ Array[{a[##], 0}&, {2, 2}]]] > works without a problem (another possible way to resolve this issue is to > specify Jacobian -> IdentityMatrix[4]). > If the specified form of the jacobian doesn't have the correct structure, > this often results in the kernel crash: > FindRoot[x == {1, 2}, {x, {0, 0}}, Jacobian -> {{{1}, {1}}}] > (*crashes the kernel*) > This may happen even if the structure is correct: > FindMinimum[x^2, {x, 1}, > Method -> {Newton, Hessian -> {{2}}}] > (*crashes the kernel*) > Here the hessian is specified correctly, but unless the gradient is also > given explicitly as Gradient -> {2x}, all the other settings (Automatic, > Symbolic, FiniteDifference) lead to the kernel crash. > Maxim Rytin > m.r@inbox.ru === Subject: Re: holding boxes verbatim > Mathematica is annoying me. I would like some way to type in a two > dimensional box form (representing an arbitrary expression) and assign > it to a symbol. I would then like to be able to operate on the > expression by, for instance: > 1 printing it > 2 printing it with some variables' values substitued into it > 3 and finally evaluating it > Hold and its variants do not do the job because they prevent > expression evaluation, but I need something that will keep its box > form exactly as I have typed it. > Please, how does one do this? > A method for doing this is very useful to me because my professors > like to see the variables substitued into the original (not > Mathematica reparsed original, but verbatim original) equations. Have a look at the Utilities`Notation` package. This should do what you want (and a whole lot more). Evaluate FrontEndExecute[ FrontEnd`HelpBrowserLookup[DemosLink, Notation Package]] for more information. 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) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: holding boxes verbatim > As a follow up to those who requested clairification: > Consider the simple examples: > HoldAllComplete[b*(a + s*m)] (*notice the order of the vairables > inside the inner Times is rearranged on output*) > HoldAllComplete[(x)^(1/2)] (*notice the reformatting of an expression > to the power 1/2 is reformatted to the square root of the expression*) > HoldAllComplete[(x/y)(h/g)] (*notice the elimination of the parenthesis*) > The reason these things happen is that the boxes are parsed into > Mathematica input such as Times[b,Plus[a,Times[s,m]]]. > I need a way to work directly with the boxes, but still at least do > some variable substitution. Some of your concerns are alleviated by using OutputForm[HoldForm[ ... ]]. At least in your examples, the only differences between the input and the output are the absence of * and unnecessary parentheses. Carl Woll === Subject: Re: holding boxes verbatim As a follow up to those who requested clairification: Consider the simple examples: HoldAllComplete[b*(a + s*m)] (*notice the order of the vairables inside the inner Times is rearranged on output*) HoldAllComplete[(x)^(1/2)] (*notice the reformatting of an expression to the power 1/2 is reformatted to the square root of the expression*) HoldAllComplete[(x/y)(h/g)] (*notice the elimination of the parenthesis*) The reason these things happen is that the boxes are parsed into Mathematica input such as Times[b,Plus[a,Times[s,m]]]. I need a way to work directly with the boxes, but still at least do some variable substitution. > Mathematica is annoying me. I would like some way to type in a two > dimensional box form (representing an arbitrary expression) and assign > it to a symbol. I would then like to be able to operate on the > expression by, for instance: > 1 printing it > 2 printing it with some variables' values substitued into it > 3 and finally evaluating it > Hold and its variants do not do the job because they prevent > expression evaluation, but I need something that will keep its box > form exactly as I have typed it. > Please, how does one do this? > A method for doing this is very useful to me because my professors > like to see the variables substitued into the original (not > Mathematica reparsed original, but verbatim original) equations. > An example of the desired behavior would be helpful. At any rate, have you > tried using HoldForm? For example: > expr = HoldForm[2^(x+1)]; > expr > expr /. x->2 > ReleaseHold[ expr /. x->2 ] > x + 1 > 2 + 1 > I used InputForm instead of a 2D box form for expr for legibility, but using > a 2D box form for expr won't cause any problems. > If the above is not helpful, please give an example of the behavior you > desire. > Carl Woll -- Chris Chiasson Kettering University Mechanical Engineering Graduate Student 1 810 265 3161 === Subject: Re: holding boxes verbatim It sounds to as if the Notation package could be used to solve your problem. Have a look at Notation Package in Master Index area of the the Help browser. Steve Luttrell > Mathematica is annoying me. I would like some way to type in a two > dimensional box form (representing an arbitrary expression) and assign > it to a symbol. I would then like to be able to operate on the > expression by, for instance: > 1 printing it > 2 printing it with some variables' values substitued into it > 3 and finally evaluating it > Hold and its variants do not do the job because they prevent > expression evaluation, but I need something that will keep its box > form exactly as I have typed it. > Please, how does one do this? > A method for doing this is very useful to me because my professors > like to see the variables substitued into the original (not > Mathematica reparsed original, but verbatim original) equations. > -- > Chris Chiasson > Kettering University > Mechanical Engineering > Graduate Student > 1 810 265 3161 === Subject: Re: holding boxes verbatim Chris, try this combination (In a notebook you will get the 2-D box form, which you can then print) HoldForm[Integrate[x^n, x]] Out[78]=HoldForm[Integrate[x^n, x]] HoldForm[Integrate[x^n, x]] /. n -> 2 Out[79]=HoldForm[Integrate[x^2, x]] ReleaseHold[HoldForm[Integrate[x^n, x]] /. n -> 2] Out[81]=x^3/3 Brian === Subject: Re: holding boxes verbatim > Mathematica is annoying me. I would like some way to type in a two > dimensional box form (representing an arbitrary expression) and assign > it to a symbol. I would then like to be able to operate on the > expression by, for instance: > 1 printing it > 2 printing it with some variables' values substitued into it > 3 and finally evaluating it > Hold and its variants do not do the job because they prevent > expression evaluation, but I need something that will keep its box > form exactly as I have typed it. > Please, how does one do this? > A method for doing this is very useful to me because my professors > like to see the variables substitued into the original (not > Mathematica reparsed original, but verbatim original) equations. An example of the desired behavior would be helpful. At any rate, have you tried using HoldForm? For example: expr = HoldForm[2^(x+1)]; expr expr /. x->2 ReleaseHold[ expr /. x->2 ] x + 1 2 2 + 1 2 8 I used InputForm instead of a 2D box form for expr for legibility, but using a 2D box form for expr won't cause any problems. If the above is not helpful, please give an example of the behavior you desire. Carl Woll === Subject: Re: holding boxes verbatim Hi Chris, I do not fully understand your question, but if it is only the evaluation that bugs you, see below: > Mathematica is annoying me. I would like some way to type in a two > dimensional box form (representing an arbitrary expression) and assign > it to a symbol. I would then like to be able to operate on the > expression by, for instance: > 1 printing it > 2 printing it with some variables' values substitued into it > 3 and finally evaluating it > Hold and its variants do not do the job because they prevent > expression evaluation, but I need something that will keep its box > form exactly as I have typed it. if you say: ReleaseHold[ expr ] expr will be evaluated even if it contains Hold. > Please, how does one do this? > A method for doing this is very useful to me because my professors > like to see the variables substitued into the original (not > Mathematica reparsed original, but verbatim original) equations. === Subject: Re: match 1, replace 2 > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, -1]? Here is one solution: {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} /. {a__, b_Integer} :> Join[Flatten[({# + 100, -1} & ) /@ {a}], {b}] 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) 35 Stirling Highway Crawley WA 6009 mailto:paul@physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul === Subject: Re: match 1, replace 2 Trevor, No doubt you will see many solutions. Here there are two of them. This one works for any list of lists: With[{z = Last /@ ls}, MapThread[Append[#1, #2] & , {Replace[Most /@ ls, n_ :> Sequence[100 + n, -1], {2}], z}]] And here is one for a list of lists of integers: ls /. n_Integer :> Sequence[ 100 + n, -1] /. {a___, b_, c_Integer} :> {a, b + c - 99} Fred Simons Eindhoven University of Technology ----- Original Message ----- === Subject: match 1, replace 2 > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. === Subject: Re: match 1, replace 2 > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, > -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. In[1]:= ls = {{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}} Out[1]= {{1}, {2, 3}, {4, 5, 6}, {7, 8, 9, 10}} In[4]:= Table[Flatten[ (If[IntegerQ[#1] && #1 =!= Last[ls[[i]]], {Sequence[#1 + 100], -1}, #1] & ) /@ ls[[i]]], {i, 1, Length[ls]}] Out[4]= {{1}, {102, -1, 3}, {104, -1, 105, -1, 6}, {107, -1, 108, -1, 109, -1, 10}} J.87nos ---------------------------------------------- Trying to argue with a politician is like lifting up the head of a corpse. (S. Lem: His Master Voice) === Subject: Re: match 1, replace 2 Hi Trevor, it can be done, but the rule is pretty complex: {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} /. {y : (_Integer ..), z_Integer} :> {Sequence @@ (Sequence @@ {100 + #, -1} & /@ List[y]), z} May be a solution with an intermediate step is more straightforward here (and simplier to understand): t = ls /. x_Integer :> {100 + x, -1} t /. {x : ({_, _} ..), y : {_, _}} :> {x, First[y] - 100} > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. === Subject: Re: match 1, replace 2 > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. Mapping this function Function[l, MapIndexed[If[First[#2] < Length[ l], Sequence @@ {100 + #1, -1}, #1] &, l]] onto your list will do it: Function[l,MapIndexed[ If[First[#2] Flatten[{ ReplaceList[(Drop[x, -1] + 100), {___, y_Integer, ___} -> { y, -1}], Take[x, -1]}]] {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} Brian > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. === Subject: Re: match 1, replace 2 > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. Here is one possibility. n=101; ls /. {a__Integer, b_Integer} :> Append[{a} /. c_Integer:>Sequence[n++,-1], n++; b] {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} Carl Woll === Subject: Re: match 1, replace 2 > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. In[1]:= ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}, {0}}; In[2]:= ls /. {f___Integer, g_Integer} :> Append[Apply[Sequence, ({100 + #1, -1} & ) /@ {f}, {1}], g] Out[2]= {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}, {0}} -- Peter Pein Berlin === Subject: Re: match 1, replace 2 > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? Mh, Without thinking too much, I would write: In[16]:= L={{1,2,3},{4,5},{6,7,8,9}}; Append[Drop[#,-1]/.{x_Integer->Sequence[x+100,-1]},Last[#]]&/@ L Out[17]= {{101,-1,102,-1,3},{104,-1,5},{106,-1,107,-1,108,-1,9}} Of course there should be a more elegant way for this. === Subject: Re: match 1, replace 2 ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}}; ls /. {a__Integer, b_Integer} :> {Sequence @@ Flatten[{100 + #, -1} & /@ {a}], b} ??? Jens Trevor Baca schrieb im > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, > {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each > list and then replaces > each matched integer n with the 2-element > sequence Sequence[100 + n, > -1]? > trevor. === Subject: Re: match 1, replace 2 I would use functional programming rather then pattern matching (rules) Define a function f as the following f[l_List] := Flatten[{Map[{100 + #, -1} &, Most[l]], Last[l]}] and then Map[] it over ls Map[f,ls] and get {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, 9}} as you needed yehuda > hi mathgroup, > what rule takes > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > to > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > trevor. === Subject: Re: How can I get a nonscalar logical variable into a compiled function? Hi All, the trouble seems to be that only numerical arrays are allowed inside a compiled function. The Mathematica book, chapter 2.6.15 gives a hint: Compile nevertheless also allows integers, complex numbers and logical variables (True or False), as well as arrays of numbers. > Hi Ben, > as arrays of boolean may not be fed to a compile function, you could > simply represent True/False by 0/1 for the Input/Output of your > function. Inside the functio, you may either choose to convert to > True/False or you can proceed with 0/1, whatever suits you better. >>I can't seem to figure out how to get a nonscalar logical variable into >>a compiled function. >>I can get a nonscalar variable of other kinds into compiled function or >>a scalar True or False into a compiled function. >>For example the following two things work: >>fun1=Compile[{{x,_Real,2}} >>Print[x]; >>]; >>fun2=Compile[{{x,True|False}} >>Print[x]; >>]; >>but how can I specify a two-dimensional input variable into the second >>case? >>fun2=Compile[{{x,True|False,1}} >>Print[x]; >>]; >>doesn't work. It returns: >>gg = {False, True, True, True, True, True, True} >>fun2[gg] >>CompiledFunction::cfsa: Argument {False, True, True, True, True, True, >>True} >>at position 1 should be a True or False. >>Can only scalar logical variables be input into compiled functions? Am >>I missing something? >>Ben === Subject: Re: Bug in JavaBlock (or in JavaBlock documentation) There are two semicolons missing from your test - which should read: Scan[ReleaseJavaObject, PeekObjects[]]; JavaBlock[JavaNew[javax.swing.JProgressBar];]; PeekObjects[] As written the JavaBlock was returning the Java object as its result - so it could not be garbage collected. Certainly, the problem goes away if you stop this happening. David Bailey dbaileyconsultancy.co.uk === Subject: Re: Bug in JavaBlock (or in JavaBlock documentation) >I think this is a bug in JavaBlock, but it could merely be a mistake in >the documentation. >The docs for JavaBlock state: JavaBlock[expr] causes all new Java >objects returned to Mathematica during >the evaluation of expr to be released when expr finishes. However, if >you evaluate the following: >Scan[ReleaseJavaObject,PeekObjects[]]; >JavaBlock[ > JavaNew[javax.swing.JProgressBar] > ] >PeekObjects[] >You'll see that the list of objects returned by PeekObjects[] contains >exactly one object - the JProgressBar created by the one call to >JavaNew, in which case it's not true that all new Java objects >returned to Mathematica during the evaluation of expr [are] released >when expr finishes. >FWIW, I'd prefer JavaBlock behave the way it's described in the docs, >since then one doesn't have to worry about the odd exception generated >by having expr return a Java object instead of some other value. Jason, As you have discovered, if a JavaBlock returns a single JavaObject, then this object will not be released by the JavaBlock. This feature was added to J/Link after the 1.0 release specifically because it is so convenient. A relatively common idiom in J/Link programming involves writing a block of code that will result in the production of one object you want to return from the block and a lot of temporary objects that should be discarded. This is similar to Module or Block in Mathematica, which return one useful expression and make assignments to temporary local variables along the way. JavaBlock is made more convenient by having this escape hatch for its return value. In other words, yes it is an exception, but a useful one. It's not likely to trip up programmers unaware of the behavior, because why would you write a JavaBlock that deliberately returns a JavaObject if you didn't want the object to exist outside the block? This feature is discussed in the section on JavaBlock in the J/Link User Guide. It was left out of the usage message in interest of keeping it short and as clear as possible. Based on this suggestion, however, I have added a sentence to the message. Todd Gayley Wolfram Research === Subject: Re: Exact Symbolic Notation You need to use the Notation package (Utilities`Notation`) - this allows you to define notations for use in Mathematica. Hywel > -----Original Message----- === > Subject: Exact Symbolic Notation > It is a pleasure talk to you all again. > My plain question is: > I want to use some exact notation with Mathematica. For instance, > I want to use variables like p' instead of pline (or > something like that). > Also I want to use P2 (with the 2 underlined). The last > option works in some > calculations but not in all of them (Why?). > Finally I want to define f1[x] as a function with the 1 > underlined(Why > is not working?). > Any enlightment on these subject are very welcome. > Alex === Attila === Subject: Re: Re: Integrate is driving me crazy, please help! > I think you are misunderstanding functions in Mathematica. They are > called via FunctionName[arguments] (note the square brackets!) Several people have pointed this out, but actually, Jim's code is valid TraditionalForm input (except that pi should be Pi). That wouldn't explain the output he got, of course. Bobby >> Integrate[(hillb*((f0 + hilla)/(2*pi*f*a*Cos(ArcSin(x/a)) + hillb))) - >> hilla, {x, -a, a}] > I think you are misunderstanding functions in Mathematica. They are > called via FunctionName[arguments] (note the square brackets!) By > convention all built-in functions are capitalised (e.g. Cos[x]) and > user-defined ones are generally in lowercase. >> Mathematica returns this: >> (-4 a ArcSin Cos f hilla pi + (f0 + hilla) hillb (-Log[hillb - 2 a >> ArcSin Cos f pi] + Log[hillb + 2 a ArcSin Cos f pi]))/(4 a ArcSin >> Cos f pi) > Here you can see that Mathematica treated Arcsin and Cos (note your > incorrect use of round brackets) as variables(!). > If you have enough time it might be worth taking an hour to go through > the built-in basic tutorial in the included help file. > Mischa -- DrBob@bigfoot.com === > My end goal is to get that >solution written into a spreadsheet but I have my doubts about any >spreadsheet (excel or gnumeric) being able to handle the imaginary numbers. That's unfortunate, because a solution that seems not to suffer from some sort of discontinuity for positive values of the parameters is that involving the logartithm. For example this intF[a_, ha_, hb_, f_, f0_] := With[ {g = Sqrt[hb^2 - 4a^2 f^2 Pi^2]}, (f0 + ha) hb (1/(2 f) - hb/(2g f Pi)I Log[(2a f Pi - I g)/(2 a f Pi + I g)]) - 2a ha ] This is a real quantity, since the log a ratio of complex conjugate numbers is imaginary and so -I Log[(x+I y)/(x+I y)] happens to be real. -I Log[(x-I y)/(x+I y)] = = -I (Log[Abs[x-I y]/Abs[x+I y]] +I Arg[(x-I y)/(x+I y)]) = -I Log[1] + Arg[(x-I y)/(x+I y)] = 0 + Arg[(x-I y)/(x+I y)] = -2 Arg[x+I y] = -2 ArcTan[y/x] The problem is that Arg, ArcTan[] and ArcTan[.,.] are affected by different forms of discontinuity due to the modular world of angles (or the polidromy of Log, if you prefer). So some of the different equivalent forms that can be found by expressing log in some other form, are only valid modulo Pi or 2 Pi. Have a look at this graphics, for example funs = { Chop[(-I) Log[(x-I y)/(x+I y)]], Arg[(x-I y)/(x+I y)], ArcTan[(2 x y)/(y^2-x^2)], ArcTan[y^2-x^2, 2 x y], -2 ArcTan[y/x], - 2 ArcTan[x, y]}; Block[{$DisplayFunction = Identity}, plots = (Plot[Evaluate[#1 /. x -> 1], {y, -10, 10}, Frame -> True, PlotRange -> {-Pi, 2*Pi}, PlotLabel -> #1] & ) /@ funs ]; Show[GraphicsArray[Partition[plots, 3]]]; The following definition for your integral solution seems to do well for positive valued parameters, and it could be plotted in a spreadsheet with a well implemented arctanget function: intF[a_, ha_, hb_, f_, f0_] := With[ {g = Sqrt[hb^2 - 4a^2 f^2 Pi^2]}, (f0 + ha) hb (1/(2 f) - hb/(g f Pi) ArcTan[ g/( 2 a f Pi)]) - 2a ha ] Try to plot it into your spreadsheet to see if you experience some kind of discontinuity that should not be there. Something like this should come up: Plot[intF[a, 3, 50, 1, 8], {a, 0, 30}, Frame -> True] cheers, Peltio Invalid address in reply-to. Crafty demunging required to mail me. === Subject: Re: Integrate is driving me crazy, please help! I follow APC's comments, After correcting them you get (in InputForm) res=(-4*a^2*f*hilla*Pi*Sqrt[hillb^2 - 4*a^2*f^2*Pi^2] + a*f0*hillb*Pi*Sqrt[hillb^2 - 4*a^2*f^2*Pi^2] + a*hilla*hillb*Pi*Sqrt[hillb^2 - 4*a^2*f^2*Pi^2] + 2*a*(f0 + hilla)*hillb^2* ArcTan[(2*a*f*Pi)/Sqrt[hillb^2 - 4*a^2*f^2* Pi^2]] - I*Sqrt[a^2]*(f0 + hilla)*hillb^2* Log[-((I*Sqrt[a^2]*hillb)/ (2*a*Sqrt[hillb^2 - 4*a^2*f^2*Pi^2]))] + I*Sqrt[a^2]*f0*hillb^2*Log[(I*Sqrt[a^2]*hillb)/ (2*a*Sqrt[hillb^2 - 4*a^2*f^2*Pi^2])] + I*Sqrt[a^2]*hilla*hillb^2* Log[(I*Sqrt[a^2]*hillb)/ (2*a*Sqrt[hillb^2 - 4*a^2*f^2*Pi^2])])/ (2*a*f*Pi*Sqrt[hillb^2 - 4*a^2*f^2*Pi^2]) And then res/.{hilla -> 3, hillb -> 50, f0 -> 8, a -> 1, f -> 1}//N//Chop will give you 14.0372 First notice that you get a general closed form result, which is more efficient to use since you need to integrate (symbolically) only once. Then the numerical values are assigned and do not involve with the accuracy of the integration. Anyway, NIntegrate[] returns the same result yehuda > Hello Mathematica Experts: > I am a biomechanist and work mostly in the area of muscle contraction. I > do a lot of numerical computations using excel, but right now I need an > analytical solution that represents force as a function of position > integrated over a shortening amplitude. I downloaded a trial version of > Mathematica and have tried to obtain a solution for this: > Integrate[(hillb*((f0 + hilla)/(2*pi*f*a*Cos(ArcSin(x/a)) + hillb))) - > hilla, {x, -a, a}] > Mathematica returns this: > (-4 a ArcSin Cos f hilla pi + (f0 + hilla) hillb (-Log[hillb - 2 a > ArcSin Cos f pi] + Log[hillb + 2 a ArcSin Cos f pi]))/(4 a ArcSin > Cos f pi) > I know the line wrap makes this hard to read so please feel free to > email me and I can send you the output as a picture. > In a sample data set, hilla=3, hillb=50, f0=8, a=1, f=1 > I can numerically integrate this function and obtain a value for that > sample data set of 14.04. When I put those sample values into the > solution that Mathematica produces, I get 10.01. > Can any of you please give a hand here? I must be making some simple > Mathematica-beginner error but I just can't see it. > In Mathematica, Log is Log to base e, right (LN in excel)? Did I use > variables that have intrinsic functions in Mathematica? Maybe I am > misunderstanding the output with regard to implicit parentheses etc. > Any help appreciated! > Jim === Subject: Re: Integrate is driving me crazy, please help! > Integrate[(hillb*((f0 + hilla)/(2*pi*f*a*Cos(ArcSin(x/a)) + hillb))) - > hilla, {x, -a, a}] I think you are misunderstanding functions in Mathematica. They are called via FunctionName[arguments] (note the square brackets!) By convention all built-in functions are capitalised (e.g. Cos[x]) and user-defined ones are generally in lowercase. > Mathematica returns this: > (-4 a ArcSin Cos f hilla pi + (f0 + hilla) hillb (-Log[hillb - 2 a > ArcSin Cos f pi] + Log[hillb + 2 a ArcSin Cos f pi]))/(4 a ArcSin > Cos f pi) Here you can see that Mathematica treated Arcsin and Cos (note your incorrect use of round brackets) as variables(!). If you have enough time it might be worth taking an hour to go through the built-in basic tutorial in the included help file. Mischa === Subject: Re: Exact Symbolic Notation Alex, I have to weigh in on this, although I don't know if I'll be much help. You could try the Notations package that comes with Mathematica. This can be used to turn expressions into symbols. I find it rather difficult to use but it does work for some people. I think the Notations package (or the MakeExpression statement) would be necessary to underline only part of a symbol. Maybe someone in the group will show you how to do it. For subscripted symbols you could try the SubscriptSymbols package by Ted Ersek on MathSource. It uses ideas of Carl Woll and also manages the use of the Notations package to symbolize subscripted variables if you wish to go that far. In Mathematica p'[x] means the derivative of f with respect to the argument and p' // FullForm Derivative[1][p] I suppose one could get away with using that... Solve[p'y == 3x, p'] {{p' -> (3*x)/y}} but I suspect that difficulties lurk somewhere. I wouldn't use it. There is a prime character that can be entered as [Prime], or esc ' esc, so you could use p[Prime] but this displays with the prime sitting on the floor instead of being raised to it's normal position. I think this is a definite deficiency in Mathematica. Primed variables are very common in text books and in the mathematical literature. Mathematica has a prime character. Why doesn't WRI make it display correctly? I've complained about this a number of times but so far you are the only other Mathematica user I've come across who seems to want to use primed symbols! I also think Mathematica would be greatly enhanced if the palette characters, the Script, DoubleStruck and Gothic were better formed and somewhat larger than their present size. These used to be better in earlier versions of Mathematica and somewhere around Version 4 they got worse and not as usable. It would also be nice if they had an additional larger bold sans serif set of characters that could be used for vectors, matrices etc. Over the years I've learned that it is almost always possible to manipulate expressions to get them into textbook form, but the inadequate extended character sets are still a major problem. One that could be easily fixed. David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ It is a pleasure talk to you all again. My plain question is: I want to use some exact notation with Mathematica. For instance, I want to use variables like p' instead of pline (or something like that). Also I want to use P2 (with the 2 underlined). The last option works in some calculations but not in all of them (Why?). Finally I want to define f1[x] as a function with the 1 underlined(Why is not working?). Any enlightment on these subject are very welcome. Alex === Subject: Sort problem Hi How to sort two lists such as: age={30,12,60,20}; pple={john,kate,peter,alice}; to give the output: age={12,20,30,60} pple={kate,alice,john,peter} ie: to keep every person opposite his age number. === Subject: Re: plot on condition Something like the following will work: gr = If[#[[1]] == 3, {Red, #[[2]]}, {Blue, #[[2]]}] & /@ Thread[{cnd, Point /@ pnts}]} then Show[Graphics[{PointSize[0.1], gr ]] Mariusz hello my question about plotting a list of points but with some condition depends on the status of points in other list; pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; cnd={7,3,5,8,3}; the condition is: plot a point in list pnts in Blue if the corresponding element in list cnd is 3 else plot in Green === Subject: Re: plot on condition > hello > my question about plotting a list of points but with some condition depends on > the status of points in other list; > pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; > cnd={7,3,5,8,3}; > the condition is: plot a point in list pnts in Blue if the corresponding > element in list cnd is 3 else plot in Green Show[Graphics[Prepend[ Transpose[{cnd/.{3->Blue,c_Integer->Green},Point/@pnts}], PointSize[.02]]]] will do it. Prepend[..,PointSize[.02]] is of course not necessary. -- Peter Pein Berlin === Subject: Re: plot on condition As far as I know, ListPlot can only deal with one set of PlotStyles (one color) at a time. You can still use ListPlot to plot the axes, but you then plot the points again in a Epilog with the needed colors. E.g. ListPlot[pnts, Epilog -> {PointSize[0.05], MapThread[({If[#1 == 3, Blue, Red], Point[#2]}) &, {cnd, pnts} ]}] Sincerily, Daniel > hello > my question about plotting a list of points but with some condition depends on > the status of points in other list; > pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; > cnd={7,3,5,8,3}; > the condition is: plot a point in list pnts in Blue if the corresponding > element in list cnd is 3 else plot in Green === Subject: Re: plot on condition Steven, Try this pnts={{1,2},{5,4},{3,2},{2,6}, {5,3}}; cnd={7,3,5,8,3}; Show[Graphics[MapIndexed[If[ cnd[[First[#2]]] == 3, {Blue, AbsolutePointSize[6], Point[#1]}, {Green, AbsolutePointSize[6], Point[#1]}] &, pnts], {PlotRange -> Automatic, AspectRatio -> GoldenRatio^(-1), DisplayFunction :> $DisplayFunction, ColorOutput ->Automatic, Axes -> Automatic, AxesOrigin -> Automatic, PlotLabel -> None, AxesLabel -> None, Ticks -> Automatic}]] Brian === Subject: Re: plot on condition Graphics[ MapThread[ {If[3 == #2, RGBColor[0, 0, 1], RGBColor[0, 1, 0]], Point[#1]} &, {pnts, cnd} ], Frame -> True ] //Show ??? Jens schrieb im Newsbeitrag > hello > my question about plotting a list of points but > with some condition depends on > the status of points in other list; > pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; > cnd={7,3,5,8,3}; > the condition is: plot a point in list pnts in > Blue if the corresponding > element in list cnd is 3 else plot in Green === Subject: Re: plot on condition pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; cnd={7,3,5,8,3}; Show[Graphics@ {AbsolutePointSize@4, {If[#[[1]]==3,Blue,Green], Point@#[[2]]}&/@ Thread@{cnd,pnts}}, Frame->True, PlotRange->{{-0.15,5.15},{-0.15,6.15}}]; or Show[Graphics@ {AbsolutePointSize@4, Thread@{cnd/.{3->Blue,_?NumericQ->Green}, Point/@pnts}}, Frame->True, PlotRange->{{-0.15,5.15},{-0.15,6.15}}]; Bob Hanlon === > Subject: plot on condition > hello > my question about plotting a list of points but with some condition depends on > the status of points in other list; > pnts={{1,2},{5,4},{3,2},{2,6},{5,3}}; > cnd={7,3,5,8,3}; > the condition is: plot a point in list pnts in Blue if the corresponding > element in list cnd is 3 else plot in Green === Subject: Permutation Representations with Mathematica Please, would you tell me if there is a way to compute the permutation representation of a group with Mathematica? Simone === Subject: Re: (x-y) DiracDelta[x-y] does not simplify to 0 Hi Alain, you can try this: FullSimplify[(x - y) DiracDelta[x - y], ExcludedForms -> {x - y}] I think that the unvaluated answer is due to the use of the math. associative law of the expression. In fact, (a+b)*c would become a*c+b*c and so... the ExcludedForms option forces Math. to don't use the associative law, in this particular context. I hope can help you. ~Scout~ Alain Cochard ha scritto nel messaggio > Mathematica 4.0 for Linux > Copyright 1988-1999 Wolfram Research, Inc. > -- Motif graphics initialized -- > Considering that > In[1]:= FullSimplify[x DiracDelta[x]] > Out[1]= 0 > I was surprised about this one: > In[2]:= FullSimplify[(x-y) DiracDelta[x-y]] > Out[2]= (x - y) DiracDelta[x - y] > whereas: > In[3]:= FullSimplify[(x-y) DiracDelta[x-y]/.x-y->z] > Out[3]= 0 > Is it simply that Mathematica is a little weak on Out[2], or does it have a > good reason for not simplifying, i.e., am I missing something at the > mathematics level? > Alain === Subject: Re: (x-y) DiracDelta[x-y] does not simplify to 0 Alain, may I add the strangest case I found up to now: case wh01 In[3]:=Simplify[(x - y)*DiracDelta[x - y], {x, y}] Out[3]=0 But also these are strange enough case wh02 In[7]:=Simplify[(x - y)*DiracDelta[x - y], {x && y}] Out[7]=0 case wh03 In[13]:=Simplify[(x - y)*DiracDelta[x - y], {x || y}] Out[13]=(x - y)*DiracDelta[x - y] case wh04 In[29]:=Simplify[I*x*DiracDelta[I*x]] Out[29]=0 But case wh05 In[30]:=Simplify[I*DiracDelta[I]] Out[30]=I*DiracDelta[I] Can't explain ... Wolfgang > Mathematica 4.0 for Linux > Copyright 1988-1999 Wolfram Research, Inc. > -- Motif graphics initialized -- > Considering that > In[1]:= FullSimplify[x DiracDelta[x]] > Out[1]= 0 > I was surprised about this one: > In[2]:= FullSimplify[(x-y) DiracDelta[x-y]] > Out[2]= (x - y) DiracDelta[x - y] > whereas: > In[3]:= FullSimplify[(x-y) DiracDelta[x-y]/.x-y->z] > Out[3]= 0 > Is it simply that Mathematica is a little weak on Out[2], or does it have a > good reason for not simplifying, i.e., am I missing something at the > mathematics level? > Alain === Subject: Re: (x-y) DiracDelta[x-y] does not simplify to 0 > Alain, > may I add the strangest case I found up to now: > case wh01 > In[3]:=Simplify[(x - y)*DiracDelta[x - y], {x, y}] > Out[3]=0 > But also these are strange enough > case wh02 > In[7]:=Simplify[(x - y)*DiracDelta[x - y], {x && y}] > Out[7]=0 > case wh03 > In[13]:=Simplify[(x - y)*DiracDelta[x - y], {x || y}] > Out[13]=(x - y)*DiracDelta[x - y] > case wh04 > In[29]:=Simplify[I*x*DiracDelta[I*x]] > Out[29]=0 > But > case wh05 > In[30]:=Simplify[I*DiracDelta[I]] > Out[30]=I*DiracDelta[I] > Can't explain ... > Wolfgang >>Mathematica 4.0 for Linux >>Copyright 1988-1999 Wolfram Research, Inc. >> -- Motif graphics initialized -- >>Considering that >> In[1]:= FullSimplify[x DiracDelta[x]] >> Out[1]= 0 >>I was surprised about this one: >> In[2]:= FullSimplify[(x-y) DiracDelta[x-y]] >> Out[2]= (x - y) DiracDelta[x - y] >>whereas: >> In[3]:= FullSimplify[(x-y) DiracDelta[x-y]/.x-y->z] >> Out[3]= 0 >>Is it simply that Mathematica is a little weak on Out[2], or does it have a >>good reason for not simplifying, i.e., am I missing something at the >>mathematics level? >>Alain FullSimplify[expr,lst] simplifies expr assuming all element of lst being True: In[1]:= FullSimplify[{a, b, c}, {a, c}] Out[1]= {True, b, True} and (True - True) evaluates to 0 (strange, isn't it? IMHO this shouldn't) eval to anything other than $Failed) -- Peter Pein Berlin === Subject: Re: (x-y) DiracDelta[x-y] does not simplify to 0 > As I remember, DiracDelta is singular and has a meaning only under > integration. Anyway the properties of the DiracDelta are kept by > Mathematica i.e., Integrate[(x - y)DiracDelta[x - y], {x, -1, 1}, > {y, -1, 1}] returns 0 as expected > On the one hand I think the Mathematica implementation of DiracDelta > (and KroneckerDelta) leaves a lot to be desired... and that is putting > it mildly. (That means I have plenty of much worse examples...). > On the other hand, I am not convinced that Mathematica ought to perform > this sort of simplification at all. DiracDelta is a generalised > function. The statement x DiracDelta[x] == 0 needs a lot of > interpreting to make sense of (I prefer to think of it as nonsense). > However > Integrate[(x-y) DiracDelta[x-y], {x,-Infinity,Infinity}] > 0 > is correct. I don't understand these reservations. I learned the statement x delta = 0 in my lectures on distributions at university, and I checked today that it also appears in one of Laurent Schwartz's (father of distribution theory) books. Plus I find it very intuitive and it's straightforward to demonstrate. But anyway, I find in your responses the answer to my initial questions, and I thank you for your time. AC === Subject: Re: (x-y) DiracDelta[x-y] does not simplify to 0 > Alain, > may I add the strangest case I found up to now: > case wh01 > In[3]:=Simplify[(x - y)*DiracDelta[x - y], {x, y}] > Out[3]=0 > But also these are strange enough > case wh02 > In[7]:=Simplify[(x - y)*DiracDelta[x - y], {x && y}] > Out[7]=0 > case wh03 > In[13]:=Simplify[(x - y)*DiracDelta[x - y], {x || y}] > Out[13]=(x - y)*DiracDelta[x - y] > case wh04 > In[29]:=Simplify[I*x*DiracDelta[I*x]] > Out[29]=0 > But > case wh05 > In[30]:=Simplify[I*DiracDelta[I]] > Out[30]=I*DiracDelta[I] > Can't explain ... > Wolfgang I have not much experience with delta functions with complex numbers, so I don't have an opinion on wh04 and wh05, but I indeed find wh01->03 funny. Hope some will tell us what's going on. Alain === Subject: Re: (x-y) DiracDelta[x-y] does not simplify to 0 I was even more surprised by this: In[3]:= Simplify[(x - y)*DiracDelta[x - y], {x, y}] Out[3]=0 As I don't know what {x,y} means here. I found it by playing around with the more meaningful {x>y},{x Mathematica 4.0 for Linux > Copyright 1988-1999 Wolfram Research, Inc. > -- Motif graphics initialized -- > Considering that > In[1]:= FullSimplify[x DiracDelta[x]] > Out[1]= 0 > I was surprised about this one: > In[2]:= FullSimplify[(x-y) DiracDelta[x-y]] > Out[2]= (x - y) DiracDelta[x - y] > whereas: > In[3]:= FullSimplify[(x-y) DiracDelta[x-y]/.x-y->z] > Out[3]= 0 > Is it simply that Mathematica is a little weak on Out[2], or does it have a > good reason for not simplifying, i.e., am I missing something at the > mathematics level? > Alain === Subject: multiple 3d plots how can i plot the following 2 3D-graphs into one graph so that i can see where they intersect. Plot3D[3*x^2*y , {x, 1, 2}, {y, 1, 2}]; Plot3D[3*x^2*y , {x, 1, 2}, {y, 1, 2}]; Plot3D[{3*x^2*y,3*x^2*y},{x,1,2},{y,1,2}] would be nice but doesn't work, since the second argument if for coloring the first. Is there an easy solution? best juergen === Subject: Re: multiple 3d plots okay, this seems to do the trick. but the show command doesn't use the color i specified for graph p2. any, idea? p1 = Plot3D[x^2*y, {x, 1, 2}, {y, 1, 2}]; p2 = Plot3D[{3*x*(1/y),Hue[.4]}, {x, 1, 2}, {y, 1, 2}]; Show[p1, p2]; === Subject: removing sublist . Again and Different >i'm a newbie. How implement the _faster functon_ which removes in a >list every element that are a subelement. >which means >f[x]:= {..,{1,2,3,4},..,{2,3},..} removes {2,3}. >thanx a lot. >giorgio borghi i ask your help for faster way to do the opposite f[x]:= {..,{1,2,3,4},..,{2,3},..} removes {1,2,3,4}. giampiero === Subject: a conflicting StringReplace I was teaching Mathematica in a college. In the class I was showing them some built-in functions about strings. Since this is not a very important issue, I didn't spend much time on each function. When I show them StringReplace, I gave them the following examples: In[1] StringReplace[abc,{ab->AB}] Out[1] ABc In[2] StringReplace[abc, {bc->BC}] Out[2] aBC No problem on those. Now a student tried the following: In[3] StringReplace[abc, {ab->AB, bc->BC}] Out[3] ABc Now he asked me why only ab is replaced. I said this is because there is a conflict because both ab and bc contains b. So Mathematica will choose the first replacement. I also told him if he changes the order, he will get aBC. Now: In[4] StringReplace[abc, {bc->BC,ab->AB}] Out[4] ABc This is the part I don't understand. Does Mathematica treat those rules in their canonical order (since ab is before bc in canonical order.), or in their written order? Hui Fang