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
- :
- Mathcad function definition cross reference

Options

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

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

Showing results for

01-26-2016
02:50 PM

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

01-26-2016
02:50 PM

Mathcad function definition cross reference

Hi I have a problem with the definition of functions. I have a function A that references to function B which uses function A from a previous iteration. here's my code (more in xmcd file) |

Thank you for your help

6 REPLIES 6

01-26-2016
08:35 PM

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

01-26-2016
08:35 PM

There are three problems here:

- The first is that theta.a(t) is a local function (it only exists within your program structure) of the variable Delta-Theta.a.t(t), which is defined globally at the top of the first page, but is a function of c.a(t) outside the program. c.a(t) is defined outside the program, but as a function of theta.a(t), which is circularly defined in terms of Delta-Theta.a.t(t) and out of sequence. Functions can only call other functions if they are defined prior (above) in the worksheet. You end up with a circular reference here that is not legal.
- Programs cannot return functions as you've defined, but only numerical results in terms of scalars or arrays.
- I believe what you are trying to do is return an array of values for each iteration that depend on previous iteration values. Using functions is not the vehicle for this. If you want to iterate, storing and using previously iterated values, then you should be using iterated arrays to do this. Look through the help and the quick sheets for examples of using iterated variables.

I hope this helps.

01-27-2016
03:49 PM

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

01-27-2016
03:49 PM

In addition to what Jeff mentioned, there are more problems. You have a number of variables undefined.

I made an attempt to build an iteration. It 'works' in the sense that it iterates, but not knowing the subject my attempt may be far off the intent.

Anyway:

See if this works for you, or if you can make it work.

Note that 't' is no longer time iteself, but an index into the time points (each Delta-t apart).

In the end you get 4 arrays, and to output them simultaneously (using the augment statement), they HAVE use the same unit. I chose unitless, that's why h.net is divided by its units.

Success!

Luc

01-27-2016
03:57 PM

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

01-27-2016
03:57 PM

They do result in nice graphs:

01-29-2016
08:36 AM

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

01-29-2016
08:36 AM

Hello guys, thank you very much for so many responses! I really appreciate it! Im also sorry for such a late response, havent had much time last days...

I tried last two days to put it together and make it working but without any success. Like you said you have used arrays instead of functions and thats where I lost somehow. I mean I dont understand really the logic of your algorithm.

- I found out that recursive function might be something useful for this? But problem is that i have no skill at all in programing so its kinda difficult for me.
- Is there any option of "storing values" in functions?
- Also I just found out that my problem has grown and become more complicated. Is this still posible to write it down?

just for information: Main point of this calculation is to calculate iteratively increasing of temperature of member from air which is increasing temperature.

edit// I understand that i cant write it like that, also i understand that i have to create iterative loop but i dont have any idea how with such complex problem.

edit2// theres error in picture statement "Effective radiation temperature of the fire environment" in mathcad file its correct

01-30-2016
11:04 AM

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

01-30-2016
11:04 AM

I think you need iteration, rather than recursion.

Iteration is a process that uses previous values of an estimated parameter to find better estimates.

Here's an example to find the square root of S:

You need a starting point for your iteration, the example above uses the initial value x.

And you need a stop criterion, like the number of iterations.

You can also use the difference between two estimates, as shown below:

Note that I use an array (R) to hold the iteration values, so I can plot how the iteration reaches its destination:

If you're not interested in how the iteration runs, but only in the end result, you could use:

Success!

Luc

01-30-2016
03:04 PM

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

01-30-2016
03:04 PM

Here is another iteration that involves two parameters that depend on each other:

You can see how X depends on (the previous value of) Y, and Y depends on (the previous value of) X. Finally R is just calculated from the present values of X and Y.