# Lineare Gleichungen

Mathematik in wxMaxima www.mathematik-verstehen.de Haftendorn Okt 2010

Achtung: Durch Anklicken der linken Zellmarkierung kann man die 
Abschnitte und auch einzelne Zellen aufklappen und auch wieder zuklappen.

Endung *.wxmx ist komfortabel. Ist die Endung *.wxm muss man 
erst noch alle Ausgaben neu erzeugen. Mit Strg r  werden alle aufgeklappten Zellen ausgewertet.
Zum Lernen ist es besser die Zellen einzeln (mit Shift+Enter) auszuwerten.

Werte einzelne Zellen aus mit Shift-Enter. 
Auswertung in einem Rutsch: Falte alle Abschnitte auf,
werte alle Zellen mit Strg r aus ( auch Menu Cell Alle Zellen auswerten).

## Einleitung

In Kapitel 2 stehen die von David Miller entwickelten einfachen Funktionen,
mit denen man leicht mit Geradenbleichungen umgehen. 
Um sie zu verwenden muss man Kapitel 2 einmal ausfalten und den großen blauen Block 
einmal auswerten (sghift Enter), dann wieder zufalten. 
Man brauch das nicht zu lesen, denn im Folgenden
werden alle Möglichkeiten ausführlich mit deutsche Kommentaren vorgestellt.

## Definitionen von David Miller

File:                 linear-eqns-how-to.wxm
Version:	       1.1
Date:	       27 January 2009
Author:	       David E. Miller <david.miller@quaoar.us>

Purpose:       Functions to solve, plot and to determine the slope and intercepts of
                       linear equations.

Abstract

Maxima may be used to find the values of conventional attributes of linear equations
of the form Ax+By+C=0. These include the slope, x- and y-intercepts. Expressions
of this form (or any equivalent form) may be solved in terms of  x or y. Also, the value
of y may be found for a specified value of x and also a value of x for a value of y. If the
slope and y-intercept of linear equation is known, the expression of the linear equation
is obtained. If the coordinates of any two points are known, the expression of the
associated equation is also obtained. Finally, a function for plotting the expression of
the linear equation is provided with basic arguments to control the plot display.
-----------------------------------------------------------------------------------------------------------------------
Notes:

This session is not comprehensive or exhaustive, however some of the basic
Maxima functions and features are demonstrated. Please note that there may
be alternative ways to form the Maxima statements of this session. Please
refer to the Maxima documentation and the wxMaxima help.

Input lines shown below may be executed by selecting the input by clicking on
the input with the mouse and pressing Ctrl-Enter -- or Shift-Enter on some
implementations. Use the down arrow key to move from a highlighted text area
to the next line of input.

These functions are defined and described in terms of x and y. Thus the expression
for the linear equation must be in terms of the names x and y. However, there is a
workaround for using an expression of a linear equation with names other than x and
y which is detailed in this tutorial at the end. If this method is used, it is up to the user
to keep matters straight.
-----------------------------------------------------------------------------------------------------------------------

/* 
Usage: 	An argument (eqn) that is a linear equation of the form Ax + By +C = 0 or any equivalent form.
		
		slope(eqn) returns a string with the slope of equation.
		
		intercepts(eqn) returns a string with the value of the x and y intercepts.
		
		eqnmxy(eqn) returns the slope, x intercept and y intercept in two ways:
			1. In the form of the values of the names m (slope), xint (x intercept), yint (yintercept).
			2. In the form of the values of the elements the list named mxy where:
				mxy[1] is the slope, mxy[2] is the x intercept, and mxy[3] is the y intercept.
		
		clearmxy() kills number values of the the list mxy[] and the names m, xint, yint.
		
		solveforxy(eqn,forxy) solves the equation (eqn) for x or y:
							solveforxy(eqn, x) gives eqn in terms of y equal to an expression of x and
							solveforxy(eqn, y) gives eqn in terms of x equal to an expression of y
		
		solveatxy(eqn,atxy) solves the equation (eqn) for y at a value of atxy of x=n  or for x at value of atxy of y=n:
							solveatxy(eqn, x= 4) gives the value of y at x=4 as a list object [x,y] and 
							solveatxy(eqn, y=-3) gives the value of x at y=-3 as a list object [x,y].
		
		eqnmb(m,b) returns an equation in the form of y=mx+b where m is the slope and b is the y intercept
		
		eqnpp(pt1,pt2) returns an equation in the form y=mx+b given coordinates of two points  as argumentsin the form of
			two lists: pt1 is [x1,y1] and pt2 is [x2,y2]
                
                convxy(eqnxy,a,b) converts an equation in terms of x and y into an equation in terms of a and b respectively
		
		plot(eqn,xmin,xmax) returns a 2D plot of eqn with the minimum value of x as xmin and the maximum value of x as xmax
*/
   
