Re: Re: Adding Vectors -- Newbie help please

*To*: mathgroup at smc.vnet.net*Subject*: [mg52042] Re: [mg52023] Re: Adding Vectors -- Newbie help please*From*: "David Park" <djmp at earthlink.net>*Date*: Mon, 8 Nov 2004 03:13:26 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

Mathematica is not so much a toolbox for doing mathematica but a metatoolbox for making the tools to do the mathematics that applies to your specific application. This means that one will almost always have to write definitions and routines to make Mathematica work efficiently for oneself. This is a beautiful example. One might think that Mathematica would have a routine to do this. But there are millions of similar routines that might apply to this and other applications. You want to input in degrees, someone else in radians. Then aren't there other units of angular measure, like multiples of 90 degrees, or Arc Minutes and Arc Seconds? Maybe someone wants {voltage, degrees, minutes, seconds}. Or maybe they want voltage last on the list. So just build up the routines that you need. Here are some possible routines for your application. Put them in a Routines Section in your notebook. Maybe later you might even make a package. RectangularToPolar[{x_, y_}] /; x == 0 \[And] y == 0 := {0, 0} RectangularToPolar[{x_, y_}] := {Sqrt[x^2 + y^2], ArcTan[x, y]180/Pi} PolarToRectangular[{r_, theta_}] := {r Cos[theta Pi/180], r Sin[theta Pi/180]}; PolarAdd[voltages : {_, _} ...] := Fold[RectangularToPolar[ PolarToRectangular[#1] + PolarToRectangular[#2]] &, {0, 0}, {voltages}] Now, having defined the routines they are easy to use. v1 := {220.0, 225}; v2 := {100.0, 16}; PolarAdd[v1, v2] {141.127, -114.908} PolarAdd[{220., 0}, {220., 30}, {220., 60}] {601.051, 30.} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: motz art [mailto:music at heart.com] To: mathgroup at smc.vnet.net Ok; but I was hoping that there is a simpler way than the following method to add two ac voltage vectors (for example): (220V, 225 degrees) (100V, 16 degrees) Clear[r, x, y, Theta, rect, polar] rect[r_,Theta_] := { r Cos[Theta Pi/180] , r Sin[Theta Pi/180]} polar[x_, y_] := {Sqrt[x^2 + y^2], ArcTan[x, y]180/Pi} (* Input vectors here *) v1 := {220, 225}; v2 := {100, 16}; r1:= rect[v1[[1]], v1[[2]] ] // N; r2:= rect[v2[[1]], v2[[2]] ] // N; rt := p1 + p2 polar[rt[[1]], rt[[2]]] // N This just seems so cumbersome, especially when compared to a scientific calculator. On Sat, 6 Nov 2004 07:36:05 +0000 (UTC), David Bailey <dave at Remove_Thisdbailey.co.uk> wrote: >motz art wrote: >> Mathematica v5: How can I input vectors in polar form and >> rectangular form? >> >> Example: >> >> a:= (r1, theta1) + (r2, theta2) Polar form. >> >> b:= (re1 , j* im1) + (re2, j*im2) Rectangular form >> >> I know this should be pretty basic, but I haven't found examples >> of this kind of input. >> >> I would guess it would be something like: >> >> Polar[magnitude, phase] >> Rectangular[Real, Imaginary] >> >> but, apparently not. (This is for electronics engineering.) >> >> Thanks for any help. >> >> >> >> >> >You can easily write a function to convert from polar to coordinate form: > >FromPolar[r_, theta_] := {r Cos[theta], r Sin[theta]} > >Note that this assumes your angles are measured in radians. Once all >your vectors are in coordinate form you can add/subtract then directly: > >{1,2}+(3,4} > >produces > >{4,6} > >Regards, > >David Bailey