cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

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

mferguson-2
1-Visitor

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

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).

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:mferguson-2)

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

View solution in original post

6 REPLIES 6
Werner_E
25-Diamond I
(To:mferguson-2)

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

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

RichardJ
19-Tanzanite
(To:mferguson-2)

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.

Werner_E
25-Diamond I
(To:mferguson-2)

The error occurs here:

match()  returns a  vector, in your case containing just a single value (1), a 1x1 matrix.

"indx" is assigned the first element of this "vector" which is just a regular integer - with your data its the number 1.

But in the next line "indx" is treated as vector (which it isn't) and the (none existing) second element of this vector is addressed.

BTW, did you know that you can right click an erroneous expression and then select "Trace Error" to see where the error stems from?

WE

Werner_E
25-Diamond I
(To:mferguson-2)

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

Thank you!  I realize now that it should've been in the otherwise loop.  Gosh what a simple fix.  I did know about Trace Error but usually don't find it to work too consistently.  Would have helped in this case.

Announcements

Top Tags