Return a vector from a function? - Printable Version +- HP Forums ( https://www.hpmuseum.org/forum)+-- Forum: HP Calculators (and very old HP Computers) ( /forum-3.html)+--- Forum: HP Prime ( /forum-5.html)+--- Thread: Return a vector from a function? ( /thread-4306.html) |

Return a vector from a function? - norlesh - 07-06-2015 12:55 AM
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. RE: Return a vector from a function? - norlesh - 07-06-2015 07:44 AM
OK so I solved my task by making it a program Code:
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? RE: Return a vector from a function? - Didier Lachieze - 07-06-2015 09:45 AM
Here is a way to return a vector from a User Defined function (a bit cumbersome but it seems to work…): [attachment=2273] But in your case it's much more simpler to use the existing rectangular_coordinates() function: [attachment=2274] RE: Return a vector from a function? - DrD - 07-06-2015 10:21 AM
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! RE: Return a vector from a function? - norlesh - 07-06-2015 12:00 PM
Thanks to both of you for the solution and pointing out the built in function. |