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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

3-Visitor

## " This Value must be scalar"

Whenever I Return the value for the program I created, It gives me the error.

Kindly help me out .

ACCEPTED SOLUTION

Accepted Solutions
25-Diamond I
(To:akshaykumawat15)

Apart from what Fred already spotted, some more remarks:

1. You may consider setting the system variable ORIGIN to 1, instead of the default value 0. You can do this either by writing ORIGIN:=1 at the top of your sheet or via the menu.
As an alternative you may stick with ORIGIN=0 and change your program to reflect the fact that the first vector element has index nr 0 (loop from 0 to n-1 instead of 1 to n).
2. Instead of returning a 4x3 matrix or a 12*1 vector (I am assuming you already adopted my remark #1) you may consider returning a nested vector. A vector with the three calculated vectors as elements.

3. A severe failure was made by you because you type square brackets in your calculations. Typing square brackets automatically define e vector. You have to use normal parenthesis instead (in some cases they may be displayed as square brackets which is admittedly confusing)

Find a attached a working work sheet (Prime 6). I have assumed that you wanted the full vectors as result. If you really only want the last values (as you created your program initially) you replace epsilon by epsilon[i in the return statements.

Furthermore your program is quite redundant and sure can be written much shorter, but I haven't bothered doing so 😉

7 REPLIES 7
23-Emerald I
(To:akshaykumawat15)

I think (I've got Express, so I can't change your program to check) that one of your problems is in

this terminology.  This is how FORTRAN (if I recall) specifies elements of a vector.  Mathcad uses a subscript (left square bracket "[") to get  instead.  The notation you used declares a function--put in a value and evaluate the expression, so when you "return e(i)" Mathcad tries to evaluate your function definition, gets confused, and flags an error.  (Mathcad's error messages have never been terribly accurate description of the problem.)

Another issue: multiple return statements:

A return statement (I believe) represents a program "break,"  execution halts operations and returns the whatever follows "return".  The next statement would not be executed.  If you replace those three lines with

you can return all three five element vectors as a 5 row three column matrix or as a 15 element vector.  (Yes, five elements, not four!  Mathcad defaults to the first element being 0 unless you change it.  The system variable ORIGIN will tell you what it is.

Good luck!

25-Diamond I
(To:Fred_Kohlhepp)

In Prime the element of a vector or matrix can be accessed by a matrix subscript as we are used to, but alternatively also via function arguments. Personally I dislike the latter as a vector isn't a function and IMHO this notation is confusing but its valid in Prime.

But you are correct anyway that the assignment is one of the errors in the sheet, because the function-approach is only allowed on the  right-hand side of an assignment.  In the program one has to use the matrix index.

3-Visitor
(To:Fred_Kohlhepp)

Thank You So Much !

25-Diamond I
(To:akshaykumawat15)

Apart from what Fred already spotted, some more remarks:

1. You may consider setting the system variable ORIGIN to 1, instead of the default value 0. You can do this either by writing ORIGIN:=1 at the top of your sheet or via the menu.
As an alternative you may stick with ORIGIN=0 and change your program to reflect the fact that the first vector element has index nr 0 (loop from 0 to n-1 instead of 1 to n).
2. Instead of returning a 4x3 matrix or a 12*1 vector (I am assuming you already adopted my remark #1) you may consider returning a nested vector. A vector with the three calculated vectors as elements.

3. A severe failure was made by you because you type square brackets in your calculations. Typing square brackets automatically define e vector. You have to use normal parenthesis instead (in some cases they may be displayed as square brackets which is admittedly confusing)

Find a attached a working work sheet (Prime 6). I have assumed that you wanted the full vectors as result. If you really only want the last values (as you created your program initially) you replace epsilon by epsilon[i in the return statements.

Furthermore your program is quite redundant and sure can be written much shorter, but I haven't bothered doing so 😉

23-Emerald III
(To:Werner_E)

Werner's sheet converted to Prime 3.0 is attached.

3-Visitor
(To:Werner_E)

Thank you so much for your response,

Actually I'm a newbie to mathcad so in further programmings ,

I'll try to reduce my redundancy.

& Thanks for the tip.

25-Diamond I
(To:akshaykumawat15)

Here is a streamlined version of your program. You may put the definition of the interpolation function "stress" at the top of the program, but I'd prefer to have it outside.

I replaced two if statements by the space saving if-function (a version which uses if statements only is included in the attached Prime 6 worksheet.

Announcements

Top Tags