Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Recursive funcion with arrays

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
08:38 AM

09-21-2017
08:38 AM

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

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-22-2017
09:53 AM

13 REPLIES 13

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
09:31 AM

09-21-2017
09:31 AM

Re: Recursive funcion with arrays

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
09:31 AM

09-21-2017
09:31 AM

Re: Recursive funcion with arrays

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
10:10 AM

09-21-2017
10:10 AM

Re: Recursive funcion with arrays

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
12:59 PM

09-21-2017
12:59 PM

Re: Recursive funcion with arrays

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
01:03 PM

09-21-2017
01:03 PM

Re: Recursive funcion with arrays

You have not initialized theta. Note that by default array indices in Mathcad start at 0, not 1 (that is what ORIGIN is).

If you initialize theta you have a unit mismatch problem.

Edit: You did initialize it, but you are attempting to get theta(1,0), which does not exist. And you still have a unit mismatch in the second expression.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
01:06 PM

09-21-2017
01:06 PM

Re: Recursive funcion with arrays

Here's the picture, Fred.

I guess the intent is to implement the recursion with just an assignment of a 2 element vector to a 2 element vector.

I'm afraid it doesn't work like that. Could be nice if it did though...

Success!

Luc

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
01:22 PM

09-21-2017
01:22 PM

Re: Recursive funcion with arrays

Corrected the units (added W to the definition of Q[1,1

And I preset the final indices of the two result arrays Q and theta, so that the matrices can be filled.

This is what I get:

It's now free of mathcad errors, not necessarily free of mathematical or physical (modelling) errors.

I Leave that up to the OP.

Success!

Luc

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-21-2017
06:28 PM

09-21-2017
06:28 PM

Re: Recursive funcion with arrays

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

09-22-2017
05:51 AM

09-22-2017
05:51 AM

Re: Recursive funcion with arrays

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.

Top Tags