A62 ==== Subject: Re: ListInterpolation Hi St.8ephane, what you have in mind is LINEAR interpolation. This can be done giving the option InterpolationOrder ->1. Then you get 5/3. However, if the interpolation order is higher, points farther away will have an effect. To guard against unexpected surprises, it is generally safe to use a low interpolation order. sincerely, Daniel res = ListInterpolation[ > Transpose[{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10 , 11 , 12}}], > {{1, 1.3, 2, 5}, {0, 1.5, 2}}]; I get res[1, 0.5] = 1. whereas for me the correct answer would be res[1, 0.5] = 5/3 since {1, 1.3, 2, 5} is the x coordinate of the data table {{1, 2, 3, > 4}, {5, 6, 7, 8}, {9, 10 , 11 , 12}} and {0, 1.5, 2} the y > coordinates. Where does I make a mistake? >I have a problem with the ListInterpolation instruction. I would like >to specify some explicit lists of positions for grid lines like this: res == ListInterpolation[{{1, 2, 3, 4}, {5, 6, 7, 8}}, {{1, 1.3, 2. 5, >5}, {0.5, 1.3}}] But it does not work: when I try to calculate res[2, 1.1], I get >ListInterpolation[{{1, 2, 3, 4}, {5, 6, 7, 8}}, {{1, 1.3, 2.5, 5}, >{0.5, 1.3}}][2, 1.1] I thank you in advance for your help. Yours sincerely Stephane Fay > Paris Observatory > France >Your input is not in proper format (and use = for assignments, not ==): >>In[1]:= res = ListInterpolation[ >> Transpose[{{1, 2, 3, 4}, {5, 6, 7, 8}}], >> {{1, 1.3, 2.5, 5}, {0.5, 1.3}}]; >>ListInterpolation::inhr: >>Requested order is too high; order has been reduced to {3, 1}. More... >>In[2]:= res[2, 1.1] >>Out[2]= >> 6.031081081081081 >>-- >>Peter Pein >>Berlin >> ==== Subject: Re: ListInterpolation res = ListInterpolation[ > Transpose[{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10 , 11 , 12}}], > {{1, 1.3, 2, 5}, {0, 1.5, 2}}]; I get res[1, 0.5] = 1. whereas for me the correct answer would be res[1, 0.5] = 5/3 since {1, 1.3, 2, 5} is the x coordinate of the data table {{1, 2, 3, > 4}, {5, 6, 7, 8}, {9, 10 , 11 , 12}} and {0, 1.5, 2} the y > coordinates. Where does I make a mistake? >I have a problem with the ListInterpolation instruction. I would like >to specify some explicit lists of positions for grid lines like this: res == ListInterpolation[{{1, 2, 3, 4}, {5, 6, 7, 8}}, {{1, 1.3, 2= =2E 5, >5}, {0.5, 1.3}}] But it does not work: when I try to calculate res[2, 1.1], I get >ListInterpolation[{{1, 2, 3, 4}, {5, 6, 7, 8}}, {{1, 1.3, 2.5, 5}, >{0.5, 1.3}}][2, 1.1] I thank you in advance for your help. Yours sincerely Stephane Fay > Paris Observatory > France >Your input is not in proper format (and use = for assignments, not = ==): >>In[1]:= res = ListInterpolation[ >> Transpose[{{1, 2, 3, 4}, {5, 6, 7, 8}}], >> {{1, 1.3, 2.5, 5}, {0.5, 1.3}}]; >>ListInterpolation::inhr: >>Requested order is too high; order has been reduced to {3, 1}. More... >>In[2]:= res[2, 1.1] >>Out[2]= >> 6.031081081081081 >>-- >>Peter Pein >>Berlin > > we've got four x-grids and three y-grids. A polynomial interpolation involves at most x^3 and y^2: data = Flatten /@ Transpose[(Flatten[#1, 1] & ) /@ {Outer[List, {1, 1.3, 2, 5}(*x - values*), {0, 1.5, 2}(*y - values*)], Transpose[{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}] (*z - values*)}] Out[1]= {{1, 0, 1}, {1, 1.5, 5}, {1, 2, 9}, {1.3, 0, 2}, {1.3, 1.5, 6}, {1.3, 2, 10}, {2, 0, 3}, {2, 1.5, 7}, {2, 2, 11}, {5, 0, 4}, {5, 1.5, 8}, {5, 2, 12}} In[2]:= fun[x_, y_] = Evaluate[Rationalize[ Fit[data, {1, x, y, x^2, y^2, x^3}, {x, y}]]] Out[2]= -(3033/518) + (31351*x)/3108 - (3765*x^2)/1036 + (625*x^3)/1554 - (4*y)/3 + (8*y^2)/3 In[3]:= fun[1, 1/2] Out[3]= 1 If you want to use an non-polynomial model, Fit[] or Statistics`NonLinearFit[] would be the choice. -- ==== Subject: Re: a question about the UnitStep function f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; integrand=f[z] f[x-z]; A workaround is to use finite but large limits on the integral g[x_]=Assuming[Element[x,Reals], Integrate[integrand,{z,-10,10}]] (1/4)*((-(x + 2))*UnitStep[-x - 2] - (x - 2)*UnitStep[2 - x] + 2*x*UnitStep[-x]) g[x]//Simplify Piecewise[{{(2 - x)/4, Inequality[0, Less, x, LessEqual, 2]}, {(x + 2)/4, Inequality[-2, Less, x, LessEqual, 0]}}] Plot[g[x],{x,-4,4},PlotRange->All]; Bob Hanlon > ==== > Subject: a question about the UnitStep function > I want to let Mathematica compute the convolution of two sqare waves. I did as follows > > f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; > > integrand=f[z] f[x-z]; > > Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, Infinity}]] > > Mathematica gave me the result as follows, > ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 > > I plot the result to check > > Plot[%,{x,-10,10}, PlotRange->All]; > > It is clear wrong since the convolution of two square waves should be convergent. Can anyone give me some help with the subtlties about the UnitStep function? Any thoughts are appriciable. > ==== Subject: Re: $Version 5.1 for Mac OS X (January 27, 2005) N[Root[-2*#1^3 + 2*#1^4 - #1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] - 6*#1^2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] + 6*#1^3*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] - 5*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] ^2 - 6*#1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^2 + 6*#1^2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^2 - 2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] ^3 + 2*#1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^3 & , 2]] 1.11221 Bob Hanlon > ==== > Subject: Here is the code: !((Root[(-2) #1^3 + 2 #1^4 - #1 Root[(-4) - 3 #1 + 66 > #1^2 + > 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] - 6 #1^2 > Root[(-4) - > 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, > 1] + 6 #1^3 Root[(-4) - 3 #1 + > 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] - 5 > Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 > &, > 1]^2 - 6 #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1 ^4 > + > 216 #1^5 &, 1]^2 + 6 #1^2 Root[(-4) - 3 #1 + > 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, > 1]^2 - 2 Root[(-4) - > 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 > &, 1] > ^3 + 2 #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + > 216 > #1^5 &, 1]^3 &, 2];)) I would guess it is a number. I applied RootReduce, ToRadicals, N or > combinations of thereof, however, nothing seem to convert the above > expression into an explicit number. What command or sequence of Mukhtar Bekkali ==== Subject: how to find n in expression x^n using a pattern? I am learning patterns in Mathemtica, and I thought this will be easy. suppose you are given a factored expression, such as x^n(x^2+2)(x^3+4) where 'n' above can be any number, including zero (i.e. there is no (x) as a separate factor). I need to find 'n', which can be 0,1,2,3,..etc.. i.e I need to find the power of the factor x by itself if it exist in the expression. not (x^n+anything), just (x^n) byitself. For example p= x (x^2+2) ---> here n=1 I tried this p /. x^n_(any_) -> n This did not work since x^1 does not match pattern x^n_. I would have worked if I had x^2 (x^3+2) for example. I know that I need to use something like x^_:1 to make it match x, which is really x^1, but I do not know how to use it in a replacement rule, becuase when I write p /. (x^n_:1)(any_) -> n it is an error. If I write p /. (x^_:1)(any_) -> _ I do not get back anything. Next I tried the Cases command, and again had no luck. The main problem is that Mathematica makes a difference between x, x^1, and x^2, etc... when it comes to matching with pattern x^n_ any idea how to do this? steve ==== Subject: Re: Can't assign value to symbols Clear[a,b,c]; Thread[First[parameters]==Rest[parameters]]/.Equal:>Set; {a,b,c} {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Bob Hanlon > ==== > Subject: Can't assign value to symbols > Situation: I have a table that contains parameters and sets of values > that I want to assign to the parameters for the purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] > - fails with error Tag Slot in #1 is Protected > - tried adding Unprotect[#1] and a variety of other attemps, but can't > get it to work. Anyone know how might accomplish this? Lee > ==== Subject: Re: Sudoku puzzle A short solution, which I placed on Mathsource last week, applies two > basic rules before resorting to backtracking. The rules are sufficient > to find the 1 at {5,5} in this example. http://library.wolfram.com/infocenter/MathSource/5690/ Very nice. One thing that would make it more visual is to have an option > Showing the solution a step at a time would be particularly useful if > you are solving the puzzle by hand, get stuck, and want a hint. I agree. I added the ShowSteps option as something of an afterthought. By that point I had already made a logical mistake. The rules I had implemented consider each row, column and subgrid in isolation. I hadn't read any literature on Sudoku and this was the way that I thought I had solved a problem by hand. As such the row function did not need to know which row it was being applied to, I just used Map to apply it to all of them. Only the backtracking code knows where it is working and can report useful progress data. At some point I will go back and change this and implement the other logic referred to in the notebook. > Since there are many people out there solving Sudoku puzzles, perhaps a > webMathematica page using your solver would be a nice hook for > webMathematica and Mathematica? I dropped a very rough webMathematica version of it on http://members.wolfram.com/webMathematica/Users/jonm/sudoku.jsp (No error checking and not very pretty). Perhaps if/when I have improved the solver, I will clean this up. ==== Subject: Re: Re: Weird behavior of SparseArray But here is what I get using the same input: In[218]:= cp1=SparseArray[{i_,j_}[Rule]0,{4,2}]; cp1[[Range[4],1]]=cp1[[Range[4],1]]+{1,1,1,1}; Normal[cp1] $Version Out[220]= {{0,0},{0,0},{0,0},{0,0}} Out[221]= !!!!!!!!!!!!!!!!!!!!!!!!!!!!! I don't understand what is going on with SparseArray If I write this: cp1 = SparseArray[{i_, j_} -> 0, {4, 2}]; >cp1[[Range[4], 1]] = cp1[[Range[4], 1]] + {1, 1, 1, 1}; >cp1 // MatrixForm I get cp1 with all entries equal to zero That's not what I see. I see In[6]:= > cp1 = SparseArray[{i_, j_} -> 0, {4, 2}]; > cp1[[Range[4],1]] = cp1[[Range[4],1]] + {1, 1, 1, 1}; > Normal[cp1] > $Version Out[8]= > {{1, 0}, {1, 0}, {1, 0}, {1, 0}} > Out[9]= > 5.1 for Mac OS X (January 27, 2005) as I would expect > -- > To reply via email subtract one hundred and four -- Adel ==== Subject: converting exact numbers to binary fixed-point representation Hi group, what I want to achieve is to represent the exact value of an irrational number, say Sin[2*Pi*131/8191], as a binary fixed-point number having 16 fractional (plus one sign bit) bits. First, I thought of converting to floating-point value and then converting to fixed-point using: Floor[N[Sin[2*Pi*(131/8191)]]*2^16] Now I'm worried about the precision of this conversion. The piece of code above truncates all fractional bits that occur after the left shift operation. The following two intermediate results (I changed to 4 bits for simplicity here) 1101,000...1 and 1100,111...1 will end up in two different code words 1101 and 1100, respectively. Though both values might be equally close to the exact value, the second would give the wrong solution. So how can I ensure, that *rounding* the exact value to a floating-point number will never lead to such a case, that eventually spoils my 16 bit representation? Is there a standard way to solve this problem? Is this a problem at all or am I worried too much? Any explanation is welcome. Torsten ==== this group and I am very grateful for all your help. Daniel (dh), i really was was looking for roots, not for expansion coefficients. Sorry, maybe my english is a little awful ... greets! Francisco Bellas Curro ==== Subject: Re: Mukhtar, N worked for me with Version 5.1.1. expr = Root[-2*#1^3 + 2*#1^4 - #1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] - 6*#1^2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] + 6*#1^3*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] - 5*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^2 - 6*#1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^2 + 6*#1^2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^2 - 2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^3 + 2*#1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^3 & , 2]; expr // N 1.11221 David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Here is the code: !((Root[(-2) #1^3 + 2 #1^4 - #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] - 6 #1^2 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] + 6 #1^3 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] - 5 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1]^2 - 6 #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1]^2 + 6 #1^2 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1]^2 - 2 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] ^3 + 2 #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1]^3 &, 2];)) I would guess it is a number. I applied RootReduce, ToRadicals, N or combinations of thereof, however, nothing seem to convert the above expression into an explicit number. What command or sequence of Mukhtar Bekkali ==== Subject: How build a function repeating the same pattern? (*I have built this function*) ss[ model1_, list1_, model2_, list2_, t_] := Module[{t1, y1, s1, t2, y2, s2,a, b},{t1, y1, s1} = Transpose[list1]; {t2, y2, s2} = Transpose[list2]; a = model1 /. t -> t1; b = model2 /. t -> t2; Plus @@ (a y1/s1) + Plus @@ (b y2/s2)]; (*It works as I wish. Example*) q1[t_] = a1 Exp[-b1 t]; q2[t_] = a2 Exp[-b2 t]; ss[ q1[t], {{t11, m11, s11}, {t12, m12, s12} }, q2[t], {{t21, m21, s21}, {t22, m22, s22}, {t23, m23, s23}}, t] Now I want to extend this function such as the pattern model, list can be repeated any number of times.Example q3[t_] = a3 Exp[-b3 t]; ss[ q1[t], {{t11, m11, s11}, {t12, m12, s12} }, q2[t], {{t21, m21, s21}, {t22,m22, s22}, {t23, m23, s23}}, q3[t], {{t31, m31, s31}}, t] Any help? Guillermo ==== Subject: Re: Controlling inverses of functions > I've got some functions (Tensor's actually) which aren't trivially > inverted and I want to either control their inverse form, or prevent > mathematica from inverting them altogether, so that I can use Solve > in safety on expressions containing them. Is there anyway of doing > that? For example: In: F[a] == F[b] F[c] > In: Solve[%, F[b]] > Out: {F[b] -> F[a] / F[c]} This is incorrect because 1 / F[c] is an invalid statement (as the > inverse isn't defined). The correct answer is that an answer can't be > derived. Any help on this would be wonderful. Joe > -- > Josef Karthauser (joe@tao.org.uk) http://www.josef-k.net/ > FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/ Hi Josef, One approach might be to use _non commutative multiplication_ {represented by a double star **), as in the following example: In[1]:= F[a] == F[b]*F[c] Out[1]= F[a] == F[b]*F[c] In[2]:= Solve[%, F[b]] Out[2]= {{F[b] -> F[a]/F[c]}} In[3]:= F[a] == F[b]**F[c] Out[3]= F[a] == F[b]**F[c] In[4]:= Solve[%, F[b]] Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. Out[4]= {{F[b] -> InverseFunction[NonCommutativeMultiply, 1, 2][F[a], F[c]]}} In[5]:= Reduce[%%, F[b]] Reduce::nsmet: This system cannot be solved with the methods available to Reduce. Out[5]= Reduce[F[a] == F[b]**F[c], F[b]] Hope this helps, /J.M. ==== Subject: Re: Can't assign value to symbols now realize there is one additional problem. Once I've executed the statement MapThread[(#1 = #2) & , {parameters[[1]], parameters[[3]]}] , because I've specified the first row of parameters as symbols, this row now loses the symbol names and takes on the assigned values, such that my attempt to execute the MapThread Statement again for a different set of values, e.g. parameters[[2]], fails. in: MapThread[(#1 = #2) & , {parameters[[1]], parameters[[3]]}] ; in: {a,b,c} Out: {4,5,6} in: MapThread[(#1 = #2) & , {parameters[[1]], parameters[[2]]}] ; out: Set:: setraw : Cannot assign to raw object 4 ... etc I want to preserve the first row of parameters as the symbol names, so one solution is to use strings, and modify David Park's solution to turn the strings into symbol names when assigned, This works the first time it is run, and parameters[[1]] still contains the strings, but ut still fails the second time. but why? in: parameters = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; in: MapThread[(#1 = #2) & , {ToExpression /@ parameters[[1]], parameters[[3]]}] ; in: {a,b,c} out {4,5,6} in: MapThread[(#1 = #2) & , {ToExpression /@ parameters[[1]], parameters[[3]]}] ; out: Set:: setraw : Cannot assign to raw object 4 ... etc why does the MapThread statement fail the second time? It seems ToExpression/@parameters[[1]] converts the strings a, b, c to symbols but then evaluates them prior to returning them, so the attempt to assign to them in MapThread fails. How can I modify the MapThread statement so I can call it multiple times, each time assigning values to the symbols identified by the strings in the first row?? Lee > Lee, Set (=) has a higher precedence Than Function (&). So all you have to do is > add parentheses. parameters = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; MapThread[(#1 = #2) & , {parameters[[1]], parameters[[3]]}] > {4, 5, 6} David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ > Situation: I have a table that contains parameters and sets of values > that I want to assign to the parameters for the purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] > - fails with error Tag Slot in #1 is Protected > - tried adding Unprotect[#1] and a variety of other attemps, but can't > get it to work. Anyone know how might accomplish this? Lee ==== Subject: Re: Can't assign value to symbols >Situation: I have a table that contains parameters and sets of >values that I want to assign to the parameters for the purposes of >running a simulation. >- parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} >- want to assign values in a given row to the symbols listed in the >first row. >- tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] >- fails with error Tag Slot in #1 is Protected >- tried adding Unprotect[#1] and a variety of other attemps, but can't >get it to work. >Anyone know how might accomplish this? Instead of MapThread[#1 = #2&, {parameters[[1]], parameters[[3]]}] use MapThread[Set[#1,#2]&, {parameters[[1]], parameters[[3]]}] I don't know why the second form works when the first form fails. -- To reply via email subtract one hundred and four ==== Subject: Re: Integrate and Boole problems > I'm using Mathematica 5.1 and I'm getting some inconsistent results > when integrating the Boole function. For example: Integrate[Boole[((x - 1)^2 + y^2 + z^2 - 3^2)*((x + 1)^2 + y^2 + z^2 - > 3^2) = 0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, > -Infinity, Infinity}]; > N[%] 50.2654821239234 + 3.829918318813164*^-9*I > NIntegrate[Boole[((x - 1)^2 + y^2 + z^2 - 3^2)*((x + 1)^2 + y^2 + z^2 > -3^2) = 0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, > -Infinity, Infinity}] 108.90854533339399 - 2.749275252793041*^-29*I Am I doing something wrong or is this just a limit of the Integrate > function? > I assume that Boole[... = 0] is actually Boole[... <= 0]. In version 5.1.0 Integrate just returns the outer integral (with respect to x) unevaluated. NIntegrate apparently uses the method SymbolicPiecewiseSubdivision and it works fine. On the other hand, Mathematica often fails on symbolic integration of the functions of the type Sqrt[r^2 - x^2 - y^2 - z^2]. So if there is an error, most likely it is not related to Boole or other piecewise functions. Here it is easy to find the exact value of the integral. We're just looking for the volume of the union of two spheres with two spherical segments removed. The volume of a spherical segment with radius R and height h is In[1]:= Integrate[r^2*Sin[theta], {r, R - h, R}, {theta, 0, ArcCos[(R - h)/r]}, {phi, 0, 2*Pi}] Out[1]= (-(1/3))*h^2*Pi*(h - 3*R) And substituting the numerical values, we obtain In[2]:= 2*(4*Pi*R^3/3 -2*%) /. {R -> 3, h -> 2} Out[2]= (104*Pi)/3 Owing to the piecewise handling routines, NIntegrate gave a good approximation. Maxim Rytin m.r@inbox.ru ==== Subject: Re: Integrate and Boole problems I'm sorry, it must have pasted incorrectly, it wasn't an equal sign, it was a less than or equal. Integrate[Boole[((x - 1)^2 + y^2 + z^2 - 3^2)*((x + 1)^2 + y^2 + z^2 - 3^2) <= 0], {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, {z, - Infinity, Infinity}] Mathematica 5.1 is able to integrate over Boolean defined regions, so in effect if you can define a region with inequalities, integrating over it will return it's area (if two dimensional) or volume (as is the case above). More about it can be found here: http://www.wolfram.com/products/mathematica/newin51/integrationregions.html ==== Subject: Re: a question about the UnitStep function I want to let Mathematica compute the convolution of two sqare waves. I > did as follows > f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; > integrand=f[z] f[x-z]; > Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, > Infinity}]] > Mathematica gave me the result as follows, > ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 > I plot the result to check > Plot[%,{x,-10,10}, PlotRange->All]; > It is clear wrong since the convolution of two square waves should be > convergent. Can anyone give me some help with the subtlties about the > UnitStep function? Any thoughts are appriciable. > Use PiecewiseIntegrate ( http://library.wolfram.com/infocenter/MathSource/5117/ ): In[52]:= PiecewiseIntegrate[f[z]*f[x - z], {z, -Infinity, Infinity}] Out[52]= If[-2 < x < 0, (2 + x)/4, 0] + If[Inequality[0, LessEqual, x, Less, 2], (2 - x)/4, 0] Also you can obtain the correct result from Integrate if you break the domain of the parameter values into several 'simpler' cases: In[53]:= L = Assuming[#, Integrate[f[z]*f[x - z], {z, -Infinity, Infinity}]]&; Piecewise[{L[#], #}& /@ {x < -1, x == -1, -1 < x < 1, x == 1, 1 < x}] // PiecewiseExpand Out[54]= Piecewise[{{1/4, x == -1 || x == 1}, {1/2, x == 0}, {(2 - x)/4, 0 < x < 1 || Inequality[1, Less, x, LessEqual, 2]}, {(2 + x)/4, Inequality[-2, LessEqual, x, Less, -1] || -1 < x < 0}}] But this isn't very reliable, for example, changing -1 < x < 1 to -1 < x <= 1 would give a wrong answer. Maxim Rytin m.r@inbox.ru ==== Subject: Re: a question about the UnitStep function Hi ! I run out the convolution of the square function on Math4 and I've correctly obtained the triangle plot. The analitical output is: 1/4 If [ 1+x<0, (x-2) UnitStep[x-2] - 2x UnitStep[x] + (x+2) UnitStep[x+2], Integrate[ (-UnitStep[-1 + x - z] + UnitStep[1 + x - z]) (-UnitStep[-1 + z] + UnitStep[1 + z]), {z,-Infinity,Infinity} ] ] I Hope help you ~Scout~ Zhou Jiang ha scritto nel messaggio I want to let Mathematica compute the convolution of two sqare waves. I > did as follows f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; integrand=f[z] f[x-z]; Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, > Infinity}]] Mathematica gave me the result as follows, > ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 I plot the result to check Plot[%,{x,-10,10}, PlotRange->All]; It is clear wrong since the convolution of two square waves should be > convergent. Can anyone give me some help with the subtlties about the > UnitStep function? Any thoughts are appriciable. ==== Subject: Re: a question about the UnitStep function Function f has finite support, so use finite limits of integration Integrate[f[z] f[x - z], {z, -1, 1}] works fine. Mariusz I want to let Mathematica compute the convolution of two sqare waves. I did as follows f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; integrand=f[z] f[x-z]; Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, Infinity}]] Mathematica gave me the result as follows, ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 I plot the result to check Plot[%,{x,-10,10}, PlotRange->All]; It is clear wrong since the convolution of two square waves should be convergent. Can anyone give me some help with the subtlties about the UnitStep function? Any thoughts are appriciable. ==== Subject: Re: a question about the UnitStep function >I want to let Mathematica compute the convolution of two sqare waves. I did as follows f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; integrand=f[z] f[x-z]; Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, Infinity}]] Mathematica gave me the result as follows, >((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 I plot the result to check Plot[%,{x,-10,10}, PlotRange->All]; It is clear wrong since the convolution of two square waves should be convergent. Can anyone give me some help with the subtlties about the UnitStep function? Any thoughts are appriciable. > > Try this, f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; integrand1=f[x] f[x-1] d[[Omega]_]=FourierTransform[integrand1,x,[Omega]]//ExpToTrig//Simplify g[x_]=InverseFourierTransform[Evaluate[d[[Omega]]],[Omega],x] DisplayTogether[Plot[f[x],{x,-10,10}],Plot[f[x-1],{x,-10,10}]] Plot[g[x],{x,-10,10}] Hope this is what your are looking for -- Pratik Desai Graduate Student UMBC Department of Mechanical Engineering Phone: 410 455 8134 ==== Subject: Re: a question about the UnitStep function > I want to let Mathematica compute the convolution of two sqare waves. I did as follows > > f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; > > integrand=f[z] f[x-z]; > > Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, Infinity}]] > > Mathematica gave me the result as follows, > ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 > > I plot the result to check > > Plot[%,{x,-10,10}, PlotRange->All]; > > It is clear wrong since the convolution of two square waves should be convergent. Can anyone give me some help with the subtlties about the UnitStep function? Any thoughts are appriciable. > > Your square wave vanishes for all values outside the interval [-1,1]. Adapting the integration interval leads to the desired result: Assuming[x [Element] Reals, Integrate[integrand, {z, -1, 1}]] (1/4)*((-(2 + x))*UnitStep[-2 - x] - (-2 + x)*UnitStep[2 - x] + 2*x*UnitStep[-x]) Plot[%, {x, -5, 5}, PlotRange -> All]; Torsten ==== Subject: Re: a question about the UnitStep function Hi Zhou, Your example is clearly wrong. Note also that integrand=f[z] f[z-x] where the argument of the second f[] (symmetric function!) has been negated, gives a different, only partly evaluated result. This result, if numerically evaluated, is correct. I think this is something for Wolfram. I will beg Daniel Lichtblau to take note. sincerely, Daniel > I want to let Mathematica compute the convolution of two sqare waves. I did as follows > > f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; > > integrand=f[z] f[x-z]; > > Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, Infinity}]] > > Mathematica gave me the result as follows, > ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 > > I plot the result to check > > Plot[%,{x,-10,10}, PlotRange->All]; > > It is clear wrong since the convolution of two square waves should be convergent. Can anyone give me some help with the subtlties about the UnitStep function? Any thoughts are appriciable. > > ==== Subject: Re: a question about the UnitStep function > I want to let Mathematica compute the convolution of two sqare waves. I did as follows > > f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; > > integrand=f[z] f[x-z]; > > Assuming[Element[x, Reals], Integrate[integrand, {z, -Infinity, Infinity}]] > > Mathematica gave me the result as follows, > ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 + x) UnitStep[2 + x])/4 > > I plot the result to check > > Plot[%,{x,-10,10}, PlotRange->All]; > > It is clear wrong since the convolution of two square waves should be convergent. Can anyone give me some help with the subtlties about the UnitStep function? Any thoughts are appriciable. > > Piecewise works well: In[1]:= fp[x_] := Piecewise[{{1, -1 <= x <= 1}}, 0]; cv = Integrate[fp[z]* fp[x - z], {z, -Infinity, Infinity}] Out[2]= Piecewise[{{2 - x, 0 < x < 2}, {2 + x, -2 < x <= 0}}, 0] -- ==== Subject: Re: a question about the UnitStep function f[x_] := (UnitStep[x + 1] - UnitStep[x - 1])/2; integrand = PiecewiseExpand[f[z] f[x - z]]; Assuming[Element[x, Reals], res = Integrate[integrand, {z, -Infinity, Infinity}]] ?? Jens Zhou Jiang schrieb im I want to let Mathematica compute the > convolution of two sqare waves. I did as follows f[x_]:=(UnitStep[x+1]-UnitStep[x-1])/2; integrand=f[z] f[x-z]; Assuming[Element[x, Reals], Integrate[integrand, > {z, -Infinity, Infinity}]] Mathematica gave me the result as follows, > ((-1 + x) UnitStep[-1 + x] - x UnitStep[x] + (2 > + x) UnitStep[2 + x])/4 I plot the result to check Plot[%,{x,-10,10}, PlotRange->All]; It is clear wrong since the convolution of two > square waves should be convergent. Can anyone > give me some help with the subtlties about the > UnitStep function? Any thoughts are appriciable. ==== Subject: Re: Can't assign value to symbols not that parameters[[1,1]] is a, but when you try to assign a value to parameters[[1,1]] it does not change a, but changes parameters[[1,1]], so the pointers paradigm from other languages is not appropriate in the Mathematica language. still you have other ways to go arround. Since you probably have the same function (i.e., simulation) you want to e valuate for different sets of values for a, b, c you can use rules, say your function is f=(a+2b)*c and the set of values is p = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}} then f/.Map[Thread[Rule[First[p], #]] &, Rest[p]] will return a list of results. yehuda Situation: I have a table that contains parameters and sets of values > that I want to assign to the parameters for the purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] > - fails with error Tag Slot in #1 is Protected > - tried adding Unprotect[#1] and a variety of other attemps, but can't > get it to work. Anyone know how might accomplish this? Lee > ==== Subject: Re: Can't assign value to symbols Situation: I have a table that contains parameters and sets of values > that I want to assign to the parameters for the purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters > [[3]]} ] > - fails with error Tag Slot in #1 is Protected > - tried adding Unprotect[#1] and a variety of other attemps, but can't > get it to work. Anyone know how might accomplish this? Lee One possibility: In[1]:= parameters = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Out[1]= {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}} In[2]:= assignments = MapThread[ StringJoin[ToString[#1], =, ToString[#2]] & , Most[Most[parameters]]] Out[2]= {a=1, b=2, c=3} In[15]:= ToExpression[assignments] Out[15]= {1, 2, 3} In[20]:= a Out[20]= 1 J.87nos ==== Subject: Re: Can't assign value to symbols Lee, Set (=) has a higher precedence Than Function (&). So all you have to do is add parentheses. parameters = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; MapThread[(#1 = #2) & , {parameters[[1]], parameters[[3]]}] {4, 5, 6} David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Situation: I have a table that contains parameters and sets of values that I want to assign to the parameters for the purposes of running a simulation. - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} - want to assign values in a given row to the symbols listed in the first row. - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] - fails with error Tag Slot in #1 is Protected - tried adding Unprotect[#1] and a variety of other attemps, but can't get it to work. Anyone know how might accomplish this? Lee ==== Subject: Re: Explicit solution to Root[] > Here is the code: !((Root[(-2) #1^3 + 2 #1^4 - #1 Root[(-4) - 3 #1 + 66 > #1^2 + > 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] - 6 #1^2 > Root[(-4) - > 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, > 1] + 6 #1^3 Root[(-4) - 3 #1 + > 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, 1] - 5 > Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 > &, > 1]^2 - 6 #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 > + > 216 #1^5 &, 1]^2 + 6 #1^2 Root[(-4) - 3 #1 + > 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 &, > 1]^2 - 2 Root[(-4) - > 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + 216 #1^5 > &, 1] > ^3 + 2 #1 Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + > 216 > #1^5 &, 1]^3 &, 2];)) I would guess it is a number. I applied RootReduce, ToRadicals, N or > combinations of thereof, however, nothing seem to convert the above > expression into an explicit number. What command or sequence of Mukhtar Bekkali > Hi Mukhtar, Is this what you are looking for (*N* seems to work pretty well)? In[1]:= Root[-2*#1^3 + 2*#1^4 - #1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] - 6*#1^2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] + 6*#1^3*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1] - 5*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^2 - 6*#1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^2 + 6*#1^2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^2 - 2*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^3 + 2*#1*Root[-4 - 3*#1 + 66*#1^2 + 80*#1^3 - 108*#1^4 + 216*#1^5 & , 1]^3 & , 2] Out[1]= Root[-24 + 6*#1 + 51*#1^2 - 40*#1^3 - 54*#1^4 + 54*#1^5 & , 1] In[2]:= N[%] Out[2]= 1.1122081402235109 /J.M. ==== Subject: Re: Explicit solution to Root[] I have Mathematica 5.0.1.0. Here is the exact code !(* RowBox[{(Clear[]), n, (Remove[]), [IndentingNewLine], (Off[General:: ]), [IndentingNewLine], (Needs[]), [IndentingNewLine], RowBox[{ RowBox[{ RowBox[{ StyleBox[{, FontColor->RGBColor[1, 0, 1]], RowBox[{ StyleBox[.91é, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[.91.9f, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[.91±, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[r, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[(.91ñ_0), FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[n, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], SubscriptBox[ StyleBox[I, FontColor->RGBColor[1, 0, 1]], 0], ,, (I_n)}], StyleBox[}, FontColor->RGBColor[1, 0, 1]]}], StyleBox[=, FontColor->RGBColor[1, 0, 1]], RowBox[{ StyleBox[{, FontColor->RGBColor[1, 0, 1]], RowBox[{ StyleBox[3, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[(2/3), FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[(1/2), FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[2, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], (2/3), StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[2, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[0, FontColor->RGBColor[1, 0, 1]], StyleBox[,, FontColor->RGBColor[1, 0, 1]], StyleBox[1, FontColor->RGBColor[1, 0, 1]]}], StyleBox[}, FontColor->RGBColor[1, 0, 1]]}]}], StyleBox[;, FontColor-> RGBColor[1, 0, 1]]}], [IndentingNewLine], (CS := .89Ìë+(i = 1)%n Integrate[u_i, {.91î, I_(i - 1), I_i}]; PS := .89Ìë+(i = 1)%k R_i; B := .89Ìë+(i = 1)%n( m_i) b_i;), [IndentingNewLine], StyleBox[(k = 1;), FontColor->RGBColor[1, 0, 0]], [IndentingNewLine], (Table[.91ñ_i = .91ñ_0, {i, 1, k}]; Table[.91ñ_i = 1 - .91ñ_0, {i, k + 1, n}];), [IndentingNewLine], (Table[{p_i, e_i, s_i} = {p_i, e_i, s_i}, {i, 1, n}];), [IndentingNewLine], (L_p = Table[p_i, {i, 1, n}]; L_q = Join[Table[e_i, {i, 1, n}], Table[s_i, {i, 1, n}]];), [IndentingNewLine], (L0_q = Join[Table[Chop[N[(I_n) i/(n + 1)]], {i, 1, n}], Table[Chop[N[(I_n) ((1 - i/(n + 1)))]], {i, 1, n}]];), [IndentingNewLine], RowBox[{ RowBox[{ StyleBox[(T_q), FontColor->RGBColor[0, 0, 1]], StyleBox[=, FontColor->RGBColor[0, 0, 1]], RowBox[{ StyleBox[Table, FontColor->RGBColor[0, 0, 1]], StyleBox[[, FontColor->RGBColor[0, 0, 1]], RowBox[{ RowBox[{ StyleBox[(q_i), FontColor->RGBColor[0, 0, 1]], StyleBox[=, FontColor->RGBColor[0, 0, 1]], (e_i + s_i)}], ,, StyleBox[({i, 1, n}), FontColor->RGBColor[0, 0, 1]]}], StyleBox[], FontColor->RGBColor[0, 0, 1]]}]}], StyleBox[;, FontColor-> RGBColor[0, 0, 1]], (T_b = Table[b_i = e_i/(e_i + s_i), {i, 1, n}]), ;, (T_u = Table[u_i = q_i - ((b_i - .91î))^2 - p_i, {i, 1, n}]), ;}], [IndentingNewLine], (T_I = Table[I_i = .91î /. (Solve[ u_i [Equal] u_(i + 1), .91î])[([1])], {i, 1, n - 1}]), [IndentingNewLine], (T_m = Table[m_i = I_i - I_(i - 1), {i, 1, n}]; T_R = Table[R_i = (p_i) m_i - (((.91ñ_i) e_i^r/r + ((1 - .91ñ_i)) s_i^r/r)), {i, 1, n}];), [IndentingNewLine], (FOCP = Table[D[R_i, p_i], {i, 1, n}]; L_p = L_p /. (Solve[FOCP [Equal] 0, L_p])[([ 1])]; Table[p_i = L_p[([ i])], {i, 1, n}] // Simplify), [IndentingNewLine], (FOCQ = Join[Table[D[R_i, e_i], {i, 1, n}], Table[D[R_i, s_i], { i, 1, n}]];), [IndentingNewLine], (e_1 = s_2; e_2 = s_1;), [IndentingNewLine], (N[ToRules[ Reduce[{0 .89.81ó s_2 .89.81ó s_1, 1/2 .89.81ó .91.87 < 1, FOCQ[([3])] [Equal] 0, FOCQ[([ 4])] [Equal] 0}, {s_1, s_2}, Reals, Backsubstitution [Rule] True]]])}]) After you run it you would see output among which there would be s2. Now, I just copied it and pasted as a new input expression, like this !(expr = Root[(-2) #1^3 + 4 #1^4 + 5 #1 Root[(-24) + 6 #1 + 51 #1^2 - 40 #1^3 - 54 #1^4 + 54 #1^5 &, 1] - 6 #1^2 Root[(-24) + 6 #1 + 51 #1^2 - 40 #1^3 - 54 #1^4 + 54 #1^5 &, 1] + 12 #1^3 Root[(-24) + 6 #1 + 51 #1^2 - 40 #1^3 - 54 #1^4 + 54 #1^5 &, 1] + Root[(-24) + 6 #1 + 51 #1^2 - 40 #1^3 - 54 #1^4 + 54 #1^5 &, 1]^2 - 6 #1 Root[(-24) + 6 #1 + 51 #1^2 - 40 #1^3 - 54 #1^4 + 54 #1^5 &, 1]^2 + 12 #1^2 Root[(-24) + 6 #1 + 51 #1^2 - 40 #1^3 - 54 #1^4 + 54 #1^5 &, 1]^2 - 2 Root[(-24) + 6 #1 + 51 #1^2 - 40 #1^3 - 54 #1^4 + 54 #1^5 &, 1]^3 + 4 #1 Root[(-24) + 6 #1 + 51 #1^2 - 40 #1^3 - 54 #1^4 + 54 #1^5 &, 1]^3 &, 2][IndentingNewLine] expr // N) And now function N does not work. However, if you shutdown the kernel and run the second input N produces a number. I do not know what is going on. Must be something with Mathematica memory. ==== Subject: Re: Explicit solution to Root[] Well, just typing it into Mathematica, I get it to reduce to: Root[-24 + 6*#1 + 51*#1^2 - 40*#1^3 - 54*#1^4 + 54*#1^5 & , 1, 0] Since it's the solution to a polynomial of degree 5, it's unlikely that you'll get a nice clean solution with just radicals. You can find more about the quintic equation here: http://library.wolfram.com/examples/quintic/ ToSymbolic based off of the above link, but the answer is pretty unwieldy. http://www.csh.rit.edu/~topher/math/tosymbolic.html In[66]:= N[Root[-24 + 6*#1 + 51*#1^2 - 40*#1^3 - 54*#1^4 + 54*#1^5 &, 1, 0]] Out[66]= 1.11221 In[70]:= ToSymbolic[Root[-24 + 6*#1 + 51*#1^2 - 40*#1^3 - 54*#1^4 + 54*#1^5 &, 1]]; In[71]:= N[%] Out[71]= {1.11221} ==== Subject: Re: Explicit solution to Root[] a) RootReduce[] will simplify the expression a bit to Root[-24 + 6*#1 + 51*#1^2 - 40*#1^3 - 54*#1^4 + 54*#1^5 & , 1, 0] b) *this* is already a number, you can get a rational approximation or but this is the exact number. Jens Mukhtar Bekkali schrieb im > Here is the code: !((Root[(-2) #1^3 + 2 #1^4 - #1 > Root[(-4) - 3 #1 + 66 > #1^2 + > 80 #1^3 - 108 #1^4 + 216 #1^5 &, > 1] - 6 #1^2 > Root[(-4) - > 3 #1 + 66 #1^2 + 80 #1^3 - 108 #1^4 + > 216 #1^5 &, > 1] + 6 #1^3 Root[(-4) - > 3 #1 + > 66 #1^2 + 80 #1^3 - 108 #1^4 + > 216 #1^5 &, 1] - 5 > Root[(-4) - 3 #1 + 66 #1^2 + 80 #1^3 - > 108 #1^4 + 216 #1^5 > &, > 1]^2 - 6 #1 Root[(-4) - 3 #1 + 66 #1^2 + > 80 #1^3 - 108 #1^4 > + > 216 #1^5 &, 1]^2 + 6 #1^2 > Root[(-4) - 3 #1 + > 66 #1^2 + 80 #1^3 - 108 > #1^4 + 216 #1^5 &, > 1]^2 - 2 Root[(-4) - > 3 #1 + 66 #1^2 + 80 #1^3 - > 108 #1^4 + 216 #1^5 > &, 1] > ^3 + 2 #1 Root[(-4) - 3 #1 + 66 #1^2 + > 80 #1^3 - 108 #1^4 + > 216 > #1^5 &, 1]^3 &, 2];)) I would guess it is a number. I applied > RootReduce, ToRadicals, N or > combinations of thereof, however, nothing seem > to convert the above > expression into an explicit number. What command > or sequence of > commands would do the job? Please advise. Mukhtar Bekkali > ==== Subject: Re: Can't assign value to symbols Situation: I have a table that contains parameters and sets of values > that I want to assign to the parameters for the purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] > - fails with error Tag Slot in #1 is Protected > - tried adding Unprotect[#1] and a variety of other attemps, but can't > get it to work. Anyone know how might accomplish this? Lee Hi Lee, You should use _Replacement Rules_ rather than assignments, as in the following examples: In[1]:= parameters = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Out[1]= {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}} In[2]:= MapThread[#1 -> #2 & , {parameters[[1]], parameters[[3]]}] Out[2]= {a -> 4, b -> 5, c -> 6} In[3]:= a*x^2 + b*x + c /. % Out[3]= 6 + 5*x + 4*x^2 In[4]:= MapThread[#1 -> #2 & , {parameters[[1]], parameters[[4]]}] Out[4]= {a -> 7, b -> 8, c -> 9} In[5]:= Solve[a*x^2 + b*x + c == 0 /. %] Out[5]= {{x -> (1/7)*(-4 - I*Sqrt[47])}, {x -> (1/7)*(-4 + I*Sqrt[47])}} /J.M. ==== Subject: Re: Can't assign value to symbols Hi Lee, Set has the Attribute HoldFirst. Therefore, if you say parameters[[1]] = parameters[[2]] parameters[[1]] will not be evaluated and you are assigning to the array and not to a,b,c. If have to tell Set to evaluate its first argument by: Evaluate[parameters[[1]]] = parameters[[2]] sincerely, Daniel Situation: I have a table that contains parameters and sets of values > that I want to assign to the parameters for the purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] > - fails with error Tag Slot in #1 is Protected > - tried adding Unprotect[#1] and a variety of other attemps, but can't > get it to work. Anyone know how might accomplish this? Lee ==== Subject: Re: Can't assign value to symbols Situation: I have a table that contains parameters and sets of values > that I want to assign to the parameters for the purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] > - fails with error Tag Slot in #1 is Protected > - tried adding Unprotect[#1] and a variety of other attemps, but can't > get it to work. Anyone know how might accomplish this? Lee Do you want sth. like In[1]:= parameters = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; f[a, b, c] /. Thread[First[parameters] -> #1] & ) /@ Rest[parameters] Out[2]= {f[1, 2, 3], f[4, 5, 6], f[7, 8, 9]} ? -- ==== Subject: Re: Can't assign value to symbols a) you should use parameters={{a->1,b->2,c->3},{a->4,b->5,c->6},{a->7,b->8,c->9}} b) Set @@@ Transpose[{parameters[[1]], parameters[[3]]} ] Jens Lee Newman schrieb im Situation: I have a table that contains > parameters and sets of values > that I want to assign to the parameters for the > purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the > symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, > {parameters[[1]], parameters[[3]]} ] > - fails with error Tag Slot in #1 is > Protected > - tried adding Unprotect[#1] and a variety of > other attemps, but can't > get it to work. Anyone know how might accomplish this? Lee ==== Subject: How to suppress plot output ? I am having difficulty forcing a suppression of output for mathematica commands when writing documents. I want to show a multi-part graph: plot1=Plot[ ... ]; plot2=Plot[ ... ]; plot3=Plot[ ... ]; plot4=Plot[ ... ]; Show[ plot1, plot2, plot3, plot4 ]; In the above, I get four individual plots and one final plot. How do I suppress the first four? Paul