Operations Research formulation in MATLAB
Show older comments
Solve below Operation Research Program & submit MATLAB code also.

2 Comments
Steven Lord
on 16 Sep 2020
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Manthan Hawal
on 17 Sep 2020
Answers (2)
Steven Lord
on 17 Sep 2020
Looking at the code you posted as a comment I have a couple of observations and suggestions.
The Queen's MATLAB was only an April Fools joke. [It fooled people for longer than I expected it to, though!] The name-value pair to set the Color property of a line when calling plot is 'Color', 'r' (or 'Color', 'g' or 'Color', [1 0.75 0.5] etc.)
plot(1:10, 1:10, 'Color', 'r')
If you look at the documentation page for the plot function there are several pieces of information that may help you. There's a "Name-Value Pair Arguments" section that lists some of the common options like 'Color'. There's also a link in the See Also section at the end of the page to "Line Properties" which shows even more properties you can specify as name-value pair arguments when you call plot (or that you can specify after the line is created.)
At a quick glance, you also have a typo on the line where you define f. You have a comma where you should have a period.
One more note, the decimal separator in MATLAB is period not comma. There is a preference for setting the decimal separator when copying data from MATLAB to the system clipboard, but it has no effect on how data is stored or displayed inside MATLAB. Your meshgrid call confused me until I realized you meant 0,2 to be the double precision number closest to two-tenths. The comma between the 5 and 0 is filling one of its normal roles in MATLAB, separating input arguments being passed to a function.
% Create optimization variables
x = optimvar("x","LowerBound",0);
y = optimvar("y","LowerBound",0);
% Set initial starting point for the solver
initialPoint.x = zeros(size(x));
initialPoint.y = zeros(size(y));
% Create problem
Prueba1 = optimproblem;
% Define problem objective
Prueba1.Objective = (x-3)^2+(y-3)^2;
% Define problem constraints
Prueba1.Constraints = x+y <= 4;
% Display problem information
show(Prueba1);
% Solve problem
[solution,objectiveValue,reasonSolverStopped] = solve(Prueba1,initialPoint,...
"Solver","fmincon");
% Display results
solution
reasonSolverStopped
objectiveValue
% Clear variables
clearvars x y initialPoint reasonSolverStopped objectiveValue
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!