cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

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

Cornel
19-Tanzanite

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

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

 

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Cornel)


@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

 

 

 

View solution in original post

6 REPLIES 6
Werner_E
25-Diamond I
(To:Cornel)


@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!

Cornel
19-Tanzanite
(To:Werner_E)

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

Cornel_0-1717077616770.png

Cornel_1-1717077628231.png

Werner_E
25-Diamond I
(To:Cornel)


@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

 

 

 

Cornel
19-Tanzanite
(To:Werner_E)


@Werner_E wrote:

When you CALL f2 from within f2 you are missing the second function argument!


It's not strange this? I mean I was expected that I can call f2 within f2 with also other arguments, beside t, like f(t, Tf) or f(t, x1, x2, x3, ...)...

Werner_E
25-Diamond I
(To:Cornel)


@Cornel wrote:

@Werner_E wrote:

When you CALL f2 from within f2 you are missing the second function argument!


It's not strange this? I


Not strange at all!

If you define a function with two arguments, you have to provide two arguments whenever you call your function.

 


I mean I was expected that I can call f2 within f2 with also other arguments, beside t,

Yes, thats exactly what happens. Once you call it with t-Tf instead of just t, the other time you call it with t+Tf instead of just t.

It would also be possible to provide different values (other than Tf) for the second argument, but this would not make much sense when you try to define this square wave signal.

 


like f(t, Tf) or f(t, x1, x2, x3, ...)...

????????????????????????

User-defined functions must be called with exactly the number of arguments for which they were defined.

 

There are a few built-in functions that may be called with fewer arguments, as some arguments are optional. Unfortunately, you cannot create such functions yourself and define default values for any omitted arguments.
But what you are asking for with your x1, x2,... would be a call with more arguments than specified in the definition. That would be nonsensical, if how would Prime know what to do with the surplus arguments?

Translated with DeepL.com (free version)

 

Cornel
19-Tanzanite
(To:Werner_E)

Ok Werner, I understood now, more after you posted your second reply showing where the missing part was located. Thank you.

Announcements

Top Tags