Skip to main content
19-Tanzanite
May 30, 2024
Solved

Why these 2 function implementation of square wave does not have the same result when plotting?

  • May 30, 2024
  • 1 reply
  • 1546 views

Hi,

Why when plotting f2(t, Tf) does not look like f1(t)? The two functions are the same...

Cornel_0-1717071592731.png

Cornel_1-1717071603833.png

 

 

Best answer by Werner_E

@Cornel wrote:

And the only solution for this is this (to define Tf above f2)?


NO!!

You simply have to use your function the way you had defined it - with two arguments!

As i already wrote, you were missing the second argument when you called your own function.

Werner_E_0-1717077857465.png

Here a an alternative function

Werner_E_1-1717078212653.png

Calling the "mod" function twice is necessary to deal correctly with negative t-values because the implemented "mod" function would return negative values for negative arguments.

 

Another alternative:

Werner_E_2-1717078496891.png

could also written as

Werner_E_3-1717078618831.png

 

 

 

1 reply

25-Diamond I
May 30, 2024

@Cornel wrote:

Hi,

Why when plotting f2(t, Tf) does not look like f1(t)? The two functions are the same...

 



No, they aren't the same. When you CALL f2 from within f2 you are missing the second function argument!

Cornel19-TanzaniteAuthor
19-Tanzanite
May 30, 2024

And the only solution for this is this (to define Tf above f2)?

Cornel_0-1717077616770.png

Cornel_1-1717077628231.png

Werner_E25-Diamond IAnswer
25-Diamond I
May 30, 2024

@Cornel wrote:

And the only solution for this is this (to define Tf above f2)?


NO!!

You simply have to use your function the way you had defined it - with two arguments!

As i already wrote, you were missing the second argument when you called your own function.

Werner_E_0-1717077857465.png

Here a an alternative function

Werner_E_1-1717078212653.png

Calling the "mod" function twice is necessary to deal correctly with negative t-values because the implemented "mod" function would return negative values for negative arguments.

 

Another alternative:

Werner_E_2-1717078496891.png

could also written as

Werner_E_3-1717078618831.png