mm-326 == I have an uneven matrix / 0 0 aa= | 0 0 0 | 0 0 / I want to fill the empty spaces with 0's, how do I do that. thank you Subject: eliminate the 2 in binary when displaying numbers in binary how do I eliminate the 2's when displacing 3 in binary the output is 0100 2 I want the 0100 without the 2 Thank you. Subject: need help with writing algorithm for polynomial gcd! I know MATHEMATICA has a built in function to computer the polynomial GCD ... but: what if I need to write a small M-program that does the following: given two polynomials in the form [a0,a1, ..., ak], [b0,b1,...bj] - i.e. coefficients only now compute the polynomial gcd (we only consider real numbers, no finite fields or evil stuff...! ... that is the good part!) what would be an efficient algorithm to do this? note: the GCD / polynomialGCD function of MATHEMATICA must not be used, other built-in functions, even for polynomials, are allowed! a lot for any assistance, I have googled long without success! <<< Tina > -- Controller: I know but this guy has no ßying experience at all. He's a menace to himself and everything else in the air... yes, birds too. (ÔAirplane!', 1980) Subject: Re: Reordering Downvalues? > you do nothing wrong, but Mathematica orders the patterns by itself > to ensure that more special patterns are applied first and this > happens in your case. I feared that this was the case - book section 2.5.7 is pretty clear on it, but 2.5.13 gives explicit instructions on how to change the order. It isn't helpful that the order doesn't matter in the example they use. Not being able to change the *Value order doesn't bother me as much as the cheerful way that Mathematica takes the instruction then doesn't do anything. Some kind of message would have been nice. Fred Klingener Subject: Re: a question about [[ ]] Possibly Ted Ersek's HoldTemporary package will satisfy. You can find that at MathSource: http://library.wolfram.com/infocenter/MathSource/705/ Needs[Ersek`HoldTemporary`] Clear[f, g] f[{x_, y_}] := {f[x], f[y]} g[x_] /; Length[f[x]] > 1 := {f[x][[1]], f[x][[2]]} g[x_] := HoldTemporary[Take[f[x], 2]] (* or g[x_] := HoldTemporary[{f[x][[1]], f[x][[2]]}] *) g[a] {f[a][[1]], f[a][[2]]} g[{x, y}] {f[x], f[y]} f[a_] := {a, a^2} g[a] {a, a^2} g[{x, y}] {{x, x^2}, {y, y^2}} There's not a lot you can DO with g[a] while f[a] is undefined, but HoldTemporary has options that may help. Bobby > here is what I am trying to do: g is a function that invokes f. > f[x] is undefined, > while f[{x,y}] returns a list, say {f[x],f[y]} (or any other list). > Assume > f[{x_, y_}] := { f[x], f[y] } > and > g[x_] := {f[x][[1]], f[x][[2]]} > I would like to have In := g[a] > Out:= {f[a][[1]], f[a][[2]]} and In := g[{b,c}] > Out:= {f[b], f[c]} > Rationale: function g has the knowledge that f iv evaluated return a list. > If f is not evaluated I want the symbolic expression to be returned. > The problem is the first case: g[a]. > I cannot prevent Mathematica from evaluating f[a][[1]] > returning the unwanted a. > For f[a][[2]] the situation is slightly better because after the mesg > Part::partw: Part !(2) of !(f[a]) does not exist. > Mathematica return the unevaluated expression f[a][[2]]. > Basically I would like Mathematica to evaluate (Something)[[ ]] > only is Something is a list and leave everything symbolic otherwise. > for any suggestion. Subject: Re: How to set y always greater than or equal to x for a function? That works great, this is just a quibble, but... Turning a Rule into a function and using MapAt seemed distasteful to me, so I came up with an equivalent solution, learning a thing or two in the process: f[x_, y_] := If[y > x, Sqrt[y - x], 0] plot1 = Graphics3D@Plot3D[f[x, y], {x, -100, 100}, {y, -100, 100}, DisplayFunction -> Identity]; rule = {x_?NumberQ, y_?NumberQ, z_?NumberQ} /; y ? x -> Sequence[]; plot2 = Head[plot1][First@plot1 /. rule, Sequence @@ Rest@plot1]; Show[plot2, DisplayFunction -> $DisplayFunction]; Bobby > Albert, I think this is an interesting plotting problem whose solution is not > totally obvious. If you are just beginning to learn Mathematica, then it is > probably not the first problem to tackle. Plot3D[Sqrt[y - x], {x, -100, 100}, {y, -100, 100}]; gives warning messages and a jagged edge to the surface. We could define a function f[x_, y_] := If[y > x, Sqrt[y - x], 0] Then Plot3D[f[x, y], {x, -100, 100}, {y, -100, 100}]; works more or less. But it has the extra xy-plane surface, which is not part > of the surface you are specifying. A few years ago I learned the following trick from MathGroup. (I can't > remember exactly who posted it.) Generate the plot above and then throw out > all points that have y <= x. plot1 = Graphics3D@ > Plot3D[f[x, y], {x, -100, 100}, {y, -100, 100}, > DisplayFunction -> Identity]; plot2 = MapAt[# /. {x_?NumberQ, y_?NumberQ, z_?NumberQ} /; y <= x - Sequence[] &, plot1, 1]; We had to convert the plot from SurfaceGraphics to Graphics3D. We had to map > our function onto the first part of plot1. The first part contains all the > primitive graphics for the surface. Any point in a Polygon for which y <=x > gets replaced by Sequence[], which effectly gets rid of it. We then Show the > new plot. Show[plot2, DisplayFunction -> $DisplayFunction]; That gives a pretty good representation of the surface. The DrawGraphics package at my web site gives some other techniques for > handling plotting problems of this type. One of its advantages is that it > automatically extracts the primitive graphics from any plot and it is then > easy to manipulate or combine the various elements. Needs[DrawGraphics`DrawingMaster`] The following implements the same trick as above. Module[{g}, > g = Draw3D[f[x, y], {x, -100, 100}, {y, -100, 100}]; > Draw3DItems[ > {g /. {x_?NumberQ, y_?NumberQ, z_?NumberQ} /; y <= x -> Sequence[]}, > BoxRatios -> {1, 1, 1/2}, > Axes -> True]]; Another method is to reparametrize the surface. If we were going to > integrate a two variable function we could use > Integrate[f[x,y],{x,-100,100},{y,x,100}]. The second iterator depends on x. > But we can't directly do that when plotting surfaces. DrawGraphics has the > command IteratorSubstitution[{y, Sqrt[y - x]}, {y, x, 100}] > {{(-w)*(-100 + x) + x, Sqrt[(-w)*(-100 + x)]}, {w, 0, 1}} It reparametrizes y and Sqrt[y-x] for {y,x,100} in terms of x and w. w has > the fixed iterator {w,0,1}. We can then plot this new function and then use > DrawingTransform3D to get back from the xw-plane to the xy-plane. Draw3DItems[ > {Draw3D[Sqrt[(-w)*(-100 + x)], {x, -100, 100}, {w, 0, 1}] /. > DrawingTransform3D[#1 & , (-#2)*(-100 + #1) + #1 & , #3 & ]}, BoxRatios -> {1, 1, 1/2}, > Axes -> True, > Background -> Linen, > ImageSize -> 450]; But this isn't too nice for this particular case because the polygons are > crimed together at one corner. Another idea is to plot the function Sqrt[y], where we can use fixed ranges > and then rotate it by 45 degrees. I plot it in two sections to get a better > representation of the rising section. Draw3DItems[ > {{Draw3D[Sqrt[y], {x, -150, 150}, {y, 0, 2}, PlotPoints -> {25, 2}], > Draw3D[Sqrt[y], {x, -150, 150}, {y, 2, 150}, PlotPoints -> 25]} // > UseRotateShape[-45Á, 0, 0]}, > BoxRatios -> {1, 1, 1/2}, > PlotRange -> {{-100, 100}1.01, {-100, 100}1.01, {-0.1, 15.1}}, > Axes -> True, > Background -> Linen, > ImageSize -> 450]; This is probably a little nicer than the non DrawGraphics plot because the > mesh lines are either level, or the sqrt curves. As an extra, here is the same surface combined with -Sqrt[y-x] and then spun > around for better viewing. g is just the primitive graphics for the surface > we plotted above. We draw it and then we draw it again with the z component > reversed. plot3 = > Module[{g}, > g = {Draw3D[Sqrt[y], {x, -150, 150}, {y, 0, 2}, PlotPoints -> {25, > 2}], > Draw3D[Sqrt[y], {x, -150, 150}, {y, 2, 150}, PlotPoints -> 25]} > // > UseRotateShape[-45Á, 0, 0]; > Draw3DItems[ > {g, > g /. DrawingTransform3D[#1 &, #2 &, -#3 &]}, > BoxRatios -> {1, 1, 1}, > Boxed -> False, > PlotRange -> {{-100, 100}1.01, {-100, 100}1.01, {-12.1, 12.1}}, > Background -> Linen, > ViewPoint -> {1.779, -2.844, 0.447}, > ImageSize -> 450]]; SpinShow[plot3] > SelectionMove[EvaluationNotebook[], All, GeneratedCell] > FrontEndTokenExecute[OpenCloseGroup]; Pause[0.5]; > FrontEndExecute[{FrontEnd`SelectionAnimate[200, AnimationDisplayTime -> 0.1, > AnimationDirection -> Forward]}] David Park > djmp@earthlink.net > http://home.earthlink.net/~djmp/ I recently purchased Mathematica 5.0, and I am in the process of > learning how to take advantage of it's many features. This is an example of one line I would like to calculate in Mathematica: Plot3D[Sqrt[y-x],{x,-100,100},{y,-100,100}]; > How can I best edit this line to make y always greater than or equal to x > during > calculation so the program doesn't try to take the square root of a > negative number? Any help will be appreciated. Albert Franco Subject: Re: Any way to display vars internal to a function on interrupt? Yes, I often compute primes of a particular characteristic, say 9^n+2. I will write Do[ m=n; If[ PrimeQ[ 9^n+2], Print[n]], {n, 1, 10^6}] and leave it running overnight. The next morning, I will interrupt the program and ask for the value of m. The iterator Ôn' is not retrievable directly. Bob. > Is there any plausible way to display the current state of the > internals of a user defined function when I've interrupted the > kernal evaluation? V 5.0 > Subject: RE: Question about Integrate and If Hi Antonio, > Integrate[1/x, {x, a, 2*a}, Assumptions -> a != 0] Integrate[1/x, {x, a, 2 a}, Assumptions -> {Element[a, Reals]}] returns Log[2]. Dave. Subject: Re: Saving Kernel Status what may DumpSave[] do .. save a dump of the kernel ?? to a file in internal Mathematica format. DumpSave[file.mx, context`] out definitions associated with all symbols in the specified context. several symbols or contexts. DumpSave[package`, objects] chooses the name of the output file based on the computer system used. DumpSave[file] saves all definitions in the current session. Regards Jens Hi there, unforunately, google couldn't help me on this question: Is there a way, to dump the status of the kernel to a file, shut down the > computer and restart it later in exactly the same status (i.e. variables > having same values, etc.)? in advance for your help, > Florian Subject: Re: Matrix Element Extraction I realy love your code but Select[Position[mat, _Integer], Length[#] == 2 && MemberQ[#, 3] &] may do what you want not only _mostly_ but it is not so wonderful cryptic :-( Regards Jens In a matrix, I want to find the positions of all the integer elements in the > rightmost column or the bottom row. In[1]:= > mat={{1,2,1},{4,5,6},{7,8,-Infinity}} Out[1]= > {{1,2,1},{4,5,6},{7,8,-Infinity}} In[2]:= > Position[Map[((MemberQ[Union[Flatten[{mat[[Length[mat]]], > mat[[All,Dimensions[mat][[ > 2]] ]]}]],#])&&(#!=-Infinity))&,mat,{2}],True] Out[2]= > {{1,1},{1,3},{2,3},{3,1},{3,2}} This _mostly_ does what I want, but took me forever to think of. I'm > convinced there must be an easier way... Especially, is there an easy way to keep the point {1,1} from appearing on > this > list, other than using a replacement rule and an If[] command? ({1,1} is > not a position in the bottom row or right most column, so I don't want this > point returned.) for any advice. -- > Curt Fischer Subject: Summation limits I want to do a summation, using the symbol form from clicking on the palette button, but want to put a test on the index of the iterator. for example, I will have global variables, k=5 and p = 2, and want to do a summation from i=1 to k, where i != p. How do I enter the lower limit i=1;i!=p ? I realize that I can just wrap the expression being summed in an If[i!=p, ...], but it would be nice if I could just put this test in the lower limit. doug Subject: Try this by support1.mathforum.org (8.11.6/8.11.6/The Math Forum, $Revision: 1.9 primary) id i26FVJv17580; Eric, I suggest that you hook up a Vector 9 wave port with a 247 compression valve. That way you can conduct a circular BTL stream and, therefore, more accurately assess each variable. Let me know if you have any other questions. Bill Subject: Boundary Value Problem by support1.mathforum.org (8.11.6/8.11.6/The Math Forum, $Revision: 1.9 primary) id i26FVLx17616; I'm not sure I can explain this very well. I need to write a program that solves a BVP by finite differences. I have done this sort: -u''(x) + c(x)u(x) = f(x) ( u(0) = gamma0, u(N) = gamma1) with an appropriate gamma0 and gamma1. When solving this, I end up with a matrix A (I hope someone knows what I'm talking about) which looks like this for one line: (-1 2+c(x)*h^2 -1 )u = f I would like to know what the Matrix A looks like when solving a general boundary value problem: -(a(x)u'(x))' + c(x)u(x) = f(x) Please someone help me! Subject: Re: Boundary Value Problem > I'm not sure I can explain this very well. > I need to write a program that solves a BVP by finite differences. > I have done this sort: -u''(x) + c(x)u(x) = f(x) ( u(0) = gamma0, u(N) = gamma1) > with an appropriate gamma0 and gamma1. When solving this, I end up with a matrix A (I hope someone knows what > I'm talking about) which looks like this for one line: > (-1 2+c(x)*h^2 -1 )u = f > Here it is typical to use the centered difference for u'' u'' ~( u(i+1)-2*u(i)+u(i-1) )/h^2 > I would like to know what the Matrix A looks like when solving a > general boundary value problem: -(a(x)u'(x))' + c(x)u(x) = f(x) > I have done such a problem in a diffusion context: -q'(x)=f(x) ßux: q = -a(x)*u'(x) diffusivity: a(x) ( your equation, -q'(x) + c(x)*u(x) = f(x), would be a reaction-diffusion) In this case a conservative finite difference approach is typically used: q'(x) ~ (q(i+0.5) - q(i-0.5))/h -q(x) ~ a(x)*(u(i+0.5)-u(i-0.5))/h (This is also called cell centered finite differences, since the ßux is computed at cell interfaces i+/-0.5, and also finite volume ) Putting it together, you get q'(x) ~ [a(i+0.5)*(u(i+1)-u(i)) - a(i-0.5)*(u(i)-u(i-1))]/h^2 Which reduces to the standard case, for a constant coefficient, a, and ßux is conserved in the general case. You should be able to see how to get to the matrix form easilly from this. Linear interpolation is typically used for interface diffusivities a(i+0.5) ~ ( a(i+1)+a(i) )/2 a(i-0.5) ~ ( a(i-1)+a(i) )/2 HTH, Matt Subject: Re: Boundary Value Problem I'm not sure I can explain this very well. > I need to write a program that solves a BVP by finite differences. > I have done this sort: -u''(x) + c(x)u(x) = f(x) ( u(0) = gamma0, u(N) = gamma1) > with an appropriate gamma0 and gamma1. When solving this, I end up with a matrix A (I hope someone knows what > I'm talking about) which looks like this for one line: > (-1 2+c(x)*h^2 -1 )u = f Don't forget h^2 on the right-hand side! > I would like to know what the Matrix A looks like when solving a > general boundary value problem: -(a(x)u'(x))' + c(x)u(x) = f(x) The answer to your question depends on the difference formula employed. By the product rule (assume a is once differentiable): -au'' - a'u' + cu = f Using central differences, we could write: u' ~ (u_{i+1} - u_{i-1})/2h + O(h^2) however this technique is notorius for generating matrices A which are not diagonally dominant. You can also use a backward or forward difference: u' ~ (u_{i+1} - u_{i})/h + O(h) u' ~ (u_{i} - u_{i-1})/h + O(h) However this technique has a lower order of accuracy than the central difference method. You might find more info by googling for finite difference convection diffusion and see what pops up. Hope that helps, John -- Remove net. to send mail. ! Subject: Re: Nonlinear curve fitting help needed There is a shareware program called NLREG which you can download and try. It will give you all of the results you request. Do a www search for it and you will find a download site. Danny > First, I am not a mathematician (clearly)- its been too long since I took > calculus! > Second this is -not- homework > I need to fit a curve to a data set so that I can interpolate potential > points. > For example, if I have: > x = {100, 130, 135, 150, 164, 180, 300, 310 } > y = {20, 25, 27, 35, 34, 45, 30, 28 } > I need to fit a loose Ôbest fit' curve so that given an x of 200 (for > example) I can give a realistic estimate of what y should be. > I also need to be able to adjust how Ôtightly' the curve fits the data > points. For example, if the curve fits too tightly on the data, then > somewhere between 180 and 300 on the x axis the y will either approach or > become 0, which is wrong for my purposes. > I need to implement this in C++, so I need the formulas and calculations to > use, if all I have to start with are my x[] and y[]. > Can anyone either help out directly or point me to a good site that will > help me out? Bryan Subject: Re: How many algebraical operations for Matrix inverse and multiplication? In sci.math.num-analysis, Michel OLAGNON : >>In sci.math.num-analysis, Fred >>: > Dear all, > Sorry to bother you for a stupid question. > Assume there is an nxn matrix A and nxm matrix B, > to calculate inverse matrix of A, i.e. inv(A), how many > algebraical operations (product, addition, subtraction, etc.) are needed? >>There are several methods of computing inv(A); the most general >>involves cofactor(A) / det(A), which involves the computation >>of an nxn determinant and n^2 (n-1)x(n-1) determinants, >>with half of them ßipping sign. > most general can mean anything. Here, you make it mean most stupid. > First, one should compute matrix inverses only in a very > few exceptional cases. The problem as stated by the OP required it (it is far from clear whether one has to expose A^-1 or not; I assumed that he did want to do such). But you're right, this is the stupid fashion. I can establish an upper bound by this method but that's all. > But assuming one really needs it, > it can be done by solving AX = B with multiple right-hand > sides B as the columns of I. This uses n times O(n^2) > operations, using, for instance, gaussian elimination. > Note that it may not be very smart to solve AY = I, and then > to multiply Y by B to get the solution of AX = B when it can be solved > directly the way above... An interesting point, which can shortcut the problem -- though it depends precisely on what the problem is. [rest snipped] -- #191, ewill3@earthlink.net It's still legal to go .sigless. Subject: Re: How To Solve An Exponential Equation (Bleasdale Model) I have 3 data points, where x=1,2,3, and y3>y2>y1 I am trying to fit these to the Bleasdale Model, where: y=(a+bx)^(-1/c) I arrive at the folllowing equation, where p, q, and r are known, and > I need to solve for B: (1+B)^p*(1+2B)^q*(1+3B)^r=1 How can I solve for B? If it helps, B is always between 0 and 1 for > my application. Jim Are p, q and r all positive or all negative? If so, B = 0 . Only if one of the exponents has the opposite sign from the others is there a non-trivial root. Does this help? -- Julian V. Noble Professor Emeritus of Physics jvn@lessspamformother.virginia.edu ^^^^^^^^^^^^^^^^^^ http://galileo.phys.virginia.edu/~jvn/ God is not willing to do everything and thereby take away our free will and that share of glory that rightfully belongs to us. -- N. Machiavelli, The Prince. Subject: Re: equation II buuu !!!!!! y' = _3 * y^(3/2) +1 > y(0) = 1 can someone plz tell me what is the resalt for this eqation? or at least > what method should i use ? thx in advance:) > Kasia The equation can be reduced to an integral by separation of variables. ^^^^^^^^^^^^^^^^^^^^^^^ Look that topic up in any book on ode's. The resulting integral is a bit hard, but can be cone by changing variables and using partial fractions. Any 1st year calculus book should tell you how to do that. -- Julian V. Noble Professor Emeritus of Physics jvn@lessspamformother.virginia.edu ^^^^^^^^^^^^^^^^^^ http://galileo.phys.virginia.edu/~jvn/ God is not willing to do everything and thereby take away our free will and that share of glory that rightfully belongs to us. -- N. Machiavelli, The Prince. Subject: Re: Infinitely(?) Stiff Differential Equations > Lots of physics books solve ode's with discontinuous coefficients or > even delta-functions in the coefficients. Basically what you do is > integrate by hand in a small region around the bad point, then use > boundary conditions to join the solutions. Why not use the Laplace transform instead? It is, of course, equivalent > but a more straightforward way to obtain the solution. For example, y'' + ( k*2 - A*delta (x) ) * y = 0 That should be k^2. Yes. The main problem with Laplace transforms is that they only work for cases with constant coefficients (or sometimes when the coefficients are simple functions). They are not exactly ideal for the general case. Thus, e.g., if the original equation had been y'' + ( k^2 - A*delta (x) -u(x) ) * y = 0 where u(x) is some continuous function, you would have a problem. Moreover, I placed the discontinuity at x=0, assuming one wanted the solution for both x>0 and x<0. One would either need the two- sided Laplace transform or else to shift the point of discontinuity as you did. IIRC, the two-sided Laplace transform is discussed in A. Erdelyi's little book, Operational calculus and generalized functions (Holt, Rinehart and Winston, New York, 1962), as well as in B. Van der Pol & H. Bremmer, Operational calculus based on the two-sided Laplace integral (Cambridge U. Press, Cambridge, 1955). -- Julian V. Noble Professor Emeritus of Physics jvn@lessspamformother.virginia.edu ^^^^^^^^^^^^^^^^^^ http://galileo.phys.virginia.edu/~jvn/ God is not willing to do everything and thereby take away our free will and that share of glory that rightfully belongs to us. -- N. Machiavelli, The Prince. Subject: Re: Stability of multisteps schemes > Hello! > I found in Prof. John Strikwerda's book Finite Difference Schemes and > Partial Differential Equations theorems about stability of multisteps > schemes (theorem 4.2.1 and 4.2.2.). But unfortunately for me there are > not proofs ot those theorems, but only sketches. I was looking for > this proofs in other books, but only book of Prof. Strikwerda includes > those theorems. > Maybe someone knows where can I find this proofs? > Any help would be very grateful. > John Maly You may try this reference. It contains a technical treatment of multistep methods. I had a tough time finding it at the library, however, since BIT was not so well-known in the Ô60s. Dahlquist, G. (1963) A special stability problem for linear multistep methods, BIT, vol 3, p 27-43. Hope that helps, John