Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Array and Trig. Functions

  1. Feb 3, 2008 #1
    Hi guys,

    I am having a problem here with a matlab m.file, I am trying to take the inverse tangent of an array and expect from this function to get another array, but for some reason I don't get an array just a single number.

    Any matlab guru that could help me with this problem?

  2. jcsd
  3. Feb 3, 2008 #2

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    arctan isn't an intrinsic matrix function. You have to calculate each element sparately.
  4. Feb 3, 2008 #3
    Thanks for the help
  5. Feb 3, 2008 #4
    arctan is not a built-in Matlab function, but atan(x) and atan2(x,y) both are, and they both take arrays for input arguments.
  6. Feb 4, 2008 #5
    Really? Because my input was an array an I just got a single number, not an array. There's something that I could do to get an array?
  7. Feb 4, 2008 #6
    Your input for which function? As I said, arctan is not built-in, so I can't guess how it would behave; that would depend on how it was written.

    Here are simple examples of the other two:

    Code (Text):
    >> theta = atan([.1 .2 .3 .4])

    theta =

        0.0997    0.1974    0.2915    0.3805

    >> theta = atan2([1 2 3 4],[10 10 10 10])

    theta =

        0.0997    0.1974    0.2915    0.3805
  8. Feb 5, 2008 #7
    I use atan(), common I would notice if is not a built in function.

    My array was stored on a variable then I tried to take the atan of the variable an expected an array.
  9. Feb 5, 2008 #8
    I don't understand this sentence.

    Are you asking how to tell if a function is built-in? Use "which", as in

    >> which atan

    which will return the location of the function's m-file, or it might simply say that the function is a pre-compiled function, i.e. it has no m-file.

    You should get back an array of the same dimensions, as in this example:

    Code (Text):
    >> M = [.1 .2 .3
            .4 .5 .6 ];
    >> atan(M)

    ans =

        0.0997    0.1974    0.2915
        0.3805    0.4636    0.5404
  10. Feb 7, 2008 #9
    I ran again the m-file and got the array I was looking for, maybe one of my inputs were wrong.

    By that sentence that I wrote, sorry... for some reason my English is getting worse. What I tried to say is that I used atan() and not arctan, that will note by the "??? Undefined command/function 'arctan'" message that is not a matlab function.

    Thanks for the help belliott4488

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Array and Trig. Functions
  1. Functions and arrays. (Replies: 1)