Geogebra Plus Linear Programming
Tags: Python, Geogebra, Linear Programming, Python3, Linear Regression Python

Geogebra Plus Linear Programming

We’ll Create a Geogebra program to help us with our linear programming — #PySeries#Episode 02

First, we’ve got this problem that comes from the math to your course guide from the Pingree school.

It is the tape’s verse CDs example:

Suppose you want to buy some tapes and CDs. Does anyone really buy tapes anymore? Anyway, you can buy up to 11 tapes; You can buy up to 7 CDS, but you want at least 3; You must get enough tapes or CDs to hold at least 10 hours of music; Each tape holds about 45 minutes of music and each CD holds an hour a tape costs $8 and a CD costs $12; So how many tapes and CDs should you buy to minimize your cost?

Let’s see the solution using Geogebra than in the end I will present the Python solution.

1# Define Your Variables:

x=The number of tapes to buy;

y=The number of CDs to buy;

2# Translate your constraints:

x<=11

3<=y>=7

600<=45x+60y

3# Type your objective Function:

T(x,y)=8x+12y

4# Open a Geogebra New Activity session, Hit Geogebra, Create an Applet and get a name to your applet (mine is GeoPlusLinearProg):

Fig 1. Opening and Creating New Activity in Geogebra App.

You can expand the applet according to your screen resolution:

Fig 2. Expanding the Applet view!

Just fine!

5# On Geogebra, on the left, type the inequality as well as equality like this:

a: x <= 11

b: x = 11

c: 3 <= y <= 7

d: y = 3

e: y = 7

f: 45*x + 6*y >= 600

g: 3*x + 4*y = 40

The regions in the graph are presented, now configure them according to your taste, clicking on each inequality and changing the style and color properties. Here are my settings.

Fig 3. Entering all the constraints and equations.

6#Now, click Point > Intercept and create 4 points, in the region of interest:

Fig 4. Separating the solution region.

7# On Geogebra, open a Spreadsheet and type (hamburger icon>View>Spreedsheet located at top-right):

Fig 5. Delimiting each intercept points of the solution.

Now, in the spreadsheet type this (drag the little rectangle down):

Points - Total Cost, T

A =8*x(A2)+12*y(A2)

B =8*x(A3)+12*y(A3)

C =8*x(A4)+12*y(A4)

D =8*x(A5)+12*y(A5)

Fig 6. We found the region of the solution; Any of the combinations are valid; the lowest cost is 9.33 Tape and 7 CDs (A3).

Any of the vertices of the trapeze serve as an answer. I choose the second option(9 Tapes and 3 CDs).

Let’s see what python decides …

8# Python Solution:

from pulp import *

prob=LpProblem('Example', LpMaximize)

x1=LpVariable("Tape", 0)

x2=LpVariable("CD", 0)

prob += x1<=11

prob += x2>=3

prob += x2<=7

prob += 45*x1+60*x2<=600

prob += 8*x1+12*x2

prob.solve()

for v in prob.variables():

print(v.name,"=", v.varValue)

print("Total Cost = ", value(prob.objective)) CD = 7.0

Tape = 4.0

Total Cost = 116.0

Fig 7. Using Visual Studio code App; please see this post about it: Python 4 Engineers — Exercises! linked bellow…

And that’s all for now!

I hope you were impressed with the Geogebra app like I am!

Bye for now!

See you in the next episode of Python Series!

https://docs.google.com/document/d/1DkycafWLUZeprvnTQcSgaasyniTWTeDe4cEzEnN6hes/edit?usp=sharing

References & Credits

Fig 8. Here is the inspiration for this lesson! Thanks to Wicked Math 👌

Posts Related:

00Episode#PySeries — Python — Jupiter Notebook Quick Start with VSCode — How to Set your Win10 Environment to use Jupiter Notebook

01Episode#PySeries — Python — Python 4 Engineers — Exercises! An overview of the Opportunities Offered by Python in Engineering!

02Episode#PySeries — Python — Geogebra Plus Linear Programming- We’ll Create a Geogebra program to help us with our linear programming (this one)

03Episode#PySeries — Python — Python 4 Engineers — More Exercises! — Another Round to Make Sure that Python is Really Amazing!

04Episode#PySeries — Python — Linear Regressions — The Basics — How to Understand Linear Regression Once and For All!

05Episode#PySeries — Python — NumPy Init & Python Review — A Crash Python Review & Initialization at NumPy lib.

06Episode#PySeries — Python — NumPy Arrays & Jupyter Notebook — Arithmetic Operations, Indexing & Slicing, and Conditional Selection w/ np arrays.

07Episode#PySeries — Python — Pandas — Intro & Series — What it is? How to use it?

08Episode#PySeries — Python — Pandas DataFrames — The primary Pandas data structure! It is a dict-like container for Series objects

09Episode#PySeries — Python — Python 4 Engineers — Even More Exercises! — More Practicing Coding Questions in Python!

10Episode#PySeries — Python — Pandas — Hierarchical Index & Cross-section — Open your Colab notebook and here are the follow-up exercises!

11Episode#PySeries — Python — Pandas — Missing Data — Let’s Continue the Python Exercises — Filling & Dropping Missing Data

12Episode#PySeries — Python — Pandas — Group By — Grouping large amounts of data and compute operations on these groups

13Episode#PySeries — Python — Pandas — Merging, Joining & Concatenations — Facilities For Easily Combining Together Series or DataFrame

14Episode#PySeries — Python — Pandas — Pandas Dataframe Examples: Column Operations