Math010-LinearEquations-BasicGraphing

393 days ago by kyleeg133

CHAPTER 8: LINEAR EQUATIONS - BASIC GRAPHING WITH SAGE

HACCdg/SPRING 2011

Worksheet: Section 8.3.  Question Type 1: How to plot a given point or ordered pair in SAGE

Plot the point or ordered pair (-2,-5)

point((-2,-5)) 
       

How to plot more than one point at a time

point([(-2,-5),(0,-4),(8/3,9/2),(-1,4)]) #We can also plot several points at same time #but we must use [] to enclose the set of points! 
       

#8.3 Question Type 2: Determine if (1,2) is a solution of x - y = 4

Method 1: We separately evaluate the two sides and then compare:

x,y,L,R=var('x,y,L,R') #Define the variables #that is, we tell SAGE what variables we intend to use! x=1 #set x and y according to the point (1,2) y=2 L=x-y # Here we assign L the LHS of the equation R=4 # Here we assign R be the RHS of the equation #Press evaluate or shift-enter show(L) #Evaluate the LHS expression show(R) #Evaluate the RHS expressioN 
       
\newcommand{\Bold}[1]{\mathbf{#1}}-1
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}-1
\newcommand{\Bold}[1]{\mathbf{#1}}4
#Since L=-1 is not equal to R=4, we conclude that point (1,2) is not a solution of x-y=4 
       

Method 2: Let SAGE do the evaluation.

Another way to do this is to type in the equation and let SAGE itself deside whether the equation evaluates to "True" or to "False"

x=1 #This is how we store a value to a variable. x=1 means ASSIGN 1 to variable x. y=2 #ASSIGN to y the value 2 x-y==4 #The double equal sign == means AN EQUATION to SAGE 
       
False
False

The only thing about Method 2 is we just know it is "False" but SAGE doesn't tell us what L and R are. Now solve the other parts of the worksheet just below. Try to include enough comments to explain what you're doing as I have done here. Use the pound # sign to let SAGE know those are just comments.

#8.3 Question Type 3: Complete each ordered pair so that it is a solution of the given equation

Given Equation: x+2y=6 Ordered Pair to complete: (2,_)

Here we know x=2 but y=unknown # We can use the given equation to solve for y!

x,y=var('x,y') #Let's re-define x and y again as variables #just to make sure it SAGE doesn't issue an error message x=2 #Assign to x the value 2 (as given above solve(x+2*y==6,y) #Solve the equation for y 
       
[y == 2]
[y == 2]
#Since x=2 and y=2, the completed answer is (2,2) a solution of x+2y=6. #You may be given the linear equation y =(1/3)*x-2 involving fractions #Notice how the fraction is placed in () and don't forget to use * #SAGE will not evaluate this: (1/3)x. And will generate an error. Go ahead and solve that one as well using SAGE. 
       

In 8.4, we are told to complete the table.  We can use the above method since  the table is just composed of three ordered pairs or points!

x,y=var('x,y') x=3 solve(x-y==2,y) 
       
[y == 1]
[y == 1]
x,y=var('x,y') y=-2 solve(x-y==2,x) 
       
[x == 0]
[x == 0]
x,y=var('x,y') x=-1 solve(x-y==2,y) 
       
[y == -3]
[y == -3]

Now we plot all three points

point([(3,1),(0,-2),(-1,-3)]) #Note the proper use of [] to enclose the 3 pts! 
       
#Note the three points or ordered pairs "seem" to form a straight line! 
       
This is how you can draw a line given two endpoints!
line([(3,1), (-1,-3)]) #The line command only two points needed to plot this line! #Note it passes thru (0,-2) as well 
       

Using any two points above, we can actually draw the line through those three points. 

This is how we tell SAGE to draw a line given two endpoints!

x,y=var('x,y') solve(x-y==2,y) #We tell SAGE to first solve the equation x-y=2 for y. 
       
[y == x - 2]
[y == x - 2]

Another method to draw a line without using the tables.  SAGE needs to know just the equation! 

The three-point method above was just for us to be able to get a quick idea how the equation translates into a line.

plot(x-2,(-4,4)) #The (-4,4) simply means that we plot x in the range from -4 to 4. We can control how large our graph will be! #Try changing the range. Re-evaluate this cell and see what happens. 
       
Let us do 8.4 (1f): Graph the linear equation y= -2x - 1 This is already solved for y! So we can go ahead and plot it
plot(-2*x-1, (-10,10)) #You are free to change the range 
       
#This is a line that slopes downward as seen from left to right. 
       
#Below, we demonstrate how to use a known equation or formula to solve problems in SAGE 
       
Section 8.2 - A short review on circle graphs Remember the relation is given by a proportion angle is to 360 degrees as percent is to 100% Let A = unknown or given angle Let P = unknown or given percent
A,P=var('A,P') #tell SAGE that we need A,P to be variables 
       
Find the angle A if percent is 25%
solve(A/360==25/100,A) #solve the proportion for A 
       
[A == 90]
[A == 90]
#Angle is 90 degrees! As expected :) 
       
Find the percent P if angle is 60 degrees
solve(60/360==P/100, P) #This time, we solve for P 
       
[P == (50/3)]
[P == (50/3)]
#Or 16 2/3% (mixed form) #That's the exact percent in fraction form. To estimate in decimal, all we need to do is put a decimal point in one of those: 50./3 
       
16.6666666666667
16.6666666666667
#That around 16.7% (nearest tenth of a percent) 
       
#Using the above example, set up an equation for simple interest and compound interest! 
       

ENJOY! THE END

 

For future reference, commands used in this lesson are found in: http://www.sagemath.org/doc/reference/sage/plot/plot.html?highlight=linear%20plot

We only need the basic use of each command.

 

arrow2d((1, 1), (3, 3)) #You can disable a command just by putting # in front of it! 
       
c=var('c') c=circle((1,1), 0.5, rgbcolor=(1,0,0)) #c = circle((1,1), 1, rgbcolor=(1,0,0)) show(c) #Hmmm...the aspect ratio is not correct :( 
       
c.show(figsize=[5,5],xmin=-1,xmax=2,ymin=-1,ymax=2) #We show the circle above assigned to variable c with correct aspect ratio! #We want to make xmax and ymax the same so x and y axis measures the same! 
       
D=var('D') D=disk((3,1), 2, (pi/2, pi)) show(D) 
       
D.show(figsize=[5,5],xmin=-1,xmax=3.5,ymin=-1,ymax=3.5) #You want to make xmax and ymax the same so x and y axis measures the same! 
       
sage: g = Graphics() #just disable all of these by putting # signs in front of every line sage: for i in range(60): ... p = polygon([(i*cos(i),i*sin(i)), (0,i), (i,0)],\ ... color=hue(i/40+0.4), alpha=0.2) ... g = g + p ... sage: g.show(dpi=200, axes=False) 
       
sage: x = var('x') #just disable all of these by putting # signs in front of every line sage: P = plot(sin(x)/x, -4,4, color='blue') + \ ... plot(x*cos(x), -4,4, color='red') + \ ... plot(tan(x),-4,4, color='green') ... sage: P.show(ymin=-pi,ymax=pi) 
       
sage: y(x) = x*sin(x^2) #just disable all of these by putting # signs in front of every line sage: v = [(x, y(x)) for x in [-3,-2.95,..,3]] sage: show(points(v, rgbcolor=(0.2,0.6, 0.1), pointsize=30) + plot(spline(v), -3.1, 3)) 
       
sage: x = var('x') #just disable all of these by putting # signs in front of every line sage: g1 = plot(cos(20*x)*exp(-2*x), 0, 1) sage: g2 = plot(2*exp(-30*x) - exp(-3*x), 0, 1) sage: show(graphics_array([g1, g2], 2, 1), xmin=0)