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

Matrix as an output of a function

  1. Jun 21, 2011 #1
    Hi guys

    I am new to matlab. I have a question in how to pick up matrix elements as a output of a function.

    Code (Text):
    function result=test(E)
    result=[1,2,3;4,5,6]*E;
    For each E, test(E) will generate a 2x3 matrix.
    I wonder how to pick up the matrix element,say test(2)(1,3).
    When I type test(2)(1,3), it shows
    ??? Error: ()-indexing must appear last in an index expression.
    So how can I pick up the matrix element?
    Thank you.
     
  2. jcsd
  3. Jun 21, 2011 #2
    Code (Text):

    x = test(1);
    x(1,3)
     
     
  4. Jun 21, 2011 #3
    Thank you a-tom-ic.
    So I need other space to save the matrix first.
     
  5. Jun 21, 2011 #4
    But here comes the other question.
    I need to integrate test(E)(1,3): int(test(E)(1,3),E1,E2).
    If I set x=test(E), then int(x,E1,E2) will be problematic as shown "Undefined function or variable 'E'.
    Is any way to solve this problem? Thank you for help.
     
  6. Jun 22, 2011 #5
    HI Phynewb,

    i'm sorry i don't understand what your trying to do! Supply more information on your variables and the task. What is E? The int-Function is symbolic toolkit isn't it?
    Code (Text):

    syms E;
    int(E)
    int(E,1,2)
     
     
  7. Jun 22, 2011 #6
    Thanks a-tom-ic.

    Say, f1(E),f2(E),f3(E) are three functions. Here E is real number and the outputs are nxn real matrices.
    Define F(E)=f1(E)*f2(E)*f3(E). So E is also an number and output is a matrix.
    The purpose is to calculate the integration of F(E)(a,b) over E from E0 to E1. Here F(E)(a,b) means the (a,b) matrix element of F(E) and it is a number:
    int(F(E)(a,b),E0,E1).

    As you said, I cannot pick up the (a,b) element by F(E)(a,b). I have to save it as other variable, say G. Let G=F(E) and then take G(a,b).
    But once you save it as other variable, how can I do the integration? Because G has no E-dependence.
    int(G(a,b),E0,E1) is problematic!
    I wonder if anyway to solve the problem.
    Hopefully I explain it clearly.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matrix as an output of a function
  1. Matrix Output (Matlab) (Replies: 1)

Loading...