source("http://macosa.dima.unige.it/r.R")    # If I have not already loaded the library
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
S 05 Equation systems

eqSystem(x) solves the linear system x
solut[n] is the n-th solution (if before "eqSystem" I put noPrint=1, the solutions are
# not printed and can only be seen with the solut command).
## Let's solve the system
# 8x + 7y + 6z = 7.4
# 7x +10y +12z = 8.65
#  x + 2y + 4z = 1.75 (see here)
S <- c(8,7,6,7.4, 7,10,12,8.65, 1,2,4,1.75); eqSystem(S)
# 0.55 0.30 0.15
solut[2] # To display only the 2nd solution (y)
# 0.3
# If the system has no solution or has infinitely many solutions it appears "singular
# system".
#
# For nonlinear systems, you can go graphically and find solutions up to 6 or 7 digits.
# But when you can relate to an equation in one variable, you can use equation
# resolution. Let's see a simple example:
#   Find the intersections between  2y+3x-15=0 (line) and (x-3)^2+(y-5)^2=4 (circle)
f = function(x) (15-3*x)/2; g = function(x,y) (x-3)^2+(y-5)^2-4
PLANE(0,7, 0,7); CURVE(g, "blue"); graph( f, 0,7, "blue")
# I get the chart below to the left:
  
# To find the intersections I consider:
h = function(x) g(x, f(x)); graphF( h, 0,4, "blue")
 
#       [ h(x)=0 when f(x)=y and g(x,y)=0 ]
 
# I get the chart above to the right, where I see the "x" solutions better
solution(h,0, 0,2)
# 1.153846
more(solution(h,0, 0,2))
# 1.15384615384615
fraction(solution(h,0, 0,2))
# 15/13
solution(h,0, 2,4)
# 3
# The x are 15/13 and 3, I find the y:
 
f(15/13); f(3)
# 5.769231  3
fraction( f(15/13) )
# 75/13
 
# The solutions are (x,y) = (15/13, 75/13) and (x,y) = (3.3), which I can control on
# the graph above, on the left

Other examples of use