# Substituting a function inside other one?

**URL:** <https://community.wolfram.com/t/substituting-a-function-inside-other-one/19510>\
**Category:** Questions\
**Created:** [January 27, 2022, 2:01pm UTC](https://community.wolfram.com/t/substituting-a-function-inside-other-one/19510 "2022-01-27T14:01:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alischfranck](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@alischfranck](https://community.wolfram.com/u/alischfranck)\
**Post date:** [January 27, 2022, 2:01pm UTC](https://community.wolfram.com/t/substituting-a-function-inside-other-one/19510/1 "2022-01-27T14:01:06Z")

</div>

So, I have this function:

```
f[z_] = Exp[-z] Sin {2 Pi [0.61 z - 0.22z^2 +2 g[z_]}; 

```

and this function

```
g[z_]=Cos[2 Pi (1.5 z - z^2 )]; 

```

How do I write one inside the other with all the parentheses, braces and square brackets in the right place to be able to write an algorithm?  
I started testing Mathematica now and I’ve been trying for days to understand what I’ve been doing wrong, because the answer doesn’t return the sine and cosine by mistake in the square brackets, parentheses…

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [January 27, 2022, 2:28pm UTC](https://community.wolfram.com/t/substituting-a-function-inside-other-one/19510/2 "2022-01-27T14:28:00Z")

</div>

The underscore `z_` indicates a pattern, and belongs to the left-hand side. Square brackets are for the argument of functions, curly braces for lists, round parentheses to indicate the order of operations. It is VERY coherent and worth internalizing the distinction, which is lost to traditional math notation:

```
g[z_] := Cos[2 Pi (1.5 z - z^2)];
f[z_] := Exp[-z] Sin[2 Pi (0.61 z - 0.22 z^2 + 2 g[z])];
Plot[f[z], {z, 0, 2}]

```

---

<div class="post-metadata">

**Author:** ![alischfranck](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@alischfranck](https://community.wolfram.com/u/alischfranck)\
**Post date:** [January 27, 2022, 2:35pm UTC](https://community.wolfram.com/t/substituting-a-function-inside-other-one/19510/3 "2022-01-27T14:35:46Z")

</div>

So, I already tried, and this happens… Do you know what is happening?

 ![Error.jpg](https://global.discourse-cdn.com/wolfram/original/3X/d/4/d471f3f361f14bddaf968b40769dadeb71f96ff5.jpeg)

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [January 27, 2022, 2:43pm UTC](https://community.wolfram.com/t/substituting-a-function-inside-other-one/19510/4 "2022-01-27T14:43:06Z")

</div>

Check again your syntax. The argument of functions like `Sin` and `Cos` goes inside square brackets. `Pi` is not a function, it is a numerical constant, it is _not_ followed by `[]`.

---

<div class="post-metadata">

**Author:** ![alischfranck](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@alischfranck](https://community.wolfram.com/u/alischfranck)\
**Post date:** [January 27, 2022, 2:50pm UTC](https://community.wolfram.com/t/substituting-a-function-inside-other-one/19510/5 "2022-01-27T14:50:55Z")

</div>

Ok… How would I write all in one function?

f[z\_] := Exp[-z] Sin [2 Pi (0.61 z - 0.22 z^2 + 2 (Cos 2 Pi [1.5 z - z^2]))]

?

I would really appreciate if you could write this down, once I know how to do it I won’t go wrong again… You would help a lost student! I’m reading what you’re writing, but I have a lot of information for a function and I don’t know how to manage it! All the parentheses and square brackets with the pi, the sine and the cosine are making fun of me! ☹

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [January 27, 2022, 2:57pm UTC](https://community.wolfram.com/t/substituting-a-function-inside-other-one/19510/6 "2022-01-27T14:57:22Z")

</div>

`2Pi` is multiplied by `1.5 z - z^2`, and this is indicated by either explicitly by `2 Pi*(1.5 z - z^2)` or implicitly by juxtaposition `2 Pi(1.5 z - z^2)`. The result is the argument of Cos, and goes within square brackets: `Cos[2 Pi (1.5 z - z^2)]`. Altogether

```
f[z_] := 
 Exp[-z] Sin[2 Pi (0.61 z - 0.22 z^2 + 2 Cos[2 Pi (1.5 z - z^2)])]

```
