Re: Related quastions. Question 2
- To: mathgroup at smc.vnet.net
- Subject: [mg57531] Re: [mg57499] Related quastions. Question 2
- From: "David Park" <djmp at earthlink.net>
- Date: Tue, 31 May 2005 04:59:58 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Vlad, Some users don't like to use % and %% statement references because they do not work if the cells are not evaluated in the correct order. I agree with that, but in the example I gave below all the statements were within a SINGLE cell and refer to other statements within the SAME cell, so there is no possibility that they won't be evaluated in the correct order. This is a good way to do a calculation because you can keep adding and modifying until you get what you want. There is no problem in evaluating the cell over and over. If you don't want the Print statements you can just leave them out. (I often find them useful to make it clear what is being done at each step.) Sometimes when using several steps to get a result I put a ";" after some of the steps to suppress that output. If you wish, you can also give intermediate output names (like step1 =..., step2 =..., et ceteria) and then refer to them by name. Provided the individual steps evaluate quickly, this is an extremely convenient method for carrying out a calculation. You can see exactly what is happening and yet everything is in a single cell. If some step takes a long time, then you may wish to give a name to the output and end the cell there. Then you can continue on with a new cell starting with the intermediate name. If you want the same thing done to both sides of an equation, why not just Map the function to both sides as I did? equation = a x + b == c; step1 = # - b & /@ equation a x == -b + c solution = Distribute[#/a] & /@ step1 x == -(b/a) + c/a if that's the form you want. But I find it easier to have as much as I can in one cell because if I make a mistake at an early stage I can just correct it and do one reevaluation of the cell. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Kazimir [mailto:kazimir04 at yahoo.co.uk] To: mathgroup at smc.vnet.net Dear Bob, you gave the example Print["Equation to solve for x"] a x + b == c Print["Subtract b from each side"] # - b & /@ %% Print["Divide each side by a"] #/a & /@ %% It works but i do not like very much expressions with %%, as I should not insert more lines before it or I have to modify this symbol. I would like to start with expr= (a x + b == c) and then make a transform like expr1 = expr - b. It clearly does not work. Could you advise me a mathematical operartion over expression which would return a x == c - b . The best thing I found was expr = (a x + b == c) Distribute[#1 - b &@expr, Equal] however, it does not work in all cases that I need. Vlad