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

1-Newbie

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

1 ACCEPTED SOLUTION

Accepted Solutions
24-Ruby V
(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

6 REPLIES 6
24-Ruby V
(To:mferguson-2)

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-Newbie
(To:Werner_E)

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.

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.

24-Ruby V
(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

24-Ruby V
(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

1-Newbie
(To:Werner_E)

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