sample if true

Use this forum to post Vensim related questions.
Post Reply
addor
Senior Member
Posts: 50
Joined: Mon Oct 27, 2003 9:45 am

sample if true

Post by addor »

I have a simple question to the "sample if true" function.

I have a function f that is small almost everywhere but has a big peak at time T, say f = 100 for time=T and else 0.1. So I want to cut the small noise such that only the peak will remain. I thought that I can do this with e.g.

only_peak = sample if true ( f<1, f , 0)

But this only cuts the noise before the peak while after the peak only_peak is a little bit biger than 1. If I select

only_peak = sample if true ( f<2, f , 0)

then only_peak is a littele bit biger than 2 after the peak, and so on.

How can I reach my goal, and why does the condition in the first argument of sample if true impacts the outcome after the condition has fullfilled?

Regards,
Peter
Attachments
sample_if_true.mdl
(1.84 KiB) Downloaded 276 times
Peter Addor
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Will an IF THEN ELSE statement do what you want?

Tony.
addor
Senior Member
Posts: 50
Joined: Mon Oct 27, 2003 9:45 am

Post by addor »

No, I don't see how (T isn't fix).

Why is

sample if true(f>1, f, 0)

not 0 whenever f is smaller than 1?
Peter Addor
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

That's not how "SAMPLE IF TRUE" works.

"SAMPLE IF TRUE" tests the condition, once it becomes true, "SAMPLE IF TRUE" holds it's value.

I am sure "IF THEN ELSE" is what you need.

only peak = if then else ( outflow trend > 1 , outflow trend , 0 )
addor
Senior Member
Posts: 50
Joined: Mon Oct 27, 2003 9:45 am

Post by addor »

Ok, I understand that

only_peak = sample if true(f>1, f, 0)

tests if f is bigger than 1. If not, it's 0. Well, have a look on my sample model. After T=20 the condition becomes valid, and for that case sample if true holds its value you said.

So why is only_peak not equal f after T=20?
Peter Addor
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

>> So why is only_peak not equal f after T=20?

It is equal to F each time the condition is true. If you look at a table with "outflow trend" and "only peak" at time=20, it takes on the value of F each time the condition is met. The condition is met until t=20.5078.

Hope this helps.

Tony.
addor
Senior Member
Posts: 50
Joined: Mon Oct 27, 2003 9:45 am

Post by addor »

Yes, sounds logically and simple.

My original problem was more complex, and I hoped to use sample if true. But as usual the question becomes trivial if I take it out of the context.

(originally I tried to (almost) deplete a stock say three times serially first if it achieved level a, then if it achieved level b<a and so on; the inflow may be constant, but 0 as long the outflow isn't 0. But this problem hasn't to do with sample if true and so doesn't belong to this thread).)
Peter Addor
Post Reply