Beginner needs help with 2d plotting



Julien,

you can use an if-then-else construct to define your function.

A function definition is done by := and Eulers number is %e

(%i1) f(x):= if x<=0 then (%e^x)/3 else 1$
(%i2) plot2d(f(x),[x,-2,2],[y,0,1.1])$

The plot shows a vertical connection between the parts. If you don't want to see this, define 
the two parts separately. In each I leave one part undefined, which remains unplotted.

(%i3) f1(x):= if x<=0 then (%e^x)/3$
(%i4) f2(x):= if x>0 then 1$
(%i5) plot2d([f1(x),f2(x)], [x,-2,2], [y,0,1.1])$

And make usage of some plot options to get a more advanced plot. E.g.

(%i6) plot2d([f1(x),f2(x)], [x,-2,2], [y,0,1.1], [gnuplot_preamble,"set grid;"])$


HTH
Volker van Nek

Am 11 May 2008 um 10:40 hat Julien Martin geschrieben:

> 
> Hello,
> 
> I have a function defined as follows:
> 
> F(x)=(e^x)/3 for x<=0
> F(x)=1 for x>0
> 
> I need to plot this function. How do I do that bearing in mind that the function definition changes 
> according to the values of x???
> 
> Can anyone please help?
> 
> Thanks in advance,
> 
> Julien.