Page 1 of 1

Piecewise graphs

Posted: Mon Feb 16, 2009 5:17 am
by DCdenizen
Hi David, any chance there's some way to graph piecewise functions? Ie...y = a + b*(x-L)^4, but only graph where (x-L) >= 0?

Posted: Mon Feb 16, 2009 11:42 am
by DPlotAdmin
Start at x=L? :D

I'm guessing that's not what you're after, though.

If you want to plot a function that results in an illegal operation for certain ranges of X (say sqrt of a negative number) you can use if(test,if true,if false) (more or less identical to the form used in Excel). Set the "if false" part to some constant well outside the range in Y you're interested in, then use Options>Amplitude limits to set the range outside which points will be ignored.

Posted: Mon Feb 16, 2009 1:47 pm
by DCdenizen
Haha, your intuition is correct...not exactly what I was after :-)

The equation is actually of the form: y=A+B*(x-L)^m+C*(x)^n

What I'd meant to write is that the b*(x-L)^4 term should be zero for any negative value of (x-L).

Posted: Mon Feb 16, 2009 2:07 pm
by DPlotAdmin
If F (your m) is a whole number, then this will work:

if(x-K<0,A+C*x^D,A+B*(x-K)^F+C*x^D)

(where K is your L)

If F is not a whole number you'll have to do some manual operations to get this to work. The problem in DPlot is that both the "if true" and "if false" parts are evaluated, whether the test is true or not. Off the top of my head I can't think of a good workaround in this case; you'll have to generate one curve for (x-K)<0 and another for (x-K)>=0, then lump the two together with Edit>Combine Curves.

Posted: Mon Feb 16, 2009 4:16 pm
by DCdenizen
I did the the logic in VBA for that reason, as the numbers aren't whole. I fed two separate FunctionofXY1Y2 commands the relevant equations, and only allowed them to graph across the valid x-values. Thanks!