restart; -1 

y := `+`(`+`(`*`(`+`(339, `-`(`*`(`/`(1, 100), `*`(x1))), `-`(`*`(`+`(`*`(3, `*`(x2))), `/`(1, 1000)))), `*`(x1)), `*`(`+`(399, `-`(`*`(`+`(`*`(4, `*`(x1))), `/`(1, 1000))), `-`(`*`(`/`(1, 100), `*`(x... 

`+`(`*`(`+`(339, `-`(`*`(`/`(1, 100), `*`(x1))), `-`(`*`(`/`(3, 1000), `*`(x2)))), `*`(x1)), `*`(`+`(399, `-`(`*`(`/`(1, 250), `*`(x1))), `-`(`*`(`/`(1, 100), `*`(x2)))), `*`(x2)), `-`(400000), `-`(`*... (1)
 

dydx1 := diff(y, x1); 1 

`+`(`-`(`*`(`/`(1, 50), `*`(x1))), 144, `-`(`*`(`/`(7, 1000), `*`(x2)))) (2)
 

dydx2 := diff(y, x2); 1 

`+`(`-`(`*`(`/`(7, 1000), `*`(x1))), `-`(`*`(`/`(1, 50), `*`(x2))), 174) (3)
 

s := solve({dydx2, dydx1 = 0}, {x1, x2}); 1 

{x1 = `/`(554000, 117), x2 = `/`(824000, 117)} (4)
 

evalf(s) 

{x1 = 4735.042735, x2 = 7042.735043} (5)
 

eval(y, s) 

`/`(21592000, 39) (6)
 

evalf(%) 

553641.0256 (7)
 

avg[x1] := eval(`+`(339, `-`(`*`(`/`(1, 100), `*`(x1))), `-`(`*`(`+`(`*`(3, `*`(x2))), `/`(1, 1000)))), s) 

`/`(31651, 117) (8)
 

evalf(%) 

270.5213675 (9)
 

avg[x2] := eval(`+`(399, `-`(`*`(`+`(`*`(4, `*`(x1))), `/`(1, 1000))), `-`(`*`(`/`(1, 100), `*`(x2)))), s) 

`/`(36227, 117) (10)
 

evalf(%) 

309.6324786 (11)
 

cost := eval(`+`(400000, `*`(195, `*`(x1)), `*`(225, `*`(x2))), s) 

`/`(113410000, 39) (12)
 

evalf(%) 

2907948.718 (13)
 

revenue := eval(`+`(`*`(`+`(339, `-`(`*`(`/`(1, 100), `*`(x1))), `-`(`*`(`+`(`*`(3, `*`(x2))), `/`(1, 1000)))), `*`(x1)), `*`(`+`(399, `-`(`*`(`+`(`*`(4, `*`(x1))), `/`(1, 1000))), `-`(`*`(`/`(1, 100)... 

`/`(135002000, 39) (14)
 

profitmargin := eval(`+`(`/`(`*`(100, `*`(y)), `*`(revenue))), s) 

`/`(1079600, 67501) (15)
 

evalf(%) 

15.99383713 (16)