Octave: plotting graph of function

 

#  several graphs (with colors) in one plot 


## time step constant
h=0.1;

## name the colors ...
blue="b";
black="k";
red="r";
blue="c";

### everything in one plot ...
hold("on")

## the domain to be plotted ...
xlim([-2,2])
ylim([-2,2])

## no box around the plot ...
axis("off")
## set axes ratio to scale ...
axis("square")

### coordinate axes in black ...
# !! format [x1,x2],[y1,y2]
plot([-2,2],[0,0],black)
plot([0,0],[-2,2],black)


### prosty graf funkce
x=0.1:h:1;
plot(x,log(2*x),red);


### parametric plot is more versatile, however ...
#  ... only a quarter of the circle will be visible ...
# [-2,2] bude videt jenom ctvrtka...

t=linspace(0,2*pi,50)';
plot(cos(t)-2,2+sin(t),blue);


###
# define my own function "fce" and time iterval "I"
fce = @(t) t/sqrt(t*t+1);
I=-1:h:0.4;
### nota bene: the function must be applied
###	_element-wise_ to the vector I, 
###  using the command _arrayfun_
#
plot(t,arrayfun(fce,t),blue);


## we can save the output in eps or jpg format:
#   (format barevny .eps respektive .jpg)
print -depsc obr1.eps
print -djpg obr1.jpg