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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Multiple (1000s) iterations of a worksheet

ptc-4677759
1-Newbie

Multiple (1000s) iterations of a worksheet

Hi Guys,

I'm new to MathCad and, like many, confronting the learning curve. I've inherited a model (~10pages) witten in M15 that spits out power consumption of my system for a given array of frequencies of input. I need to turn this into a recurrent calculation to see the power consumption over time. I've inserted a matlab script that calculates my inputs and it spits out a matrix of thousands of columns. I need to then calculate the power for each column and save it somewhere. All was dandy until I've found that loops can't incorporate references.

Any suggestions of how to structure this?

Many thanks in advance.

-Roger

12 REPLIES 12

In principal, it shouldn't be a problem for Mathcad to calculate functions of column, but ...

Could you explain in more detail what you mean by "can't incorporate references" and why that is a problem? Can you post an example of what you mean? How many rows does your matrix have?

Stuart

Make the calculation of power a function of frequency array: power(frequencyarray):=....

Then write a loop that calls this function, passing it each column of the matlab constructed matrix through each pass, along the lines of:

loop.PNG

p is then a vector of powers; one for each column of the Matlab matrix (assuming one value of power results from one column of the matrix).

Can you upload a simplified worksheet with just a few columns and a simplified power calculation so we can see exactly what your problem is?

Alan

Oops! In the function above, for 'rows' read 'cols'

So, if I understood corrctly, I should try and make my existing model (worksheet) a function. Then I can call the function and calculate the power. Correct?

Would that be like calling a function (.m file) in matlab? Can I just define a function at the start of the xmcd file?

The algorithm I have in mind for this is like so:

call matlab script to get frequency/ loudness of wav file (done)

- output is matrix of loudness per 100ms

- matrix has a column for each time sample

for each column of matrix

call power model (old file)

calculate power

save in power vector

save power vector and loudness matrix

plot vector

Does this help any?

It's the for loop I'm stuck on. The rest works 😃

Ideally I would call the file (add as a reference?) and just let it spit out my power consumption. The model I have only calculates instantaneous power. So I have to loop it for all the time frames of my input file. I've attached one of the pages from my inherited model, as requested.

A page of model.jpg

Edit:

The trial matrix I have is ~200,000 columns

Thanks for your guys's help!

I'm having trouble relating your expaination at the top to your picture.What in the picture changes based on a time sample; your page looks to be self-contained without any external references.

Can you post a sheet with a short sample. (Advanced editor allows files to be attached.)

Hi Fred,

So I agree, there are no external references. This is from the power calculation worksheet (6/10), I thought that is what was asked for.

As for a look at what I'm doing (trying to do) here's my worksheet so far (not sure this will help).

Tha gap in the for loop is where I was going to insert the reference to my other worksheet.

Thanks!

I've added a few notes. WIthout data I can't do much, and I'm assuming that Ptot_app is a calculation on the data.

You cannot call a worksheet from inside another worksheet. Installing a reference to a worksheet is identical to pasting the contents of the worksheet in (just like copy all/paste.) If you have defined a function, it will execute; but I don't see any evidence that you know about functions.

If you show me what P tot_app does, I'll try to update this file.

If you simply have a large matrix and wish to apply a function to each column, then the simplest thing to do is iterate through each column and use the column operator (ctl-6) to extract the data and then pass it to the function; then store the results in a vector (I presume you know that Mathcad uses column matrices to represent vectors and that the indexing base is 0 rather than Matlab's 1 ...). See attached for a generic example (the functions fillmat and randmat are defined in the collapsed Area named 'Utilities').

Stuart

Ah ... stable door ... horse ... bolt

Ignore the above post - I've just noticed that Alan has already said the same thing.

Stuart

Thanks for the utilities pages!

Structure should be more like the attached.

Alan

PS In Mathcad functions are usually defined before they are called, compared with Matlab's requirement to define them after the calling program.

Aha, ok. This is starting to make more sense to me. So if I modify my original worksheet (my "model") to have a function then I can call the function at the end and iterate my power calculation.

Now will that work with the linear style calculations Mathcad seems to make? So here's what I have in my model:

Calculate vector A as input

Matrix B = f(A)

C = f(B)

and so on

until at the end, Power = f(z)

So you're suggesting I put a function at the top of the worksheet:

PowerCalc(InputVector):= final formula in model

Then call that function at the end of the worksheet in an iterative loop. Right?

Roger Calixto wrote:

Aha, ok. This is starting to make more sense to me. So if I modify my original worksheet (my "model") to have a function then I can call the function at the end and iterate my power calculation.

Now will that work with the linear style calculations Mathcad seems to make? So here's what I have in my model:

Calculate vector A as input

Matrix B = f(A)

C = f(B)

and so on

until at the end, Power = f(z)

So you're suggesting I put a function at the top of the worksheet:

PowerCalc(InputVector):= final formula in model

Then call that function at the end of the worksheet in an iterative loop. Right?

Yes. If you currently require ~10 pages to get to the power you might well end up with several functions, but that will work ok. (Also note that a function can take several arguments.)

Alan

Top Tags