Return a vector from a function?
07-06-2015, 12:55 AM
Post: #1
 norlesh Junior Member Posts: 31 Joined: May 2014
Return a vector from a function?
How can I create a user defined function to map two variables into a vector on the prime?

i.e. something along the lines of:

defvect(angle, magnitude):=[magnitude*cos(angle), magnitude*sin(angle)]

but that works.
07-06-2015, 07:44 AM
Post: #2
 norlesh Junior Member Posts: 31 Joined: May 2014
RE: Return a vector from a function?
OK so I solved my task by making it a program

Code:
 EXPORT DEFVECT(mag,ang) BEGIN    RETURN([mag*COS(ang),mag*SIN(ang)]); END;

But that really feels like tapping an exposed nail head with a sledge hammer. Is there no way to return a vector or matrix from the 'Define' window?
07-06-2015, 09:45 AM (This post was last modified: 07-06-2015 09:46 AM by Didier Lachieze.)
Post: #3
 Didier Lachieze Senior Member Posts: 1,446 Joined: Dec 2013
RE: Return a vector from a function?
Here is a way to return a vector from a User Defined function (a bit cumbersome but it seems to work…):

But in your case it's much more simpler to use the existing rectangular_coordinates() function:

07-06-2015, 10:21 AM (This post was last modified: 07-06-2015 10:25 AM by DrD.)
Post: #4
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Return a vector from a function?
By using a list first, try this function, which will create the variables M0, mag, and ang. (Uncheck the [M0]):

[Shift] [Define]
NAME: defvect
Function: M0:=list2mat({mag*COS(ang), mag*SIN(ang)})

M0:[ ] mag:[] ang:[ ]

oops, I see Didier beat me to it!
07-06-2015, 12:00 PM
Post: #5
 norlesh Junior Member Posts: 31 Joined: May 2014
RE: Return a vector from a function?
Thanks to both of you for the solution and pointing out the built in function.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)