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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Shift Register Instead of For loop

ptc-5051640
1-Newbie

Shift Register Instead of For loop

Hiya,

Is it possible that I could use shift registers instead of for loop in mathcad.

Thanks.

14 REPLIES 14

Mathcad has not the ability to do bit shift operations on integers - there are no explicit data types, anyway.

What would be the reason for that kind of operation? If its speeding up calculations or creating more compact programs, then it would not be an option to create bit shifting routines yourself using conventional methods.

I want to replace for loop, as it takes alot of time and computation.

Anum Ali wrote:

I want to replace for loop, as it takes alot of time and computation.

I guessed it, but unfortunately shifting in the sense you thinks of is not available in Mathcad.

But most of the times its not the loop itself the most time consuming. There are some operations which tend to be implemented not really optimal with respect to computation time - especially stacl and augment come to my mind.

If you post an example, chances are that someone here will find a different way to speed it up.

Its a simple for loop, I dont know how it could be more simplified. I code is attached below.

dec2bin.jpg

Won't work on a screenshot.

But local variable x is obsolete and not used in any case.

You don't reveal much of what you intend to do, but it looks like simple copy operations and the second prog overwrites elements it assigns in the first phase - doesn't make much sense to me.

Maybe you wish to post the worksheet and describe what you are trying to do with your routines.

I cant share my mathcad worksheet due to office regulations.

Only I want to replace for loop as shown above.

Anum Ali wrote:

I cant share my mathcad worksheet due to office regulations.

Only I want to replace for loop as shown above.

Thats quite often case, but most of the time posters are able to create a modified, stripped down sample worksheet which clearly shows the intention and the problem, without revealing vital company secrets.

In your case info(values) about bit, Binary, signal and packet_len are missing along with an explanation on what you are trying to do at all, as the local assignments for x don't make any sense from what I see and the overwriting of the first few signal data with the preamble either.

Maybe you could use "stack" and "submatrix" to avoid the loops, but chances are, thatyour overall calculations will not be speeded up that way. Neverthelees it may be worth a try. As already said, Mathcad won't provide the speedy low level operations you are searching for.

Is your main problem putting the preamble in front of a very large signal-vector?

er...

Have a look at these functions, which I think can be adapted to what you want and do work a bit like shift registersBitvecs.xmcd

Thanks for your help but you are still using while and for loops.

I think the only way to do this would be to create user dlls from C or C++, languages that do support shift operations. See Mathcad help on how to do this. Quite a lot of work, and only worthwhile if you are going to use these operations a lot

Hello,

What operations do you want to do with / after the shift register?

If you can give examples of the type of calculation that you neeed there may be ways to achieve your goals.

Regards

Andy

A little more on this. If one wants to create something that behaves like a shift register you can build something wher each element copies its neighbor on each clock pulse - but a much more efficient method is to write data into an array, incrementing the entry pointer each time (modulo the length of the shift register L) and read the data out also using a read pointer which is L addreses behind the entry pointer and also increments each time (modulo L). In this scheme the data in the array does not move, so only one read and write is needed per cycle, regardless of the register length. This can be fairly easily achieved in Mathcad if the register is implemented as a bit array (if bits are the required element size)

Its hard to advice as AnumAli only vaguely described HOW he would like to solve his problem (whatever it is), obviously having in mind some programming languages he is familiar with.

But what Andy and me asked him to no avail was to tell us WHAT he wants to achieve at the end. What routine has to deal with arrays that large (or that often), that using loops is not acceptable for him and whats the goal of this routine would be at last.

From the pic he posted this can't be seen and what he did there looked faulty (as far as one can tell without knowledge of what he is aiming for).

Maybe the question was posted just out of curiosity if there is a build-in option to do it and writing his own dll is not an option for him.

Top Tags