Skip to main content
8-Gravel
February 3, 2023
Solved

A series order question

  • February 3, 2023
  • 1 reply
  • 1846 views

Hi all experts

Hope you could do me a favor.

How could i express the following series order with programing function?

Tks

Ton is the constant value and Toff(t) is variable by having different "duration" Ton, Ton+T1, Ton+T1+T2

KC_10577235_0-1675422443556.png

 

 

 

 

 

Best answer by Werner_E

You may try a recursive approach either using he if-function

Werner_E_1-1675427911159.png

or the if-statement

Werner_E_2-1675428007696.png

And here is a non-recursive approach which should be more efficient for larger values of n

Werner_E_3-1675429301369.png

We can get rid of the local variable Rlast but have to treat n=1 as a special case and so have to use an if-statement

Werner_E_1-1675431073512.png

We can also hide that if-statement using a boolean factor

Werner_E_2-1675431190101.png

 

 

 

 

 

1 reply

Werner_E25-Diamond IAnswer
25-Diamond I
February 3, 2023

You may try a recursive approach either using he if-function

Werner_E_1-1675427911159.png

or the if-statement

Werner_E_2-1675428007696.png

And here is a non-recursive approach which should be more efficient for larger values of n

Werner_E_3-1675429301369.png

We can get rid of the local variable Rlast but have to treat n=1 as a special case and so have to use an if-statement

Werner_E_1-1675431073512.png

We can also hide that if-statement using a boolean factor

Werner_E_2-1675431190101.png

 

 

 

 

 

Kocela8-GravelAuthor
8-Gravel
February 3, 2023

Hi Werner

Thank you for the help.

If i would have better understand the logical flow in the programming, is there any debug command for watching the progress of step by step? like pause and start function, tks.    

25-Diamond I
February 3, 2023

@Kocela wrote:

Hi Werner

Thank you for the help.

If i would have better understand the logical flow in the programming, is there any debug command for watching the progress of step by step? like pause and start function, tks.    


No, unlike real Mathcad (version 15 and below) Prime unfortunately does not offer any kind of the debugging facilities you demand.
You may throw in "return" statements at specific positions of interest and return a single variable or a vector of variable values which are of interest to examine, but its tedious to do so and not very flexible. Its not a substitute for real debugging/trace capabilities.

Another way you may help yourself rudimentary is to use WRITEPRN and APPENDPRN to explicitely write informations of interest (variable values, recursion depth, ...) to an external text file. Still not a step by step debugger, requires code modification by throwing in the file access commands but can be quite handy in some situations.