OT: Friday Night Quiz

ndzied1

Lifetime Supporting Member
Join Date
Aug 2002
Location
Chicago, Illinois
Posts
2,856
It's been a while since someone has done one so here is a little quiz...

Can you make a single equation function for the attached graph without using if statements? Note that all segments of this graph are straight lines; there are no curves at the corners, just sharp corners. :unsure:

Profile1.gif
 
I like your signature.

It's been a while since someone has done one so here is a little quiz...

Can you make a single equation function for the attached graph without using if statements? Note that all segments of this graph are straight lines; there are no curves at the corners, just sharp corners. :unsure:

In what language? There needs to be a boolean operator that evaluates to 0 or 1 as a function of time. Then one can trigger different slopes at different times. This is sort of like writing step or ramp functions when using laplace transforms.

In C there is the ? : construct. It is a one line if then else.
One can also write a switch or case of statement on one line.

Ladder can activate compute blocks with contacts. That doesn't require a if statement.

Why do you ask? Obviously this isn't obvious. The general technique would be to start with a function
veloicty(t)=?(t>=0)*(5*t)+?(t>=1)*(-5*(t-1))+?(t>=5)*(-(t-5))+?(t>=6)*(t-6)+?(t>=8)*(-2*(t-8))+?(t>=9)*(2*(t-9))+?(t>=10)*(-4*(t-10))+?(t>=10.5)*(4*(t-10.5)).
The ?( ) function evaluate to 1 or 0 depending on whether it is true or false.

Sorry to spoil the fun.
 
You didn't spoil anything because you used the equivalent of "if" statements.

I wasn't thinking of a specific computer language, just math. I would classify your ?() function and the C language ?: construct as "if" statements.

The answer I'm looking for is a combination of standard mathematical constructs that would be understandable by any 8th grade student; even one that had absolutely no computer programming or spreadsheet knowledge.
 
From high school Algebra I remember the notation for writing a function that is defined differently along different parts of it's domain. It's called a compound or piecewise function. Your graph is trivial with linear equations if this is allowed. As far as I'm concerned this is a different "if" notation, just like Pete's suggested ternary operator.
 
Last edited:
From high school Algebra I remember the notation for writing a function that is defined differently along different parts of it's domain. It's called a compound or piecewise function. Your graph is trivial with linear equations if this is allowed. As far as I'm concerned this is a different "if" notation, just like Pete's suggested ternary operator.

I'll give you that the equation is non-linear (obviously from inspection). I struggled with saying that it is not an "if" notation but I think I'm ok on that ground... I don't need to make any comparison to evaluate any part of the equation. Maybe you'll call this a trick later but why would I post this if there wasn't something more than the obvious.

The function is not piecewise but a continuous function.

If by compound you mean that
f(x) = g1(x) + g2(x) + g3(x)+...
then it is compound.

Of course, the answer is not obvious, that is the reason for the whole thing.

Of course there are several ways to do this with a computer or look up table like there is for almost any problem. When I mentioned a game the other day, people wanted to try to solve it with a computer but I'm more interested in playing the game with a person and see how far I can get with the computing power in my brain...

The solution may be absolutely valueless but I was very surprised by it when I first saw it. It is something my dad developed when I was telling him about motion planning. I couldn't find it anywhere online which doesn't mean it hasn't been discovered before but maybe...? If so I will dub it "Captain's Equation" after what my nephew, his first grandson, called him when he was little.

Anyway, there's a clue above. I'm sure some will say the answer contains a form of "if" but if I can fall back on the precious computers, they don't have to make any comparison to evaluate the "trick" parts of the answer so I'll say it is not strictly an "if".
 
A piecewise function can be continuous. It's just a form of notation saying that f(x)=5x from [0,1] 0 from (1,5] 10-x from (5,6] 4 from [6,8], etc.

I imagine that you have a clever recursively defined function that includes both t and past factors and absolute values. I think that's what Pete's getting at, but I don't see how the solution is easy...
 
Generate a function for each segment of the profile.
Inside each function generate an integer multiplier. Bit 0 of the multiplier is evaluated using boolean logic from the integer part of the time. Select the boolean logic to turn the multiplier on for the relevant segment of the profile. Sum the results of all the function generators.

