Introduction to Mathematica as a Computational Software

Omeiza Olumoye       11/18/2014

* A general note of caution is when a function is blue - it indicates the function has not being assigned *

(2^4000);

:= is an assignment statement

f[x_]:=(x^3)Cos[x]+(E^x)Sin[x]

D[f[x],{x,1}];

D[f[x],{x,2}];

% refers to the most recent computation

Simplify[%];

g[x_,y_]:=(5^y)Sin[x ]-7(x^3)((Cos[y])^2);

Take the derivative of g[x,y] by taking the partial derivative with respect to x-twice and then y-twice

D[g[x,y],{x,2},{y,2}];

Simplify[%];

Solving a quadratic equation (always a double equal sign instead of one)

Solve[(x^2)-9x+4==0,x];

Series[(E^x),{x,0,6}];

Plot[Sin[x],{x,-2π,2π}];

Plot[{Sin[x],Cos[x]},{x,-2π,2π},PlotStyle->{Red,Green}];

Plot3D[Sin[(x^2)+(y^2)],{x,-2,2},{y,-2,2}];

Linear Programming 
Food Name	Carbs/Unit	Proteins/Unit	Fat/Unit	Price/Unit
Rice	           53	           4.4	           0.4	           0.5
Quinoa	40	           8	           3.6	           0.9
Tortilla	           12	           3	           2	           0.1
Lentils	           53	          12	           0.9	           0.6
Broccoli	6	          1.9	           0.3	           0.4

Nutrient	            Minimum	Maximum
Carbohydrates	 100	           1000
Protein	            10	           100
Fat	                       0	           100

Food Name	Decision Variable
Rice	           (Subscript[x, r])
Quinoa	(Subscript[x, q])
Tortilla	           (Subscript[x, t])
Lentils	           (Subscript[x, l])
Brocolli	(Subscript[x, b])

Objective Function will be min   0.5(Subscript[x, r ])+ 0.9(Subscript[x, q])+ 0.1(Subscript[x, t])+0.6(Subscript[x, l ])+ 0.4(Subscript[x, b])
such that
100 ≤  53(Subscript[x, r ]) + 40(Subscript[x, q ]) + 12(Subscript[x, t ])+ 53(Subscript[x, l ])+  6(Subscript[x, b ]) ≤ 1000
10   ≤ 4.4(Subscript[x, r ]) + 8(Subscript[x, q ]) + 3(Subscript[x, t ])+ 12(Subscript[x, l ])+  1.9(Subscript[x, b ]) ≤ 100
0     ≤ 0.4(Subscript[x, r ]) + 3.6(Subscript[x, q ]) + 2(Subscript[x, t ])+ 0.9(Subscript[x, l ])+  0.3(Subscript[x, b ]) ≤ 100

LinearProgramming[{0.5,0.9,0.1,0.6,0.4},{{53,40,12,53,6},{4.4,8,3,12,1.9},{0.4,3.6,2,0.9,0.3},{53,40,12,53,6},{4.4,8,3,12,1.9},{0.4,3.6,2,0.9,0.3}},{{100,1},{10,1},{0,1},{1000,-1},{100,-1},{100,-1}}];

Add a constraint such that we spend not more than 60% of the total cost on any of the food items

LinearProgramming[{0.5,0.9,0.1,0.6,0.4},{{53,40,12,53,6},{4.4,8,3,12,1.9},{0.4,3.6,2,0.9,0.3},{53,40,12,53,6},{4.4,8,3,12,1.9},{0.4,3.6,2,0.9,0.3},0.6*{-((0.4*0.5)/0.6),0.9,0.1,0.6,0.4},0.6*{0.5,-((0.4*0.9)/0.6),0.1,0.6,0.4},0.6*{0.5,0.9,-((0.4*0.1)/0.6),0.6,0.4},0.6*{0.5,0.9,0.1,-((0.4*0.6)/0.6),0.4},0.6*{0.5,0.9,0.1,0.6,-((0.4*0.4)/0.6)}},{{100,1},{10,1},{0,1},{1000,-1},{100,-1},{100,-1},{0,1},{0,1},{0,1},{0,1},{0,1}}];

References
http://neos-guide.org/content/diet-problem
https://reference.wolfram.com/language/tutorial/ConstrainedOptimizationLinearProgramming.html