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

Function of another function

Desiv5-disabled
1-Newbie

Function of another function

Hello,

let's say we have defined a function f(x,y) and another one, g(f(x,y),u,v), so g is a function depending on u, v and on f(x,y). How do I write the function g correctly in Mathcad: g(f,x,y,u,v) or g(f(x,y),u,v) or g(x,y,u,v)? It may be a stupid question, so I apologize for that, but I need to understand how Mathcad "thinks"...

Thanks in advance for your answers.
10 REPLIES 10

Attached example should help.

stv

... another example added.

jmG

That depends on what you want to do inside function g.
If you only need the result of f inside g, and the parameters x and y can (only?) be supplied from the outside, then you can define g as g(f,u,v) and when use g as g(f(x,y),u,v). Effectively you pass the result of evaluation of f(x,y) as the first parameter to g.

If you want f to be ANY two parameter function, AND its two parameters x and y are supplied by g internally, you can (still) define g as g(f,u,v) but internally you use it as f(x,y). Here you pass the function name as the first parameter to g. But you can only pass it the name of a predefined function that accepts (only) 2 parameters.

example suppose: sinus(t,F):= sin(F*t)
and define g(f,u,v):=u*f(u/v,v^2)
then the call g(sinus,12,3) will result in whatever 12*sin(3^2*12/3) evaluates to.
See that the difference in calling is that you only supply the function name, not its parameters, to function g.

Succes!
Luc

Quite right, Luc !

The work sheet from the collab is expected. The concept genralises ever wider, and the best example is the "Breather", in this collab. The concept of the collab didn't print well in my mind as u,v aren't necessarily linear grid planes, rather themselves function of two unique variables and that finally Createmesh will crunch with ease and great accuracy where any interpolating value can be extracted. In fact, the f(x,y) does not necessarily implies a 2d function like in the case of the vector distance where f[x,g(y)].

The work sheet will avoid getting lost in conjectures.

jmG

None of the above.

You are starting from a faulty premise. You are using the concept of function from physics, where it is just a relationship between variables defining the state of the system. But Mathcad functions come from computer science, where a function is just the specification of a calculation, a rule for calculating a number based on some set of input numbers.

A function is not a function of any particular variable(s). It is a function of its arguments. While when defining a function one must use names (simple names, not expressions of any sort) for the formal arguments, these are dummy variables in the sense that the names are irrelevant to the definition (although as a matter of sanity it is recommended that the names do have some mnemonic value). Thus the functions f(x):=x² and g(y):=y² are identical. It is not the case that f is a function of x while g is a function of y.

You cannot define a function g(f(x,y),u,v). The arguments must be simple names. Thus g could be defined as g(w,u,v). The variables w, u, and v have no relationship to any worksheet variables of the same (or similar) names. They are purely local names, that exist only in the definition. If, in actual use, w is to be a function of x and y, say w=f(x,y) then you may evaluate g as g(f(x,y),u,v). That passes to g the three values, f(x,y), the current value of u, and the current value of v. Or, for many purposes equivalently, you may define a variable w as w:=f(x,y) and then evaluate g(w,u,v).
__________________
� � � � Tom Gutman
PhilipOakley
5-Regular Member
(To:TomGutman)

It is important to separate the defining of the
function from those items discussing the evaluation
of the function.

It is easy to misread the various contributions if
care is not taken.

Philip Oakley

On 7/20/2009 6:39:37 PM, philipoakley wrote:
>It is important to separate the defining of the
>function from those items discussing the evaluation of the function.
>
>It is easy to misread the
>various contributions if
>care is not taken.
>
>Philip Oakley
_________________________

The originator should read Createmesh/Createspace.

The work sheet will clarify all that stuff.

jmG

>A function is not a function of any particular
> variable(s). It is a function of its arguments.
And what about this function:
a:=3
f(x):=x^a
f(2)=8
but here must be an error message!

More correct only so (incapsulation):
f(x, a):=x^a
f(2,3)=8
Or?
Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm

The function f can be described by the definition f(x):=x³. As far as the function definition is concerned, the exponent of three is a constant. That it was specified as a name (with a value) rather than a literal is of no significance to the definition.

This is the general rule in Mathcad. A reference to a (worksheet) variable is a reference to its value. Nothing else. Remember, what Mathcad describes as variables, and are commonly thought of as varaibles, are, in fact, in computer science terms really named constants. Within the scope of a definition a:=3 the name a is synomous with the literal 3.
__________________
� � � � Tom Gutman
ifomenko
15-Moonstone
(To:TomGutman)

Luc is right!

Function of function.png

Top Tags