slope(eqn):=sconcat("The slope is: ",coeff(expand(rhs(solve([eqn], [y])[1])),x,1))$
intercepts(eqn):=sconcat("x intercept is: (", ev(rhs(solve([eqn], [x])[1]),y=0),",0)"," and y intercept is: (0,", ev(rhs(solve([eqn], [y])[1]),x=0),")")$
eqnmxy(eqn):=mxy:[m:coeff(expand(rhs(solve([eqn], [y])[1])),x,1),xint:ev(rhs(solve([eqn], [x])[1]),y=0),yint:ev(rhs(solve([eqn], [y])[1]),x=0)]$
clearmxy():=kill(mxy,m,xint,yint)$
solveforxy(eqn,forxy):=solve([eqn], [forxy])[1]$
solveatxy(eqn,atxy):=[if lhs(atxy)=x then rhs(atxy) else rhs(solve(ev(eqn,atxy),[x])[1]),if lhs(atxy)=y then rhs(atxy) else rhs(solve(ev(eqn,atxy),[y])[1])]$
eqnmb(m,b):=y=m*x+b$
eqnpp(pt1,pt2):=expand(solve((y-pt1[2]=((pt2[2]-pt1[2])/(pt2[1]-pt1[1]))*(x-pt1[1])),[y])[1])$
plot(eqn,xmin,xmax):=wxplot2d(rhs(solve([eqn], [y])[1]), [x,xmin,xmax],[xlabel,"x"],[ylabel,"y"])$

## Anleitung zu den Möglichkeiten mit Geraden

### Definition der Geradengleichung

Examples of use:

eq1:3*y-7*x=10;

This is the linear equation of interest.

Now try:

slope(eq1);
intercepts(eq1);
eqnmxy(eq1);
m; mxy[1];
xint; mxy[2];
yint; mxy[3];
solveforxy(eq1,x)
solveforxy(eq1,y)
p1:solveatxy(eq1,x=4);
p2:solveatxy(eq1,y=-3);
eqnmb(m,yint);
eqnpp(p1,p2);
plot(eq1,-5,5);
clearmxy();

### Erste Berechnungen

The slope (Steigung) is:

slope(eq1);

The intercepts (Schnittpunkte mit den Achsen) are:

intercepts(eq1);

The slope and intercepts can be assigned names
and put in a list with one command.
Man kann diese Befehle Zusammenfassen.
Here is the list [slope, x intercept, y intercept]
 [Steigung, x-Achsenabschnitt, y-Achsenabschnitt]:

eqnmxy(eq1);

Below are the names for slope, x intercept, and y intercept:

Es sind schon Namen vorgesehen, man kann aber auch wie üblich
mit liste[n] auf die Liste zugreifen

mxy;

m; mxy[1];

xint; mxy[2];

yint; mxy[3];

### Umformungen in andere Gleichungsform

Solve for x in terms of y:

solveforxy(eq1,x);

Solve for y in terms of x:

solveforxy(eq1,y);

### Bestimmung einer zweiten Koordinate, wenn eine bekannt

Solve for y  at x=4 and name it point p1:

p1:solveatxy(eq1,x=4);

Solve for x  at y=-3 and name it point p2:

p2:solveatxy(eq1,y=-3);

### Aufstellen der Gl. aus Punkt und Steigung

Find the equation using the slope (Steigung) and y intercept, y-Achsen-Abschntt:

eqnmb(m,yint);

### Aufstellen der Gl. aus zwei Punkten

Find the equation using the two points p1 and p2 :
Dabei sind die Punkte durch [p1x,p1y]... gegeben

