# Qualche flash, per un'idea delle cose che si possono fare a tutti i livelli scolastici
# (in modo piu' semplice, e vario, di quanto si possa fare con un foglio di calcolo).
# A few flashes, for an idea of the things that can be done at all school levels
# (in a simpler, and more varied, way than with a spreadsheet).
 
source("http://macosa.dima.unige.it/r.R")
 
500/23; more(500/23)
# [1] 21.73913
# [1] 21.7391304347826
fraction(21.7391304347826)
# [1] 500/23
div(500,23); divInt(500,23, 25)
# [1] 21 17
# [1] 21  7  3  9  1  3  0  4  3  4  7  8  2  6  0  8  6  9  5  6  5  2  1  7  3  9
# [1] 3
round(500/23,-1); round(500/23,0); round(500/23,2)
# [1] 20
# [1] 22
# [1] 21.74
pi; more(pi)
# [1] 3.141593
# [1] 3.14159265358979
b1=13; b2=4; h = 5; (b1+b2)*h
# [1] 85
fraction(  (14+25) / ( 5*(12+14) )  )
# [1] 3/10
c(42,20,5,6)/3
# [1] 14.000000  6.666667  1.666667  2.000000
dat = c(42,20,5,6); dat/3; sort(dat)
# [1] 14.000000  6.666667  1.666667  2.000000
# [1]  5 6 20 42
min(dat); max(dat); length(dat); sum(dat)
# [1] 5
# [1] 42
# [1] 4
# [1] 73
N = 25755; C = 12068; S = 20843; Italia = c(N,C,S)
Pie(Italia);
Strip(Italia); above("North",21); above("Center",53); above("South",82)
# %  43.90107 20.57069 35.52824

BF=4; HF=2                      # 2-inch base, 4-inch heigtht
PLANE(-4,4, -2,2)               # with PLANE x-scale and y-scale are equal
segm(-4,1, 4,-2, "red")
POINT(-4,1,"brown"); POINT(4,-2,"blue")
circle(2,0, 1, "green")
P=c(-4,-2); Q=c(0,1); R=c(-2,2)
POINT(P[1],P[2],1); POINT(Q[1],Q[2],1); POINT(R[1],R[2],1)
text(-4.5,-2,"P"); text(0.5,1,"Q"); text(-2.5,2,"R")
x = c(P[1],Q[1],R[1],P[1]); y = c(P[2],Q[2],R[2],P[2])
polyline(x,y,"blue")
      

angle(P,R,Q)
# 90
Plane(2012,2019, 0,11)
year = 2012:2019
K = c(2.2, 7.1, 6.3, 7.5, 10.4, 5.2, 5.0, 7.6)
polyline(year,K, "blue"); POINT(year,K, "brown")
abovex("year"); abovey("K")
      
# If I wanted I could put the data in a table (see):
T = array(dim=c(8,2)); data.entry(T)
      
 
BF=4; HF=3
Plane(-3,8,-10,20)         # with Plane x-scale and y-scale may be different
F = function(x) -7+(x-3)^2
graph(F, -3,8, "red")
maxmin(F,-2,6); F(maxmin(F,-2,6))
# [1] 3
# [1] -7
POINT(5,F(5), "blue"); POINT(-2,F(-2), "blue")
point_point(-2,F(-2), 5,F(5))
# [1] 22.13594
deriv(F,"x")
# 2 * (x - 3)
integral(F,-2,5); fraction(integral(F,-2,5))
# [1] -4.666667
# [1] -14/3
Gintegr(F,-2,5, "blue")
      
