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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Inscrutable Error with Simple Program

pdorvel
1-Visitor

Inscrutable Error with Simple Program

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].

ACCEPTED SOLUTION

Accepted Solutions

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

Does the attached help?

View solution in original post

16 REPLIES 16

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

Does the attached help?

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

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

Please re-upload the worksheet.

Mike

I opened this file (ZIPX) using WinZip 15.5.

P.S. Unfortunately, at this moment I do not have access to Mathcad.

Cheers.

Mike

Mike

I have tried to re-upload a document to the current discussion

but being a relatively new participant I could not find a way to

do this. Ultimately I uploaded the document to the programming

group but it doesn't appear in the discussion thread. My problem

has been solved. It was a silly oversight on my part. In my single

dimension array Q=(1 0 2) say, my program was written to check

Q<k> = 0. But Q<k> only returns the array of that one cell, not its

value. Hence I needed to at least add indices Q<k>[1,1 to the program.

Better though is simply to use Q[1,k = 0 as the test. This works.

Thank you,

Paul

Hi Paul,

I have just commented on the document you posted. If you click on the 'use advanced editor' link in the top right hand corner you can then upload worksheet and attached files.

Mike

I forgot to add - While it is your prerogative which version to choose to adopt. Fred's example doesn't indicate the total amount of zero's in a Matrix, which is what you were after isn't it?

Mike

Andy.

If you change Q<k> to Q[1,k address the kth element of the first row rather than the whole kth column your program works.

Thanks, Vladimir, for unpacking it!

Fred Kohlhepp wrote:

...Thanks, Vladimir, for unpacking it!

No problem.

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

Another method?

Clipboard01.jpg

Mike

Oops, worksheet attached.

Mike

Mike,

That is a clever function. Not sure what the expression in the upper limit of the first sum is to accomplish?

in the original file, Q<=>0, doesn't exclude real number. But I don't think that syntex is recoginized anyway.

tmp.gif

Mike,

That is a clever function. Not sure what the expression in the upper limit of the first sum is to accomplish?

Good spot Wayne.

It wasn't meant to accomplish anything. It was a typo

Mike

Andy: You are absolutely right. I needed the scalar not the array. Thanks Paul

Announcements

Top Tags