Skip to main content
1-Visitor
September 21, 2017
Solved

Recursive funcion with arrays

  • September 21, 2017
  • 4 replies
  • 7939 views

Hello,

 

I have a problem implementing a recursive funcion in Mathcad Prime 3.1, hope someone can help me make it work. I want to calculate a heat transfer layer per layer. So the array should work like this: T_layer,time

Here's what I want it to do: Take given Temperature T_0,0 and given Temperature T_1,0 and calculate Q.dot_1,1. With Q.dot_1,1 and a given time increment (t) calculate Q_1,1. With Q_1,1 and the mass (which is dependent on the layer) I want to calculate T_1,1. With it and T_0,1 (given) calculate Q.dot_1,2 and so on Meanwhile it should also calculate the other layers. So T_1,0 and T_2,0 (both given) to Q.dot_2,1 with t to Q_2,1 with the mass to T_2,1. Now T_2,1 and T_1,1 (from the first layer calculation) to Q.dot_2,2 and with t to Q_2,2 and so on. I hope I could explain it well enough.

Thanks in advance, David

EDIT: Thanks to FredKohlhepp I zipped and uploaded the worksheet

Best answer by davessn

I got it working! This is what it looks like:

heat loop.png

Thanks again for the help!

4 replies

1-Visitor
September 21, 2017

Attaching a MC file; right-mouse-click your file and "send to" "compressed folder (zip)" should zip it , which then can be attached to your post..

Attached is an example of muti-layered walls. Unfortunately, in P4, so I attach a pdf.

I hope this helps.

Norm

23-Emerald I
September 21, 2017

There's an old technique, initializing the first element of vectors, then stepping thru calculating each successive step in each vector.  I've attached a not-very-good example.

 

In this wonderful new web application many of us have to zip a file to attach it.  This problem was highlighted when the application first went into service, and PTC promised to have it fixed.  Like so many of their promises . . .

davessn1-VisitorAuthor
1-Visitor
September 21, 2017

Thanks for the answer. This way of calculating could proof itself helpful.

Though when I try this I get an error I don't really understand saying the array index istn't valid. And that the index can't be smaller than ORIGIN neither bigger than the last element. But I don't see why it should be any of those. I attached the file trying this way of calculation.

23-Emerald I
September 21, 2017

You'rre running 3.1, I'm running 3.0--I can't open your file, you can't save back.

 

Attach a PDF and thank PTC for their marketing stragety!

1-Visitor
September 21, 2017

Looking at the first step of the calculation where z=1 and s=1, your definition of Q[1,1 and Theta[1,1 both require Theta[1,0.  However, Theta[1,0 is undefined.

 

Can you provide the result that you expect in your example?

davessn1-VisitorAuthor
1-Visitor
September 22, 2017

Yes, thats true, thanks for the clue.

Now I took the error free version of LucMeekes (Thanks alot!) and fixed some technical conditions.

I already calculated the complete loop manually which gives you the expected result. I attached the manual calculation and the new array calculation as pdf and Mathcad Prime 3.1 worksheet.

As you can see there the first Q._1,1 is calculated correct, but it doesn't calculate a new Temperature and I don't know why not.

Also I'm confused why I need to define Q._s_E/s_R,9 but if I don't some error is happening.

davessn1-VisitorAuthorAnswer
1-Visitor
September 22, 2017

I got it working! This is what it looks like:

heat loop.png

Thanks again for the help!