eqnpp(p1,p2);

Plot the equation from xmin=-5 to xmax=5:

plot(eq1,-5,5);

Wenn man diese Datei als *.wxmx speichert, bleiben die Ausgaben, auch die Grafik
erhalten.

The output graphics file (maxout.png) is not saved but is displayed as shown above
unless the plot function is input with a $ instead of a semicolon (;) as it is here.
To save this plot file, click inside the graph above to change it to a grey highlight
color, then right click inside the grey box displayed. Now move the mouse over the
the Save image message box that appears until it reverses its color and then click on
the inside of this message box. Use the dialog window that appears to save the plot.

Note: The entire wxMaxima file and all plots may be exported to HTML form by selecting 
File --> Export to HTML from the wxMaxima menu bar.

To clear values to start over with a new equation:

## Anwendungen in anderen Zusammenhängen

### Vorgehen, wenn die Variablen anders heißen

clearmxy();

Below is a workaround for using names in the expression for the linear equation other
than x an y. Assume that these are a and b. First assign to the desired names the names
x and y:

(a:x,b:y)$

Now enter the expression for the linear equation in terms of these names using the
following with the expression in parentheses prefixed by a single quote:

eq2:'(3*b-7*a=10);

Merke ' vor einem Ausdruck unterdückt die Auswertung, man sieht also a und b

Now the name ''eq2 may be used in the above functions for the attributes of the expressions
for linear equations as before. In order to do this use ''eq2 instead of merely eq2. This results
in the following:

Merke '' erzwingt die Auswertung, man sieht x und y 
Achtung, dass sind zwei: ' und nocheins ', keines falls das Anführunszeichen schift 2.

''eq2;

### Letzlich kann man x,sy oder die neuen Variablen nehmen.

slope(''eq2);

intercepts(''eq2);

eqnmxy(''eq2);

The values above are the same as before.

eq2;

However, the expression above for the equation is in terms of a and b
instead of x and y.

Now solve for x or y -- or a or b.

solveforxy(''eq2,x);

solveforxy(''eq2,y);

solveforxy(eq2,a);

solveforxy(eq2,b);

The above show that the results are in terms of x and y not a and b.
In this case, either eq2 or ''eq2 works as well as a or b as the solve 
"for" argument. It is best to be consistent and  only use ''eq2 as the
name form and x or y as the solve "for" argument.

Solve for some points:

solveatxy(''eq2,x=4);

solveatxy(''eq2,y=-3);

p1:solveatxy(''eq2,a=4);

p2:solveatxy(''eq2,b=-3);

The above show that the solveatxy() function works if the name is x or y,
or a or b,  that the known value is assigned to. Use the form that is
most useful.

eqnmb(m,yint);

eqnpp(p1,p2);

These functions work as before. They are always in terms of x and y.

(ev(%,x:'a,y:'b));

To convert these to names a and b use use the form above.  Here
% is the value of eqnmb(m,yint). The result is the same if the value
of eqnpp(p1,p2) is used instead. The use of % as a  name can get
tricky. It is better practice to save these values using an assignment
to a name as:

eqnxy:eqnmb(m,yint);

(ev(eqnxy,x:'a,y:'b));

convxy(eqnxy,'a,'b):=(ev(eqnxy,x:a,y:b));

The above expression defines a function convxy() to do the job.
Instead of typing the previous expression do the following:

convxy(eqnxy,a,b);

Converts the eqn in x and y (named eqnxy) to a and b respectively.

convxy(eqnxy,p,q);

Converts the eqn in x and y (named eqnxy) to p and q respectively.

convxy(eqnxy,v,w);

Converts the eqn in x and y (named eqnxy) to v and w respectively.

myeqn:eqnxy$

convxy(myeqn,s,t);

This function does not depend on the name eqnxy. Any name will
do if it is assigned the correct expression. The name myeqn was
used above and x and y were converted to s and t respectively.

plot(''eq2,-5,5);

The form plot(eq2,xmin,xmax) also works.

The above workaround is useful if the goal is preserve the form of the original
expression for the linear equation in terms of names other than x and y. The
name eq2 retains the original names of the variables. This allows other
expressions to use eq2 as is:

eq2;

clearmxy();

"Good Luck!"$