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):
You can expand the applet according to your screen resolution:
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.
6#Now, click Point > Intercept and create 4 points, in the region of interest:
7# On Geogebra, open a Spreadsheet and type (hamburger icon>View>Spreedsheet located at top-right):
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)
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
# Episode 01 #PySeries # An overview of the Opportunities Offered by Python in Engineering
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
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
15Episode#PySeries — Python — Python 4 Engineers — Keeping It In The Short-Term Memory — Test Yourself! Coding in Python, Again!
16Episode#PySeries — NumPy — NumPy Review, Again;) — Python Review Free Exercises
17Episode#PySeries — Generators in Python — Python Review Free Hints
18Episode#PySeries — Pandas Review…Again;) — Python Review Free Exercise
19Episode#PySeries — MatlibPlot & Seaborn Python Libs — Reviewing theses Plotting & Statistics Packs
20Episode#PySeries — Seaborn Python Review — Reviewing theses Plotting & Statistics Packs