Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.35 KB | None | 0 0
  1. clc;
  2. clear all;
  3.  
  4. A1 = [4 6 15; 2 2 0; 5 3 4; 7 3 12];
  5. b1 = [250 60 100 220];
  6. f = [2 1.5 3];
  7.  
  8. [x, fval] = linprog(f, -A1, -b1, [], [], 0, []);
  9. x = (ceil(x));
  10. cena = f * x;
  11. cena = sum(cena);
  12. bialko = sum(A1(1, :) * x);
  13. tluszcz = sum(A1(2, :) * x);
  14. witaminy = sum(A1(3, :) * x);
  15. weglowodany = sum(A1(4, :) * x);
  16.  
  17.  
  18. str1 = ['Student powinien zjeść ', num2str(x(1)), ' kanapek, ', num2str(x(2)), ' pierogow i ', num2str(x(3)), ' słodyczy'];
  19. str_zaw = ['Student otrzyma ', num2str(bialko), ' bialka ',  num2str(tluszcz), ' tłuszczu ',  num2str(witaminy), ' witamin ',  num2str(weglowodany), ' węglowodanów'];
  20. str2 = ['Optymalna cena to ', num2str(cena), ' zł'];
  21.  
  22.  
  23.  
  24. A2 = [5 25; 0.5 0; 100 250; 10 10];
  25. b2 = [500, 15, 7500, 400];
  26.  
  27. f2 = [100 200];
  28. [x2, fval2] = linprog(-f2, A2, b2, [], [], 0, []);
  29. cena2 = f2 * x2;
  30. cena2 = sum(cena2);
  31. drewno = sum(A2(1, :) * x2);
  32. skora = sum(A2(2, :) * x2);
  33. klej = sum(A2(3, :) * x2);
  34. praca = sum(A2(4, :) * x2);
  35.  
  36. str3 = ['Powinniśmy wyprodukować ', num2str(x2(1)), ' krzeseł i , ', num2str(x2(2)), ' stołów'];
  37. str_mat = ['Produkcja wymaga ', num2str(drewno), ' drewna ',  num2str(skora), ' skóry ',  num2str(klej), ' kleju ',  num2str(praca), ' nakładu gozin pracy'];
  38. str4 = ['Optymalna cena to ', num2str(cena2), ' zł'];
  39.  
  40. disp(str1)
  41. disp(str2)
  42. disp(str_zaw)
  43. disp(str3)
  44. disp(str4)
  45. disp(str_mat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement