ich habe das Problem, dass mein Programm mit der Funktion linprog meine Nebenbedinungen nicht akzeptiert?
Kurz zum Programm: es geht um eine Lineare Programmierung, die herausfinden soll, wie man drei zutaten so mischt, dass die Kosten minimal sind.
Code:
%
% Finds the minimum of a problem specified by % min f'*x such that A*x <= b, % Aeq*x = beq % lb <= x <= ub
%% Variables:
% Input: % f Linear objective function vector f % A Matrix for linear equality constraints % b Vector for linear equality constraints % x1 Limestone (Kalk) % x2 Corn (Weizen) % x3 Soybean meal (Sojabohnen) % Output: % fopt returns the value of the objective function fun at the solution x: fopt = f'*x.
Habe aber den Fehler jetzt gefunden. Ich habe nicht bemerkt, dass ich nur die Ungleichungen und nicht Gleichungen in die A Matrix schreiben darf. Für die Gleichungen (also mit = ) muss ich die Aeq Matrix verwenden.
Hier nochmals der Code mit dem es funktioniert.
Code:
% Linear Programming
%
% Finds the minimum of a problem specified by % min f'*x such that A*x <= b, % Aeq*x = beq % lb <= x <= ub
%% Variables:
% Input: % f Linear objective function vector f % A Matrix for linear equality constraints % b Vector for linear equality constraints % x1 Limestone (Kalk) % x2 Corn (Weizen) % x3 Soybean meal (Sojabohnen) % Output: % fopt returns the value of the objective function fun at the solution x: fopt = f'*x.
% First, enter the coefficients % BE CAREFULL: This is a function for searching the minimum. Therefore you % have to add a minus in the f - vector
f = [10; 30.5; 90];
A = [-0.38-0.001-0.002 0.380.0010.002 -0-0.09-0.5 00.020.08];
Aeq = [111];
beq = [1];
b = [-0.008; 0.012; -0.22; 0.05;];
lb = zeros(3,1)
ub = ones(3,1)
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.