Skip to main content
1-Visitor
August 8, 2012
Question

Multiple (1000s) iterations of a worksheet

  • August 8, 2012
  • 4 replies
  • 4906 views

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

4 replies

1-Visitor
August 8, 2012

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

19-Tanzanite
August 8, 2012

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'

1-Visitor
August 8, 2012

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!

23-Emerald I
August 8, 2012

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

1-Visitor
August 8, 2012

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!

1-Visitor
August 9, 2012

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?

19-Tanzanite
August 9, 2012

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