Forum Stats

  • 3,854,724 Users
  • 2,264,413 Discussions


Returning an object from a method


I have built a library of Matrix functions and now I want to test those functions. I have built a simple program to do this, and connected the library to this application. In my program I do the following;-

1 Use a Constructor to create the matrix of the correct size and with a value assigned to each location in the array.

2 Use a library method (matMultTD()), to multiply two matrices together and return a Matrix object.

fitLeft = new Matrix(2, 2, 1);

fitLeft.matMultTD(obsLeft, obsLeft);

I have followed the actions in the debugger and the matMultTD method does what is it supposed to do, but obviously the way that I have linked the Matrix output from the matMultTD method does not work because the fitLeft Matrix retains the original values. What am I doing wrong?



  • dvohra21
    dvohra21 Member Posts: 14,674 Gold Crown

    fitLeft object values won't be modified, just because one of its methods is called. What is the matMultTD method? And why is it called with obsLeft passed as parameter twice?

  • User_27ADD
    User_27ADD Member Posts: 3 Red Ribbon

    Hej dvohra21, Thank you for your response, I appreciate it. I have found that by modifying the method matMultTD and replacing the second line of code above with;-

    fitLeft = obsLeft.matMultTD(obsLeft);

    I get the right answer.

    I have obsLeft twice (or the owning and the passed objects in the revised version) because the method is a general method to multiply the transpose of one 2-D array by a second 2-D array, ie the arrays need to have identical values in their rows but not in their columns.

    But I have a question or comment. I deliberately created the fitLeft matrix to be too large in the constructor above, yet it returned the correct answer. Why is this?

  • dvohra21
    dvohra21 Member Posts: 14,674 Gold Crown

    As no class definitions that include constructor/s and methods/s have been posted it may be a guessing puzzle as to what is being computed with matrices. Please post class definitions including constructor/s and methods/s.