Skip to main content
1-Visitor
June 17, 2014
Solved

For loop error

  • June 17, 2014
  • 5 replies
  • 4085 views

I'm new to MathCAD(using MathCAD15). I'm trying to write a program that iterates through a set of data to locate the falling edge of a trip signal. The data set I am working with has thousands of lines where the voltage drops from arround 2.5v to around zero at the time a machine trips offline. I wrote a silplified program with only 10 datapoints as a baby step tward my goal. I am getting an error that doesnt make sense to me. "This value must be a Matrix of scalar elements"

See the attached program, any help is appriciated.

Best answer by RichardJ

It would be easier if you attach a worksheet. It's hard to debug an image.

Probably, if you right click on the absolute value operator, |, it will be set to "square matrix determinant". Select "absolute value" instead.

5 replies

19-Tanzanite
June 17, 2014

1. Instead of n0,0 and ni,0 just use n0 and ni, because n is just a vector.

2. Better to upload a worksheet, not just an image.

Alan

RichardJ19-TanzaniteAnswer
19-Tanzanite
June 17, 2014

It would be easier if you attach a worksheet. It's hard to debug an image.

Probably, if you right click on the absolute value operator, |, it will be set to "square matrix determinant". Select "absolute value" instead.

1-Visitor
June 17, 2014

Thanks guys. I had been fighting with that for about an hour. You answered my question in <5min.

25-Diamond I
June 17, 2014

Instead of for and break you could use the while-statement:

17.06.png

The result of my routine differes from yours when the vector consists of 1's only. Not sure what result you expect in that case.

1-Visitor
June 18, 2014

Another routine using a For Loop.

Clipboard01.jpg

25-Diamond I
June 18, 2014

A good one!

And while we are at that "make it shorter" contest, here a a very short and completely different approach:

18.06.png

It throws an error if the vector consist of all 1's which can easily be coped with an "onerror" statement.

BTW, I feel that a for-loop should not be terminated prematurely, whether using break or using return. But I admit that thats a very puristic point of view. And I am very often missing a "do-while" or "Repeat-Until" construction.

1-Visitor
June 18, 2014

Werner Exinger wrote:

A good one!

And while we are at that "make it shorter" contest, here a a very short and completely different approach:

18.06.png

I like it

Werner Exinger wrote:

BTW, I feel that a for-loop should not be terminated prematurely, whether using break or using return.

To be honest I do not usually construct for-loops that way, but the eager to reduce the program lines got to me.