Skip to main content
1-Visitor
December 11, 2015
Solved

"This Value Must be a Matrix of Scalar Elements" (M15)

  • December 11, 2015
  • 6 replies
  • 5987 views

In attempting to get the final function in the worksheet (under the heading "Lay Out PSO Algorithm and Find Best Results) to work, I am running into some problems.  It will take some looking into, certainly, but Mathcad is saying that I'm not giving it scalar elements for the function "StressPenalty."  If anyone could help me figure out why this is the case, I'd appreciate it (this code closely follows one that I know to work properly.  It should work as it is).

Best answer by Werner_E

Just a few "maybe's":

  1. Maybe the for loop should be inside an "otherwise" statement. This should at least make the routine work.

    You could also "return" to stop the routine if Phi is just a one column vector
  2. Maybe the loop for nn should run up to N, not just up to N-1 so the function does return 50 column matrices ab bot just 49 column ones.
  3. This is an alternative to 2. Let the ii-loop in the last routine which calculates A.opt an Phi just run up to N-1. I guess that 2. is more appropriate

Using 1. and 2. and providing a range variable for plotting I get

WE

6 replies

25-Diamond I
December 11, 2015

Right click here

and change from "Square Matrix Determinant" to "Absolute Value".

Now we get an index out of range error a line above  because sigma.N only hase 8 rows and not 10.

Werner

1-Visitor
December 11, 2015

Thank you.  I got past all of that, but now it's telling me I'm not providing a vector just a couple of lines below the previous issue.  I am on the verge of being done with this code, as this is basically the last function, but it's just giving me fits.

issue.PNG

19-Tanzanite
December 11, 2015

In the LocalBest function you define indx as the first value in the vector returned by match, so it's a scalar. In the next line you call index with a vector subscript of 2.

If you get rid of the 2 then you get another error because you pass phi to LocalBest, but after the first iteration phi is a matrix, not a vector. Pass column kk of phi to LocalBest and the program calculates. I can't say whether it gives the correct results though.