mm-649 === Subject: Re: Strange Elements in Table > I use a couple IF's which specify the elements in a 2x10 table. When I > look at the table after calculation, I get a 2x11 table. Why??? All the > needed results are in the first 10 columns, the 11th states the If > commands. It is difficult to pinpoint your mistake without the actual code; however, I hope that the following line will help you to understand how to fix the weird result you got. Say we want all the entries of a 2x10 matrix being equal to the product of their indices except when the indices are equal: In[1]:= Table[If[i == j, 0, i*j], {i, 1, 2}, {j, 1, 10}] Out[1]= {{0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {2, 0, 6, 8, 10, 12, 14, 16, 18, 20}} Hope this helps, /J.M. === Subject: Integration problem I have a periodic function f=1(2pi) (1-e^{-2a})/(1-2e^{-a}cos(x-x0)+e^{-2a}), and I want to calculate the first Fourier coefficient, which corresponds to Integrate[f cos(x),{x,0,2pi}]. The result mathematica tells me is -Cos[x0] Sinh[a]. (The correct result would be Cos[x0] e^{-a}.) If I set x0 to zero, I get the correct result e^{-a}: Simplify[Integrate[(f /. x0 -> 0) Cos[x], {x, 0, 2 [Pi]}], a > 0] e^{-a} The problem is, that for x0=0 both outputs don't match. Can anyone tell me what's wrong? Heidi === Subject: Re: NonlinearFit - Logistic Function-CalcCenter3 expr=a/(1+b*Exp[-c*t]); param={a,b,c}; data1={{-0.06,-0.05},{0.97,-4.2}, {1.99,-9.79},{3,-12.44}, {3.99,-14.57},{5.92,-16.85}, {7.87,-17.27},{11.89,-17.69}, {15.8,-17.74},{19.74,-17.77}, {23.67,-18.19}}; param1=FindFit[data1, expr, param, t] {a -> -17.5291,b -> 8.78665,c -> 1.05894} Plot[expr/.param1, {t,Floor[Min[data1[[All,1]]]], Ceiling[Max[data1[[All,1]]]]}, Frame->True,Axes->False, PlotRange-> {Floor[Min[data1[[All,2]]]]-1, Ceiling[Max[data1[[All,2]]]]+1}, PlotStyle->Blue, Epilog->{Red,AbsolutePointSize[4],Point/@data1}]; data2={{-0.08,0.05},{0.96,-3.19}, {1.93,-6.4},{2.98,-10.32}, {3.97,-11.8},{5.92,-13.98}, {7.88,-14.12},{11.85,-15.34}, {15.79,-14.61},{19.7,-15.43}, {23.67,-15.83}}; For the second data set, specify the Method as either Gradient or QuasiNewton FindFit[data2, expr, param, t, Method->QuasiNewton] {a -> -14.9178,b -> 10.2846,c -> 1.00721} param2=FindFit[data2, expr, param, t, Method->Gradient] {a -> -14.9179,b -> 10.2927,c -> 1.00749} Plot[expr/.param2, {t,Floor[Min[data2[[All,1]]]], Ceiling[Max[data2[[All,1]]]]}, Frame->True, Axes->False, PlotRange-> {Floor[Min[data2[[All,2]]]]-1, Ceiling[Max[data2[[All,2]]]]+1}, PlotStyle->Blue, Epilog->{Red,AbsolutePointSize[4],Point/@data2}]; Bob Hanlon === > Subject: NonlinearFit - Logistic Function-CalcCenter3 > I can fit a logistic function of the form > a/(1 + b*Exp[-c*t]) > to the data points -0.06 -0.05 > 0.97 -4.2 > 1.99 -9.79 > 3 -12.44 > 3.99 -14.57 > 5.92 -16.85 > 7.87 -17.27 > 11.89 -17.69 > 15.8 -17.74 > 19.74 -17.77 > 23.67 -18.19 > I can not fit the same function to the data points > -0.08 0.05 > 0.96 -3.19 > 1.93 -6.4 > 2.98 -10.32 > 3.97 -11.8 > 5.92 -13.98 > 7.88 -14.12 > 11.85 -15.34 > 15.79 -14.61 > 19.7 -15.43 > 23.67 -15.83 > I have tried to do it with Mathematica without success. > I have no problem when I use a progam called CurveExpert. === Subject: Re: solve for a squared variable > Hi everyone, > Why does > Solve[x^2 + y == 1, x^2] > give and error message? How can I solve for x^2? > Ruth Hi Ruth, Since the error message is _General::ivar : x^2 is not a valid variable. More..._ so we must do a change of variable as in the following example: In[1]:= expr = x^2 + y == 1 Out[1]= x^2 + y == 1 In[2]:= Solve[expr /. x^2 -> X, X] Out[2]= {{X -> 1 - y}} In[3]:= x -> Sqrt[X /. %[[1]]] Out[3]= x -> Sqrt[1 - y] In[4]:= expr /. % Out[4]= True /J.M. === Subject: Re: solve for a squared variable > a more elegant procedure, perhaps using patters or whatever. > ----- Original Message ----- === > Subject: [work] Re: solve for a squared variable >>That's because x^2 is not recognized as a symbol. >>let t = x ^ 2, then Solve[t + y == 1, t], you will get the result >>immediately. >>-- >>Li Zhengji >>------------------------------------------------------------- >>If all you have is a hammer, everything is a nail. >>------------------------------------------------------------- Hi Ruth, I guess you have a function in mind, which does this: In[9]:= SolveExpression[x^2 + y == 1, x^2] Out[9]= {{x^2 -> 1 - y}} or even this: In[10]:= SolveExpression[{Tan[t] == b/a, c Cos[t] == a}, a^2 + b^2] Out[10]= {{a^2 + b^2 -> c^2}} ? Well, far from being elegant, the function in this q&d hack does it (almost surely with as many bugs as possible): Needs[Utilities`FilterOptions`]; Clear[SolveExpression]; Options[SolveExpression] ^= UseReduce -> False; (* when to solve for symbols only, use built - in functions *) SolveExpression[eqns_List, Module[{f = If[TrueQ[UseReduce /. {opts}], Reduce, Solve]}, f[eqns, vars, FilterOptions[f, opts]] ]; SolveExpression[eqns_List, vars_List, opt___] := Module[{eq2, va2, t, nosyms, syms, sol, nsvars, usered = TrueQ[UseReduce /. {opt}], varnames = Cases[#1, x_Symbol /; !NumericQ[x], Infinity] & }, nosyms = Complement[vars, syms = varnames[vars]]; t = Table[Unique[], {Length[nosyms]}]; eq2 = Join[eqns, Thread[t == nosyms]]; va2 = Join[syms, t]; nsvars = varnames[nosyms]; sol = If[usered, Reduce[eq2, va2, Backsubstitution -> True, FilterOptions[Reduce, opt]], Solve[eq2, va2, nsvars, FilterOptions[Solve, opt]] ] /. Thread[t -> nosyms]; sol = sol /. (Rule | Equal)[x_, _] | _ == (x_) /; MemberQ[nsvars, x] :> Sequence[]; If[usered, LogicalExpand[sol] /. (a_) == (b_) /; MemberQ[vars, b] :> b == a, Union[sol] ] ]; SolveExpression[e_List, v_, o___] := SolveExpression[e, {v}, o]; SolveExpression[e_, v_List, o___] := SolveExpression[{e}, v, o]; SolveExpression[e_, v_, o___] := SolveExpression[{e}, {v}, o]; -- Peter Pein, Berlin GnuPG Key ID: 0xA34C5A82 http://people.freenet.de/Peter_Berlin/ === Subject: 5.2 Install issues I am having trouble installing Mathematica 5.2 on numerous computers in my department. Most of these had no problem with version 5.1. While the InstallShield Wizard is preparing to install, I get an error that site that said to run isscript8.msi. When I do this, I get an error that the installed doesn't have permission to write to C:Program FilesCommon Filesinstallshielddriver8intel32. When I check file permissions, administrator and system have full control. Is there a solution to this other than formatting and reinstalling the operating system? === Subject: Re: Batch Hello again, I will just copy a simple code below to describe what I am getting. The output in the first notebook is a = a; b = b ; ... What I want is to execute this like a routine, so nb2 should be evaluated before the Print[]. I understand that my program may need some improvement and I will work on that, but I really want to know how to solve the problem I have just described. Maria Cristina ++++++++++++++++++++++++++++++++++ notebooks ++++++++++++++++++++++++ This is the former notebook ; Do[ { c = 3, nb2 = NotebookOpen[tt1.nb], SelectionMove[nb2, All, Notebook], Print[k main , k], SelectionEvaluate[nb2], Print[a = , a], Print[b = , b], Print[ac = , ac], Print[bc = , bc], }, {k, 1, 1}] tt1.nb : Print[k = ,k, nb2] a=k+2 ac=c+2 nb3=NotebookOpen[tt2.nb] SelectionMove[nb3,All,Notebook] SelectionEvaluate[nb3] saida=ToString[k] saida=StringInsert[saida,.tt1.sai,StringLength[saida]+1] NotebookSave[nb2,saida] tt2.nb Print[k = ,k, tt2] b=k+10 bc=c+10 saida=ToString[k] saida=StringInsert[saida,.tt2.sai,StringLength[saida]+1] NotebookSave[nb3,saida] >Hi Maria, >> I thank both Dave and Luc very much, I manage to go one >>step further. >> I have tryed SelectionEvaluation before, but I could not >>identify the notebook properly. Now after you told me I tryed >>with NotebookOpen and it couldn't find the file ($Failed). I >>had to include my working directory in the preferences, and >>now it works. >> I prepare a very simple test, just a notebook calling a >>second nb which calls a third one. It works perfectly, >>opened and executed each notebook without a problem. >> Then I put these callings inside a loop (Do) which would >>just print the loop iteration number. >> Now I come to another problem. All the expressions inside >>the loop are executed and only afterwards the execution of >>the second notebook is performed. Only after that the >>execution of notebook 3 is evaluated. >> This is not what I need. I need that the calling of the >>notebook evalutaion is treated like if it were a routine, >>the program is deviated to the second notebook and after >>evaluating it completely it would come back to the following >>command inside the loop. >> Can anyone give me another advice ? >> >Just to ensure I understand you, you have > nb01 -> nb02 -> nb03 >Which works. However, you need > nb01 -> Do[nb02, {iter}]] -> nb03. >To me (and assuming I've got it right), this sounds like a perfect >application for a package. The minimum you need to do is save the notebook >as a package (Save as special -> package). Commands in the package (it's >difficult to tell exactly what you've done) can then be called as part of a >loop, much as you would call any of the standard packages. >Hope that helps, >Dave. -- Profa Maria Cristina Tavares Faculdade de Engenharia El.8etrica e de Computa.8d.8bo CP 6101 - CEP 13083-970 tel : (19) 3788 3738 fax : (19) 3289 1395 http://www.dsce.fee.unicamp.br/~cristina --------------070400090109010604090601 Hello again,

    I will just copy a simple code below to describe what I am getting. The output in the first notebook is a = a; b = b ; ...

    What I want is to execute this like a routine, so nb2 should be evaluated before the Print[].

    I understand that my program may need some improvement and I will work on that, but I really want to know how to solve the problem I have just described.


          Maria Cristina
++++++++++++++++++++++++++++++++++   notebooks ++++++++++++++++++++++++

                    This is the former notebook ;
Do[
  {
     c = 3,
     nb2 = NotebookOpen[tt1.nb],
     SelectionMove[nb2, All, Notebook],
     Print[k main , k],
     SelectionEvaluate[nb2],
     Print[a = , a],
     Print[b = , b],
     Print[ac = , ac],
     Print[bc = , bc],
    },
  {k, 1, 1}]

            &nbs p;          tt1.nb :
Print[k = ,k, nb2]
a=k+2
ac=c+2
 nb3=NotebookOpen[tt2.nb]
 SelectionMove[nb3,All,Notebook]
 SelectionEvaluate[nb3]
saida=ToString[k]
saida=StringInsert[saida,.tt1.sai,StringLength[saida]+1]
NotebookSave[nb2,saida]

            &nbs p;            &nb sp;      tt2.nb

Print[k = ,k, tt2]
b=k+10
bc=c+10
saida=ToString[k]
saida=StringInsert[saida,.tt2.sai,StringLength[saida]+1]
NotebookSave[nb3,saida]

Hi Maria, 
  
    I thank both Dave and Luc very much, I manage to go 
one 
step further.
    I have tryed  SelectionEvaluation before, but I could not 
identify the notebook properly. Now after you told me I tryed 
with NotebookOpen and it couldn't find the file ($Failed). I 
had to include my working directory in the preferences, and 
now it works.
    I prepare a very simple test, just a notebook calling a 
second nb which calls a third one.  It works perfectly, 
opened and executed each notebook without a problem.
    Then I put these callings inside a loop (Do) which would 
just print the loop iteration number.
    Now I come to another problem. All the expressions inside 
the loop are executed and only afterwards the execution of  
the second notebook is performed. Only after that the 
execution of notebook 3 is evaluated.
    This is not what I need. I need that the calling of the 
notebook evalutaion is treated  like if it were a routine, 
the program is deviated to the second notebook and after 
evaluating it completely it would come back to the following 
command inside the loop.
    Can anyone give me another advice ?
    

Just to ensure I understand you, you have
        nb01 -> nb02 -> nb03
Which works.  However, you need
        nb01 -> Do[nb02, {iter}]] -> nb03.
To me (and assuming I've got it right), this sounds like a perfect
application for a package.  The minimum you need to do is save the notebook
as a package (Save as special -> package).  Commands in the package  
(it's
difficult to tell exactly what you've done) can then be called as part of a
loop, much as you would call any of the standard packages.  
Hope that helps,
Dave.
  


-- 
Profa Maria Cristina Tavares
Faculdade de Engenharia Elétrica e de Computação
CP 6101 - CEP 13083-970
tel : (19) 3788 3738
fax : (19) 3289 1395
http://www.dsce.fee.unicamp
.br/~cristina
--------------070400090109010604090601-- === Subject: Re: number of digits in n^p Hi George, if you don't want to use DigitCount[] command (eg. Total[DigitCount[n^b]] or Plus@@DigitCount[n^b] ), let's suppose that d is the number of digits in n^b then n^b = a*10^d where 0.1 <= a < 1. Taking the log base 10 of both sides of the equation and solving in d we get d = b*log(n) - log(a) where -1 <= log(a) < 0. Thus, since d is an integer, truncate b*log(n) to an integer and add 1. In Mathematica we can write: In[1]:= f[n_Integer, b_Integer]:= IntegerPart[b Log[10,n]]+1 /; n>0&&b>0 In[2]:= f[67,89] Out[2]= 163 ~ Scout ~ > i wonder if there is a formula, a function, or a method in mathematica to > know the number of digits in n raised to the power of p without > calculating the result, such as 67^89 will give us a number with 163 > digits in it, is there a way to know this result without actually > calculating 67^89 > George === Subject: Re: number of digits in n^p > i wonder if there is a formula, a function, or a method in mathematica to know the number of digits in n raised to the power of p without calculating the result, such as 67^89 will give us a number with 163 digits in it, is there a way to know this result without actually calculating 67^89 > George Hi George, Is this what you are looking for? In[1]:= Plus @@ DigitCount[67^89] Out[1]= 163 /J.M. === Subject: Re: number of digits in n^p Not extremely difficult! The function (Floor[Log[10, x]] + 1) gives the number of digits (before the decimal point) of a positive number. Use the logarithm laws to obtain digitsofpower[n_Integer /; n > 0, p_Integer /; p >= 0] := Floor[p*Log[10,n]]+ 1 E.g. digitsofpower[67, 89] returns 163 Ingolf Dahl Sweden -----Original Message----- === Subject: number of digits in n^p i wonder if there is a formula, a function, or a method in mathematica to know the number of digits in n raised to the power of p without calculating the result, such as 67^89 will give us a number with 163 digits in it, is there a way to know this result without actually calculating 67^89 George __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com === Subject: Re: solve for a squared variable Ruth, Manipulate the equation 'by hand'.... x^2 + y == 1 # - y & /@ % x^2 + y == 1 x^2 == 1 - y David Park djmp@earthlink.net http://home.earthlink.net/~djmp/ Hi everyone, Why does Solve[x^2 + y == 1, x^2] give and error message? How can I solve for x^2? Ruth === Subject: Extracting coefficients for sinusoidals Suppose I have a signal signal = Sin[p] and a non-linear function f[x_] := x - x^3/3 then f[signal] = Sin[p] - Sin[p]^3/3 but I don't want this form (with powers of the Sin function), but rather the form with multiples of p. TrigReduce can solve that: signal // f // TrigReduce (9*Sin[p] + Sin[3*p])/12 It's easy to extract the coefficients by visual inspection, 9/12, 1/12 but how can it be done programmaticaly? With a more complex non-linear function, for example a1*x + a1*x^2 + a1*x^3 + a4*x^4 + a5*x^5 using signal // f // TrigReduce // InputForm resulting in (8*a1 + 6*a4 - 8*a1*Cos[2*p] - 8*a4*Cos[2*p] + 2*a4*Cos[4*p] + 28*a1*Sin[p] + 10*a5*Sin[p] - 4*a1*Sin[3*p] - 5*a5*Sin[3*p] + a5*Sin[5*p])/16 visual ispection is no longer simple enough. So how can I get the coefficients, individually or as a list? I'm not sure how I want the Cos and Sin terms to be treated; probably a*Cos[x] should correspond to a*I*Sin[x] when the coefficients are collected. -- Helge Stenstr.9am === Subject: NDSolve acceleration by forcing use of LAPACK functions I'm looking at two Mathematica notebooks. The first is Michael Trott's Mathematics of Tsunamis (http://mathworld.wolfram.com/news/2005-01-14/tsunamis/) http://mathworld.wolfram.com/news/2005-01-14/tsunamis/Tsunami.nb and the second is the Mathematica 5.2 promoting Modeling, Simulating and Analyzing a Tsunami (http://library.wolfram.com/infocenter/Demos/5699/) by Robert Knapp et al (noted animations on Jeff Bryant's pages). The Trott version has an NDSolve[] method options set up that invokes LAPACK's dgetrf() function. The Knapp version does not. Why this is important will now become more clear: The LAPACK function dgetrf() performas an LU matrix factorisation which is dominated by a matrix-matrix multiplication (i.e. Dot[] in Mathematica, also called 'dgemm' in BLAS/LAPACK speak). I work for ClearSpeed in the UK and we have PCI-X co-processor cards that deliver 50GFLOPS of dgemm performance. We wish to show the capability improvement users will see running 'hard' computations. Each of the notebooks is easily scalable. In fact, the Knapp example was designed to demonstrate the impact of this scaling. By increasing the resolution of the computation, the wave propogation is smoother and more faithful. Until now, the cost of this more refined analysis has been presented in minutes turning into hours of compute. Using our card, I have measured a six-fold time-difference for the LAPACK-function (given a large enough problem size) versus a 3.4GHz Xeon. Obviously, it would be more interesting to use the Knapp version since it shows the wave propogation on a per-step basis and has a more interesting sea-bottom. I have thus far failed to comprehend the changes required to make the method options in the Knapp version invoke the LAPACK functions. I would appreciate some helpful pointers. James Irwin ClearSpeed Technology PLC === Subject: calling a C executable from within Mathematica Would someone please help me with the function call within Mathematica? I would like to use a C program within Mathematica. Here is what the program looks like when run under a DOS window. I have included some paratheses where I comment. E:Analysis>simulation5.ext alpha.txt params.txt output.txt 5 rows of data read from alpha file. enter level of temp, volatility, 100 year mean, thermal coefficient 63 .2 3.6 1.2 (entered with spaces) what percent is man-made carbon effect? 12 threshold (%)? 95 how many simulations? 9999 average number of years between 20%, 15%, 10%, and 5% peturburances? 50 25 15 5 (entered with spaces) here is the alpha text file that is located in the same directory as the C executable: 60 .20 61 .23 62 .25 63 .29 64 .33 Here is the params text file that is located in the same directory as the C executable: 1000000.0 0.0 4.58 0.0 2.0 99.0 85.0 10.0 15.0 2.0 50.0 20.0 10.0 20.0 We can change the input/output code in the C code to best suit Mathlink. Steve -- Steven Taracevicz 310.749.6666 cell 702.355.6396 310.388.3265 fax === Subject: The question of equality,... Ok I thought I understood this stuff but maybe not,... If I wanted to check for bit-for-bit equality of two arbitrary precision numbers (without regard to how many of those digits are meaningful) like the way it would be done using the == operator in C, then correct? For == the 5.1 Appendix A says: Approximate numbers are considered equal if they differ in at most their last eight binary digits (roughly their last two decimal digits). SameQ requires exact correspondence between expressions, except that it considers Real numbers equal if their difference is less than the uncertainty of either of them So what can I use then? Any and all help is much appreciated. Terry === Subject: Re: Complete solution to a modular System of equations > In coding theory one is intersted to find the dual code of a given > code. To do this one has to solve a modular linear equation such as: > eq = {a + b + d == 0, a + c + d == 0, b + c + d == 0} > lhs = {{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}}; rhs = {0, 0, 0}; > LinearSolve[lhs,{0,0,0},Modulus->2] > Out[52]= > {0,0,0,0} > as you see it returns only one solution. How can I find all solutions. > The number of solutions is a power of 2. For about example there is > exacly one more solution which is > {1,1,1,0}. > Is there any function in Mathematica to do this? or I should start > writing my own code? > chekad You can get a full set of generators to the null space using (no surprise here) NullSpace. In[11]:= NullSpace[lhs, Modulus->2] Out[11]= {{1, 1, 1, 0}} If your linear system is inhomogeneous you can get a particular solution using LinearSolve. You can then form all possible solutions by adding all possible null vectors, which in turn is done by adding all possible linear combinations of null space basis vectors. I would not try this over fields of large (or very small) characteristic. Daniel Lichtblau Wolfram Research === Subject: Re: Complete solution to a modular System of equations > In coding theory one is intersted to find the dual code of a given > code. To do this one has to solve a modular linear equation such as: > eq = {a + b + d == 0, a + c + d == 0, b + c + d == 0} > lhs = {{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}}; rhs = {0, 0, 0}; > LinearSolve[lhs,{0,0,0},Modulus->2] > Out[52]= > {0,0,0,0} > as you see it returns only one solution. How can I find all solutions. > The number of solutions is a power of 2. For about example there is > exacly one more solution which is > {1,1,1,0}. > Is there any function in Mathematica to do this? or I should start > writing my own code? Use Reduce: In[11]:= Reduce[{Mod[lhs . {a, b, c, d} - rhs, 2] == 0, 0 <= a < 2, 0 <= b < 2, 0 <= c < 2, 0 <= d < 2}, Integers] Out[11]//OutputForm= (a == 0 && b == 0 && c == 0 && d == 0) || (a == 1 && b == 1 && c == 1 && d == 0) > chekad Carl Woll Wolfram Research === Subject: Re: Complete solution to a modular System of equations > In coding theory one is intersted to find the dual code of a given > code. To do this one has to solve a modular linear equation such as: > eq = {a + b + d == 0, a + c + d == 0, b + c + d == 0} > lhs = {{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}}; rhs = {0, 0, 0}; > LinearSolve[lhs,{0,0,0},Modulus->2] > Out[52]= > {0,0,0,0} > as you see it returns only one solution. How can I find all solutions. > The number of solutions is a power of 2. For about example there is > exacly one more solution which is > {1,1,1,0}. > Is there any function in Mathematica to do this? or I should start > writing my own code? > chekad You can get a full set of generators to the null space using (no surprise here) NullSpace. In[11]:= NullSpace[lhs, Modulus->2] Out[11]= {{1, 1, 1, 0}} If your linear system is inhomogeneous you can get a particular solution using LinearSolve. You can then form all possible solutions by adding all possible null vectors, which in turn is done by adding all possible linear combinations of null space basis vectors. I would not try this over fields of large (or very small) characteristic. Daniel Lichtblau Wolfram Research === Subject: Re: Complete solution to a modular System of equations > In coding theory one is intersted to find the dual code of a given > code. To do this one has to solve a modular linear equation such as: > eq = {a + b + d == 0, a + c + d == 0, b + c + d == 0} > lhs = {{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}}; rhs = {0, 0, 0}; > LinearSolve[lhs,{0,0,0},Modulus->2] > Out[52]= > {0,0,0,0} > as you see it returns only one solution. How can I find all solutions. > The number of solutions is a power of 2. For about example there is > exacly one more solution which is > {1,1,1,0}. > Is there any function in Mathematica to do this? or I should start > writing my own code? Use Reduce: In[11]:= Reduce[{Mod[lhs . {a, b, c, d} - rhs, 2] == 0, 0 <= a < 2, 0 <= b < 2, 0 <= c < 2, 0 <= d < 2}, Integers] Out[11]//OutputForm= (a == 0 && b == 0 && c == 0 && d == 0) || (a == 1 && b == 1 && c == 1 && d == 0) > chekad Carl Woll Wolfram Research === Subject: Re: Complete solution to a modular System of equations > In coding theory one is intersted to find the dual code of a given > code. To do this one has to solve a modular linear equation such as: > eq = {a + b + d == 0, a + c + d == 0, b + c + d == 0} > lhs = {{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}}; rhs = {0, 0, 0}; > LinearSolve[lhs,{0,0,0},Modulus->2] > Out[52]= > {0,0,0,0} > as you see it returns only one solution. How can I find all solutions. > The number of solutions is a power of 2. For about example there is > exacly one more solution which is > {1,1,1,0}. > Is there any function in Mathematica to do this? or I should start > writing my own code? > chekad eq = {a + b + d == 0, a + c + d == 0, b + c + d == 0}; Reduce[eq, {a, b, c, d}, Modulus -> 2] a == C[1] && b == C[1] && c == C[1] && d == 0 Here C[1] is an arbitrary constant in Z/2, in other words it can be either 0 or 1, hence the two solutions are exactly {0,0,0,0} and {1,1,1,0}. Andrzej Kozlowski === Subject: Re: Complete solution to a modular System of equations > In coding theory one is intersted to find the dual code of a given > code. To do this one has to solve a modular linear equation such as: > eq = {a + b + d == 0, a + c + d == 0, b + c + d == 0} > lhs = {{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}}; rhs = {0, 0, 0}; > LinearSolve[lhs,{0,0,0},Modulus->2] > Out[52]= > {0,0,0,0} > as you see it returns only one solution. How can I find all solutions. > The number of solutions is a power of 2. For about example there is > exacly one more solution which is > {1,1,1,0}. > Is there any function in Mathematica to do this? or I should start > writing my own code? > chekad Igor Gachkov's package _Error-correcting codes with Mathematica_ may be of interest. Check http://library.wolfram.com/infocenter/MathSource/5085/ Hope this helps, /J.M. === Subject: Re: Complete solution to a modular System of equations eq={a+b+d==0,a+c+d==0,b+c+d==0}; soln=Reduce[eq,{a,b,c,d},Modulus->2] a == C[1] && b == C[1] && c == C[1] && d == 0 List@@Last/@soln/.{{C[1]->0},{C[1]->1}} {{0, 0, 0, 0}, {1, 1, 1, 0}} Bob Hanlon === > Subject: Complete solution to a modular System of equations > In coding theory one is intersted to find the dual code of a given > code. To do this one has to solve a modular linear equation such as: > eq = {a + b + d == 0, a + c + d == 0, b + c + d == 0} > lhs = {{1, 1, 0, 1}, {1, 0, 1, 1}, {0, 1, 1, 1}}; rhs = {0, 0, 0}; > LinearSolve[lhs,{0,0,0},Modulus->2] > Out[52]= > {0,0,0,0} > as you see it returns only one solution. How can I find all solutions. > The number of solutions is a power of 2. For about example there is > exacly one more solution which is > {1,1,1,0}. > Is there any function in Mathematica to do this? or I should start > writing my own code? > chekad === Subject: NDSolve acceleration by forcing use of LAPACK functions I'm looking at two Mathematica notebooks. The first is Michael Trott's Mathematics of Tsunamis (http://mathworld.wolfram.com/news/2005-01-14/tsunamis/) http://mathworld.wolfram.com/news/2005-01-14/tsunamis/Tsunami.nb and the second is the Mathematica 5.2 promoting Modeling, Simulating and Analyzing a Tsunami (http://library.wolfram.com/infocenter/Demos/5699/) by Robert Knapp et al (noted animations on Jeff Bryant's pages). The Trott version has an NDSolve[] method options set up that invokes LAPACK's dgetrf() function. The Knapp version does not. Why this is important will now become more clear: The LAPACK function dgetrf() performas an LU matrix factorisation which is dominated by a matrix-matrix multiplication (i.e. Dot[] in Mathematica, also called 'dgemm' in BLAS/LAPACK speak). I work for ClearSpeed in the UK and we have PCI-X co-processor cards that deliver 50GFLOPS of dgemm performance. We wish to show the capability improvement users will see running 'hard' computations. Each of the notebooks is easily scalable. In fact, the Knapp example was designed to demonstrate the impact of this scaling. By increasing the resolution of the computation, the wave propogation is smoother and more faithful. Until now, the cost of this more refined analysis has been presented in minutes turning into hours of compute. Using our card, I have measured a six-fold time-difference for the LAPACK-function (given a large enough problem size) versus a 3.4GHz Xeon. Obviously, it would be more interesting to use the Knapp version since it shows the wave propogation on a per-step basis and has a more interesting sea-bottom. I have thus far failed to comprehend the changes required to make the method options in the Knapp version invoke the LAPACK functions. I would appreciate some helpful pointers. James Irwin ClearSpeed Technology PLC === Subject: Re: Mathematica: access serial port? > Is there any way to make a Mathematica program access the serial port? > I need this to link to external electronical device. > Maybe using MathLink (but I don't know programming in C/C++)? A while back I created a package that does this. After reading your message I cleaned it up a little and contributed it to the Mathematica InfoCenter , but it has not yet been posted. In the mean time you can download it here . Unzip, place the folder in $[User]BaseDirectory/Applications, then load with < Is there any way to make a Mathematica program access the serial port? > I need this to link to external electronical device. > Maybe using MathLink (but I don't know programming in C/C++)? > I use Mathematica 5.0 in Linux, so this maybe would require a kernel > module for the serial port. === Subject: Re: Mathematica: access serial port? > Is there any way to make a Mathematica program access the serial port? > I need this to link to external electronical device. > Maybe using MathLink (but I don't know programming in C/C++)? A while back I created a package that does this. After reading your message I cleaned it up a little and contributed it to the Mathematica InfoCenter , but it has not yet been posted. In the mean time you can download it here . Unzip, place the folder in $[User]BaseDirectory/Applications, then load with < Is there any way to make a Mathematica program access the serial port? > I need this to link to external electronical device. > Maybe using MathLink (but I don't know programming in C/C++)? > I use Mathematica 5.0 in Linux, so this maybe would require a kernel > module for the serial port. === Subject: Re: Bug in Reduce? >The source of this apparent bug could be my misunderstanding of the middle, >vars parameter of Reduce, but it sure seems like the following output >indicates that c must be 0 for my two equations to be satisfied, when in >fact if a and b are both 0, c does not need to be 0. >Jack >In[1]:= >Reduce[{a c - b d == 0, a d + b c == 0}, {a, b, c, d}, Reals] // >FullSimplify >Out[1]= >c == 0 && (d == 0 || (a == 0 && b == 0)) >(version 5.1 for Windows) I get a more richer solution when I used assumptions (c notequal 0) and simplify Clear[a, b, c, d] expr1 = {a*c - b*d == 0, a*d + b*c == 0} $Assumptions = {c .89ÅÊ 0, a ì[Micro] Reals, b ì[Micro] Reals, cì[Micro] Reals, d ì[Micro] Reals, c ì[Micro] Reals} s1 = Reduce[expr1, {a, b, c, d}] // Simplify >>(a == 0 && (b == 0 || (c == 0 && d == 0))) || ((b*c)/a + d == 0 && a != 0 && (b == (-I)*a || b == I*a)) || (c == 0 && d == 0 && a^2 + b^2 != 0) Hope this helps If there are some ineligible characters those are meant to be element Esc Shift+1=Esc -- Pratik Desai Graduate Student UMBC Department of Mechanical Engineering Phone: 410 455 8134 === Subject: Re: Bug in Reduce? >The source of this apparent bug could be my misunderstanding of the middle, >vars parameter of Reduce, but it sure seems like the following output >indicates that c must be 0 for my two equations to be satisfied, when in >fact if a and b are both 0, c does not need to be 0. >Jack >In[1]:= >Reduce[{a c - b d == 0, a d + b c == 0}, {a, b, c, d}, Reals] // >FullSimplify >Out[1]= >c == 0 && (d == 0 || (a == 0 && b == 0)) >(version 5.1 for Windows) I get a more richer solution when I used assumptions (c notequal 0) and simplify Clear[a, b, c, d] expr1 = {a*c - b*d == 0, a*d + b*c == 0} $Assumptions = {c .89ÅÊ 0, a ì[Micro] Reals, b ì[Micro] Reals, cì[Micro] Reals, d ì[Micro] Reals, c ì[Micro] Reals} s1 = Reduce[expr1, {a, b, c, d}] // Simplify >>(a == 0 && (b == 0 || (c == 0 && d == 0))) || ((b*c)/a + d == 0 && a != 0 && (b == (-I)*a || b == I*a)) || (c == 0 && d == 0 && a^2 + b^2 != 0) Hope this helps If there are some ineligible characters those are meant to be element Esc Shift+1=Esc -- Pratik Desai Graduate Student UMBC Department of Mechanical Engineering Phone: 410 455 8134 === Subject: Re: Bug in Reduce? > $Version > 5.2 for Mac OS X (June 20, 2005) > Reduce[{a c-b d==0,a d+b c==0}, > {a,b,c,d},Reals]//Simplify > (a == 0 && b == 0) || (c == 0 && d == 0) > Bob Hanlon === >>Subject: Bug in Reduce? >>The source of this apparent bug could be my misunderstanding of the > middle, >>vars parameter of Reduce, but it sure seems like the following output >>indicates that c must be 0 for my two equations to be satisfied, when in >>fact if a and b are both 0, c does not need to be 0. >>Jack >>In[1]:= >>Reduce[{a c - b d == 0, a d + b c == 0}, {a, b, c, d}, Reals] // >>FullSimplify >>Out[1]= >>c == 0 && (d == 0 || (a == 0 && b == 0)) >>(version 5.1 for Windows) In[1]:= FullSimplify[Reduce[{a*c - b*d == 0, a*d + b*c == 0}, {a, b, c, d}, Reals]] Out[1]= (a == 0 && b == 0) || (c == 0 && d == 0) In[2]:= $Version Out[2]= 5.2 for Microsoft Windows (June 20, 2005) /J.M. === Subject: calling a C executable from within Mathematica Would someone please help me with the function call within Mathematica? I would like to use a C program within Mathematica. Here is what the program looks like when run under a DOS window. I have included some paratheses where I comment. E:Analysis>simulation5.ext alpha.txt params.txt output.txt 5 rows of data read from alpha file. enter level of temp, volatility, 100 year mean, thermal coefficient 63 .2 3.6 1.2 (entered with spaces) what percent is man-made carbon effect? 12 threshold (%)? 95 how many simulations? 9999 average number of years between 20%, 15%, 10%, and 5% peturburances? 50 25 15 5 (entered with spaces) here is the alpha text file that is located in the same directory as the C executable: 60 .20 61 .23 62 .25 63 .29 64 .33 Here is the params text file that is located in the same directory as the C executable: 1000000.0 0.0 4.58 0.0 2.0 99.0 85.0 10.0 15.0 2.0 50.0 20.0 10.0 20.0 We can change the input/output code in the C code to best suit Mathlink. Steve -- Steven Taracevicz 310.749.6666 cell 702.355.6396 310.388.3265 fax === Subject: Re: Why this function does not return a single value Hi Bill I have no problems fitting a set of 15 Gaussian or Lorentzian peaks together with the hump and the exponential wing on the low 2theta side. That fit converges rapidly after I give it a good set of initial values. It involves 50 adjustable parameters. I was very pleased with how Mathematica handled that problem. I define the sum of 16 Gaussian peaks GaussSumNew[x_] := Sum[a[i]*Exp[(-Log[2.])*((x - b[i])^2/c[i]^2)], {i, 1, 16}] And then I do Peaks = NonlinearFit[MyData, GaussSumNew[x] + a[17]*Exp[-x/b[17]], {x}, {{a[1], 2429.}, {a[2], 609.}, {a[3], 459.}, {a[4], 1009.}, {a[5], 2695.}, {a[6], 7271.}, {a[7], 1432.}, {a[8], 1308.}, {a[9], 2998.}, {a[10], 3775.}, {a[11], 3775.}, {a[12], 1001.}, {a[13], 325.}, {a[14], 563.}, {a[15], 1119.}, {a[16], 5317.}, {a[17], 12359.}, {b[1], 5.45}, {b[2], 9.81}, {b[3], 11.08}, {b[4], 13.89}, {b[5], 14.87}, {b[6], 16.92}, {b[7], 18.1}, {b[8], 19.51}, {b[9], 22.18}, {b[10], 22.8}, {b[11], 23.76}, {b[12], 25.89}, {b[13], 29.77}, {b[14], 30.93}, {b[15], 34.01}, {b[16], 28.35}, {b[17], 1.67}, {c[1], 0.5}, {c[2], 0.5}, {c[3], 0.5}, {c[4], 0.5}, {c[5], 0.5}, {c[6], 0.5}, {c[7], 0.5}, {c[8], 0.5}, {c[9], 0.5}, {c[10], 0.5}, {c[11], 0.5}, {c[12], 0.5}, {c[13], 0.5}, {c[14], 0.5}, {c[15], 0.5}, {c[16], 15.}}] In the above fit I add the exponential background and MyData is a list of {x,y} pairs of numbers Imported from my data file. Analysis of FitResiduals riveled that some information was not accounted for by this model. Basically the Autocorrelation Function for the residuals is not just noise. There is a structure to it and I think that neither Gaussian nor Lorentzian does represent the shape of my peaks well. Therefore I decided to try the Voigt function and run into some difficulties. However the same approach as presented above does not work with Voigt function because it involves NIntegrate in the definition of my function. Now in my last post I said that I adjusted the parameters so that resulting plot gives You some idea of how my data looks. The representation is far from perfect. I found that initial values manually by first reading the peak positions from the graph and then changing manually the intensity of each and every peak so that it comes close to experimental values when I plot the data points together with the function. And I do not intend to do that for every data file I have to analyze this way and I just want to know how to do this. I am fully aware that NonlinearFit with that many parameters is non trivial. However I am willing to try it and I think that with a good set of initial parameters I will be successful. Marek >>If You run the code from my previous post You will see how my data >>looks like because I adjusted the parameters in the lists a, b, >>[Delta]L and [Delta]G so that it represents my data quite well. >>However I want to use NonlinearFit (or FindFit) to find the values of >>those parameters which best represent my data. > We are clearly not communicating effectively. I did run your code and was > able to see how the function plots. But this gives me essentially no > information as to what to suggest. > When I asked about your data, I was not interested in a plot of your data > but the structure of the data files. For example, if I were trying to > correlate temperature measurments made in Celsius to temperature > measurments in Fahrenheit, I might have a file that looked like > 50, 122.5 > 60, 140.1 > 70, 158 > 80, 176.2 > 90, 194.3 > Now since I know there is a linear relationship between Celsius and > Fahrenheit I would use FindFit as follows: > FindFit[data, a*T + b, {a, b}, T] > to get > {a -> 1.797, b -> 32.43} > Here data is an array that contains values of the independent variable as > well as the response. And in this particular example, data is set equal > to: > {{50, 122.5}, {60, 140.1},{70, 158}, {80, 176.2}, > {90, 194.3}} > A non-linear problem or multi-dimensional problem is handled identically. > That is I have a data matrix where every row is the values for the > independent variables followed by the response, an expression that says > how the response is obtained from the independent variables, a list of the > symbols used as independent variables and finally the symbol used as the > response variable. > There is no limit to how complex I choose to make the expression relating > independent variables to response save memory, my patience and the number > of distinct data points in the data set. > For example, if I had a suitable number of data points I could have chosen > as my expression relating Celsius to Fahrenheit as say > a*T + T^b + c Log[T] +d > Obviously, this will not result in a meaning fit. And in this particular > case, FindFit may not be able to achieve convergence. > In your case, the expression showing the relationship between a single > independent variable and response could be written as > Voigt[x,a1,b1,dL1,dG1] + Voigt[x,a2,b2,dL2,dG2] + ... > and the corresponding paramater list would be > {a1,b1,dL1,dG1,a2,b2,dL2,dG2,....} > Here I am assuming a data matrix with two columns, the first representing > values for a single dependent variable and the second column the response. > FindFit can be used with more than one independent variable without > difficultly. > However, you described a desire to fit a sum of 15 non-linear functions to > the data. And it is beginning to sound like for each of these you need to > optimize possibly 4 independent parameters. If I have this correct, then > you are likely to be quite fustrated with either FindFit or NonlinearFit. > Fitting non-linear models to data is inherently a difficult problem And > the difficulty increases rapidly with the number of non-linear parameters > that need to be found. With a large number of parameters ot be found, it > will be very difficult to ensure the algortithm used doesn't get trapped > by a local minimum giving a sub-optimum solution. Of course, this issue > can be largely mitigated by giving FindFit a good set of starting points. > One final comment. You say above you adjusted the paramters to give a good > fit to your data. If so, why bother with either FindFit or NonlinearFit at > all? What FindFit will do is provide you with another estimate as to the > values of the parameters you've effectively already estimated by some > other means. The values provided by FindFit or NonlinearFit are likely to > be different than the values you've already obtained and *might* be > considered better under some very specific conditions which often aren't > met by real data. -- To reply via email subtract one hundred and four === Subject: Re: Why this function does not return a single value Hi Bill I have no problems fitting a set of 15 Gaussian or Lorentzian peaks together with the hump and the exponential wing on the low 2theta side. That fit converges rapidly after I give it a good set of initial values. It involves 50 adjustable parameters. I was very pleased with how Mathematica handled that problem. I define the sum of 16 Gaussian peaks GaussSumNew[x_] := Sum[a[i]*Exp[(-Log[2.])*((x - b[i])^2/c[i]^2)], {i, 1, 16}] And then I do Peaks = NonlinearFit[MyData, GaussSumNew[x] + a[17]*Exp[-x/b[17]], {x}, {{a[1], 2429.}, {a[2], 609.}, {a[3], 459.}, {a[4], 1009.}, {a[5], 2695.}, {a[6], 7271.}, {a[7], 1432.}, {a[8], 1308.}, {a[9], 2998.}, {a[10], 3775.}, {a[11], 3775.}, {a[12], 1001.}, {a[13], 325.}, {a[14], 563.}, {a[15], 1119.}, {a[16], 5317.}, {a[17], 12359.}, {b[1], 5.45}, {b[2], 9.81}, {b[3], 11.08}, {b[4], 13.89}, {b[5], 14.87}, {b[6], 16.92}, {b[7], 18.1}, {b[8], 19.51}, {b[9], 22.18}, {b[10], 22.8}, {b[11], 23.76}, {b[12], 25.89}, {b[13], 29.77}, {b[14], 30.93}, {b[15], 34.01}, {b[16], 28.35}, {b[17], 1.67}, {c[1], 0.5}, {c[2], 0.5}, {c[3], 0.5}, {c[4], 0.5}, {c[5], 0.5}, {c[6], 0.5}, {c[7], 0.5}, {c[8], 0.5}, {c[9], 0.5}, {c[10], 0.5}, {c[11], 0.5}, {c[12], 0.5}, {c[13], 0.5}, {c[14], 0.5}, {c[15], 0.5}, {c[16], 15.}}] In the above fit I add the exponential background and MyData is a list of {x,y} pairs of numbers Imported from my data file. Analysis of FitResiduals riveled that some information was not accounted for by this model. Basically the Autocorrelation Function for the residuals is not just noise. There is a structure to it and I think that neither Gaussian nor Lorentzian does represent the shape of my peaks well. Therefore I decided to try the Voigt function and run into some difficulties. However the same approach as presented above does not work with Voigt function because it involves NIntegrate in the definition of my function. Now in my last post I said that I adjusted the parameters so that resulting plot gives You some idea of how my data looks. The representation is far from perfect. I found that initial values manually by first reading the peak positions from the graph and then changing manually the intensity of each and every peak so that it comes close to experimental values when I plot the data points together with the function. And I do not intend to do that for every data file I have to analyze this way and I just want to know how to do this. I am fully aware that NonlinearFit with that many parameters is non trivial. However I am willing to try it and I think that with a good set of initial parameters I will be successful. Marek >>If You run the code from my previous post You will see how my data >>looks like because I adjusted the parameters in the lists a, b, >>[Delta]L and [Delta]G so that it represents my data quite well. >>However I want to use NonlinearFit (or FindFit) to find the values of >>those parameters which best represent my data. > We are clearly not communicating effectively. I did run your code and was > able to see how the function plots. But this gives me essentially no > information as to what to suggest. > When I asked about your data, I was not interested in a plot of your data > but the structure of the data files. For example, if I were trying to > correlate temperature measurments made in Celsius to temperature > measurments in Fahrenheit, I might have a file that looked like > 50, 122.5 > 60, 140.1 > 70, 158 > 80, 176.2 > 90, 194.3 > Now since I know there is a linear relationship between Celsius and > Fahrenheit I would use FindFit as follows: > FindFit[data, a*T + b, {a, b}, T] > to get > {a -> 1.797, b -> 32.43} > Here data is an array that contains values of the independent variable as > well as the response. And in this particular example, data is set equal > to: > {{50, 122.5}, {60, 140.1},{70, 158}, {80, 176.2}, > {90, 194.3}} > A non-linear problem or multi-dimensional problem is handled identically. > That is I have a data matrix where every row is the values for the > independent variables followed by the response, an expression that says > how the response is obtained from the independent variables, a list of the > symbols used as independent variables and finally the symbol used as the > response variable. > There is no limit to how complex I choose to make the expression relating > independent variables to response save memory, my patience and the number > of distinct data points in the data set. > For example, if I had a suitable number of data points I could have chosen > as my expression relating Celsius to Fahrenheit as say > a*T + T^b + c Log[T] +d > Obviously, this will not result in a meaning fit. And in this particular > case, FindFit may not be able to achieve convergence. > In your case, the expression showing the relationship between a single > independent variable and response could be written as > Voigt[x,a1,b1,dL1,dG1] + Voigt[x,a2,b2,dL2,dG2] + ... > and the corresponding paramater list would be > {a1,b1,dL1,dG1,a2,b2,dL2,dG2,....} > Here I am assuming a data matrix with two columns, the first representing > values for a single dependent variable and the second column the response. > FindFit can be used with more than one independent variable without > difficultly. > However, you described a desire to fit a sum of 15 non-linear functions to > the data. And it is beginning to sound like for each of these you need to > optimize possibly 4 independent parameters. If I have this correct, then > you are likely to be quite fustrated with either FindFit or NonlinearFit. > Fitting non-linear models to data is inherently a difficult problem And > the difficulty increases rapidly with the number of non-linear parameters > that need to be found. With a large number of parameters ot be found, it > will be very difficult to ensure the algortithm used doesn't get trapped > by a local minimum giving a sub-optimum solution. Of course, this issue > can be largely mitigated by giving FindFit a good set of starting points. > One final comment. You say above you adjusted the paramters to give a good > fit to your data. If so, why bother with either FindFit or NonlinearFit at > all? What FindFit will do is provide you with another estimate as to the > values of the parameters you've effectively already estimated by some > other means. The values provided by FindFit or NonlinearFit are likely to > be different than the values you've already obtained and *might* be > considered better under some very specific conditions which often aren't > met by real data. -- To reply via email subtract one hundred and four === Subject: The question of equality,... Ok I thought I understood this stuff but maybe not,... If I wanted to check for bit-for-bit equality of two arbitrary precision numbers (without regard to how many of those digits are meaningful) like the way it would be done using the == operator in C, then correct? For == the 5.1 Appendix A says: Approximate numbers are considered equal if they differ in at most their last eight binary digits (roughly their last two decimal digits). SameQ requires exact correspondence between expressions, except that it considers Real numbers equal if their difference is less than the uncertainty of either of them So what can I use then? Any and all help is much appreciated. Terry