For example, for the first segment

itime = int(t);
iMult.Bit0 = (NOT it.Bit0) AND (NOT it.Bit1) ... etc;
Segment1Result= 5t * iMult;
 
Generate a function for each segment of the profile.
That is basically what I said.
Actually, I Think Norm is looking for ideas. Another way of doing this is to have a function that returns 0 out side a range and 0 to 1 inside a range of times.

v(t)=f(t,t(n),t(n+1)*v(n+1)+(1-f(t,t(n),t(n+1))*v(n)

f(t)=0 if t < t(n) or t > t(n+1)
f(t)=t-t(n)/(t(n+1)-t(n))

This hides the if statement if the f(t). However this requires indexing n.
Another variation is to have a f(t) that looks like this:
f(t,t(n-1),t(n),t(n+1).
This function would return 1 at t(n) and go down to 0 as t approaches t(n-1) or t(n+1). One can just write the code like this
Code:
v(t)=v(0)*f(t,t(0),t(0),t(1))+
     v(1)*f(t,t(0),t(1),t(2))+
     v(2)*f(t,t(1),t(2),t(3))+ ....
This still hides the if inside the f(t) function. I think this is the best Norm is going to get without using a table. He did say that the formula but be a line of code. However, this would be very inefficient because all the multiplications would be done and all the f function would need to be checked in the equation.

I think this is the best Norm will get if his function must be a line of code.
 
Sorry, I haven't had time to post more. Some family stuff came up this morning.

Here are some quick charts to get things moving in the right direction.

Fig1.gif Fig2.gif
 
Give us a break

I claim my first solution meet the original criteria.
It satisfies the conditions.
No IF is necessary. My ? function could be any function that returns a 1 or 0 based on the sign of the result of t-t0 or t>=0. Just rewrite my initial solution replacing the ?() with a f() and a f(t>=0) with a f(t-0) the result is the same.

If is obvious you have another solution in mind.
 
Pete - quit being ridiculous! The "? :" C construct is the ternary operator, which is shorthand notation for the if function - more accurately a 3 argument conditional expression. It's not a magical function to be defined to work however you wish. You could obviously overload the operator in C - that would like changing the "+" to an XOR function.

The piecewise function that I keep mentioning is the algebraic notation (remember OP said an 8th grader should understand) for that function that is defined differently along it's range - the math version of what you've been going for in function form (and what L D[AR2,P#0.0] did in pseudocode).

In C there is the ? : construct. It is a one line if then else.
One can also write a switch or case of statement on one line.

Peter Nachtwey said:
No IF is necessary. My ? function could be any function that returns a 1 or 0 based on the sign of the result of t-t0 or t>=0. Just rewrite my initial solution replacing the ?() with a f() and a f(t>=0) with a f(t-0) the result is the same.
 
Last edited:
OP - the a(x+|x|) is clever. I still don't see how you can make that graph into a single function...

If by compound you mean that
f(x) = g1(x) + g2(x) + g3(x)+...
then it is compound.

Oh, and a little pat on the back for myself...
I imagine that you have a clever recursively defined function that includes both t and past factors and absolute values
 
f(x)=2.5|x|-2.5|x-1|-0.5|x-5|+0.5|x-6|-|x-8|+|x-9|-2|x-10|+2|x-10.5|

This question is very similar to the only one I ever answered correctly on a Putnam exam.
 

Similar Topics

www.patchn.com has a hydraulic forum so I posted the problem there...
Replies
14
Views
6,310
Retirement Milestone It’s been an amazing 42 year trip. I have had great fun, seen amazing technologies, met good friends, learned something new...
Replies
36
Views
7,399
I usually can find what answers I need in the archives but thought I'm tired, it's been one of those weeks and I could not find the answer last...
Replies
1
Views
1,924
What is your ‘Strategy’ to these 4 ‘Insights’? This is taken from a slide in a sales presentation done recently, my edits are in ( brackets )...
Replies
1
Views
2,022
For you guys trained by the US Military and Drone aficionados. One of the first Carrier TO&L of a Drone...
Replies
20
Views
5,583
Back
Top Bottom