Skip to main content
1-Visitor
December 1, 2011
Solved

Inscrutable Error with Simple Program

  • December 1, 2011
  • 2 replies
  • 6879 views

My goal was to determine the size of a single dimension index based on the

contents of the first column [row] of a matrix. For instance if I have Q=(1,0,2) I want

an index N=2, for two non-0 elements for Q1 and Q3. Q can be any size and any

number of 0 elements can exist. I attach a simple replica of the program I used

to calculate this index, using the "for" and "if" functions. It seems simple so I am

feeling pretty stupid right now. Can you see anything wrong with the attached

program? It was developed in MathCAD 2001i [V8].

Best answer by Fred_Kohlhepp

I can't open your program, my computer doesn't recognise "zipx"

Does the attached help?

2 replies

23-Emerald I
December 1, 2011

I can't open your program, my computer doesn't recognise "zipx"

Does the attached help?

pdorvel1-VisitorAuthor
1-Visitor
December 2, 2011

Fred

The program and set up you sent works as I would have intended mine to work.

There is not much different in what I did than what you show. The only real differences

were that I have a one dimensional matrix [simpler] and I did not express the LHS

of the program as a function or the rows(A). Instead I simply embedded this number

in the for statement. My lines are generally as follows.

N= i set to 0

for k E 1 .... cols(Q)

i=i+1 if Q(k) <=> 0 |Q(k) is the column k of Q

[i=i otherwise, or no statement same effect]

i

This would give me N=3, total columns of Q, instead of 2, in my example, with non-zero

elements.

I will try your suggestion and I am sure it will cure my issue.

Thank you,

Paul

1-Visitor
December 2, 2011

To me Fred's solution looks a little different to what you were after.

Please re-upload the worksheet.

Mike

12-Amethyst
December 2, 2011

The problem appears to be that k<0> is returning an array & that isn't equal to a scalar.

There are a couple of alternate methods to achieve the function attached

Best regards

Andy

1-Visitor
December 2, 2011

Another method?

Clipboard01.jpg

Mike

1-Visitor
December 2, 2011

Oops, worksheet attached.

Mike