# A set of beans (un insieme di fave)
beans = c(
1.35,1.65,1.80,1.40,1.65,1.80,1.40,1.65,1.85,1.40,1.65,1.85,1.50,1.65,1.90,
1.50,1.65,1.90,1.50,1.65,1.90,1.50,1.70,1.90,1.50,1.70,1.90,1.50,1.70,2.25,
1.55,1.70,1.55,1.70,1.55,1.70,1.60,1.70,1.60,1.75,1.60,1.75,1.60,1.80,1.60,
1.80,1.60,1.80,1.60,1.80,1.00,1.55,1.70,1.75,1.30,1.55,1.70,1.75,1.40,1.60,
1.70,1.75,1.40,1.60,1.70,1.80,1.40,1.60,1.70,1.80,1.40,1.60,1.70,1.80,1.40,
1.60,1.70,1.80,1.40,1.60,1.70,1.80,1.40,1.60,1.70,1.80,1.40,1.60,1.70,1.80,
1.45,1.60,1.70,1.80,1.50,1.60,1.70,1.80,1.50,1.60,1.70,1.85,1.50,1.60,1.70,
1.85,1.50,1.60,1.75,1.90,1.50,1.60,1.75,1.90,1.50,1.65,1.75,1.90,1.55,1.65,
1.75,1.95,1.55,1.65,1.75,2.00,1.55,1.65,1.75,2.30,1.35,1.65,1.80,1.40,1.65,
1.80,1.40,1.65,1.85,1.40,1.65,1.85,1.50,1.65,1.90,1.50,1.65,1.90,1.50,1.65,
1.90,1.50,1.70,1.90,1.50,1.70,1.90,1.50,1.70,2.25,1.55,1.70,1.55,1.70,1.55,
1.70,1.60,1.70,1.60,1.75,1.60,1.75,1.60,1.80,1.60,1.80,1.60,1.80,1.60,1.80,
1.00,1.55,1.70,1.75,1.30,1.55,1.70,1.75,1.40,1.60,1.70,1.75,1.40,1.60,1.70,
1.80,1.40,1.60,1.70,1.80,1.40,1.60,1.70,1.80,1.40,1.60,1.70,1.80,1.40,1.60,
1.70,1.80,1.40,1.60,1.70,1.80,1.40,1.60,1.70,1.80,1.45,1.60,1.70,1.80,1.50,
1.60,1.70,1.80,1.50,1.60,1.70,1.85,1.50,1.60,1.70,1.85,1.50,1.60,1.75,1.90,
1.50,1.60,1.75,1.90,1.50,1.65,1.75,1.90,1.55,1.65,1.75,1.95,1.55,1.65,1.75,
2.00,1.55,1.65,1.75,2.30
)
stem(beans)
 The decimal point is 1 digit(s) to the left of the |
  10 | 00
  11 | 
  12 | 
  13 | 0055
  14 | 000000000000000000000055
  15 | 0000000000000000000000005555555555555555
  16 | 0000000000000000000000000000000000000000005555555555555555555555
  17 | 0000000000000000000000000000000000000000005555555555555555555555
  18 | 00000000000000000000000000000055555555
  19 | 000000000000000055
  20 | 00
  21 | 
  22 | 55
  23 | 00
histo(beans)
[the distance of the sides of the grid is   5 %] 
  Frequencies and percentage freq.: 
   2, 0, 0,    4,  24,   40,   64,   64,   38, 18,    2, 0,  4
0.77, 0, 0, 1.54,9.23,15.38,24.62,24.62,14.62,6.92,0.77,0,1.54
      
# Deaths by age group (morti per classi di età) in Italy in 1951
interv = c(0, 5, 10, 20, 30, 40, 50, 60,  75, 100)
freq =    c(729,35,77, 132,134,285,457,1401,1569)
histoclas(interv,freq)
      
The mean (brown dot) is about  58.31897 
For percentages use  PERC  For other statistics use  morestat()
morestat()
   Min. 1st Qu.  Median    Mean  3rd Qu.   Max. 
  1.000   1.550   1.650   1.659   1.750   2.300 
    The brown dots are 5^ and 95^ percentiles 
           The red dot is the mean 
 
h = function(x,y) x*y*exp(-x^4-y^4)
x = y = seq(-2,2, len=31); z = outer(x,y,h)
BF=3.5; HF=3; NW()  
MARG(0.2); G=persp(x,y,z,phi=40,theta=30,d=20,col="cyan",ticktype="detailed",expand=0.5,cex.axis=0.8,cex.lab=0.8)