Skip to main content
14-Alexandrite
November 20, 2024
Solved

must be scalar

  • November 20, 2024
  • 2 replies
  • 1436 views

Hi there, 

I think almost 30% of mathcad's community questions is about ( this value must be scalar) .. I really find it confusing to differentiate between scalar/ array/ vector( maybe it seems stupid to you, but can you tell me how to identify each one of them? and the errors occur because of them

I got this error in my sheet, how can I solve it ?

YA_10963798_0-1732092292059.png

prime 10 is attached

Thanks in advance

 

Best answer by terryhendicott

Hi,

Like this:

Capture.JPG

Scalar is an individual value like a:=3

range is a group of values i:=1,2..5.  You can tell a range from a vector because you cannot subscript one of the group i[2 does not exist

vector is a mathematical construct.  you can tell a vector from a range as you can subscript an individual scalar from the vector b:=v[2

Cheers

Terry

 

2 replies

21-Topaz II
November 20, 2024

Hi,

Like this:

Capture.JPG

Scalar is an individual value like a:=3

range is a group of values i:=1,2..5.  You can tell a range from a vector because you cannot subscript one of the group i[2 does not exist

vector is a mathematical construct.  you can tell a vector from a range as you can subscript an individual scalar from the vector b:=v[2

Cheers

Terry

 

14-Alexandrite
November 20, 2024

thank you so much terry 

25-Diamond I
November 20, 2024

Just to explain the error message:

 

It stems from the line   if Layer[j <-- "Sand"

 

The if-statement must be followed by a real number, a scalar. If its 0 its interpreted as "false", all other values as "true".

A comparison like a=b returns 0 or 1, depending on the values in a.

But a local assignment like x <--- abc  'returns' the value abc.

You accidentally used an assignment and not as you were supposed to do a comparison. And you assigned a string ("Sand").
So your if-statement reads if "Sand" ... and thats syntactically wrong as Prime expects a number, a scalar for which it can decide if its zero or not where you provided a string, a text.

The error had nothing to do with ranges vs vectors and it also had nothing to do with the vectorization you applied. This vectorization is not necessary as all involved variables are scalars and not vectors, but it would not do any harm.

Another error in your routine were the indices which Terry has fixed as well. Your original would have run into a "index out of range/invalid index" error because sigma'.v contains more elements than Layer.

BTW, writing nfs[j after the if/else statement has no effect and you could delete this line.

14-Alexandrite
November 20, 2024

AAh I understand now . If you notice in my previous questions I always get stuck in such error .. either ( this value must be a scalar or this value must be a vector) so I thought there are many things should be learnt to overcome this error, but it seems each error has its own reason ..

Thank you for the clarification