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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

A series order question

KC_10577235
5-Regular Member

A series order question

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

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

 

 

 

 

 

View solution in original post

5 REPLIES 5

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

 

 

 

 

 

KC_10577235
5-Regular Member
(To:Werner_E)

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.    


@KC_10577235 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.

KC_10577235
5-Regular Member
(To:Werner_E)

Hi Master Werner

How to reform the program below to array or vector forms?

e.g: T(3)=[T1, T2, T3]

Tks

 

KC_10577235_0-1675494804032.png

 

Quick and dirty without changing function T

Werner_E_0-1675511233614.png

And a bit more efficient using a modified function

Werner_E_1-1675511281308.png

 

 

Top Tags