MATLAB only please
I am trying to get my getdatafuntion to work. I am also trying to get all my x's, y's, and v's to popup in the command window so I can put in any value and it will find the value for me using
the equation I put in.
function project_9_sjl()
% PROJECT_9_SJL project_9_sjl() is the driver function for the
program.
%
% Name: Scott Lawrence
% Date: 3/27/2019
% Class: CMPSC 200
% Description: Determine the optimal location of a
warehouse
%
fprintf('\t\tAUTHOR: Scott Lawrence\n');
fprintf('\t\tDATE: 27 March 2019\n');
fprintf('\t\tDESCRIPTION: Determine the optimal location of a
warehouse\n');
[X1, X2, X3, X4, X5, X6, Y1, Y2, Y3, Y4, Y5, Y6] =
getLocations();
function x = getDataRange
x = input('Enter the location of X1');
if x > 100, x < 0;
fprintf(Inputvalue)
getDataRange
else
end
end
% Enter the locations of the
customers
function [X1, X2, X3, X4, X5, X6, Y1, Y2, Y3, Y4, Y5, Y6] =
getLocations()
X1 = getDataRange('Enter the location of X1:', 0, 100);
X2 = getDataRange('Enter the location of X2:', 0, 100);
X3 = getDataRange('Enter the location of X3:', 0, 100);
X4 = getDataRange('Enter the location of X4:', 0, 100);
X5 = getDataRange('Enter the location of X5:', 0, 100);
X6 = getDataRange('Enter the location of X6:', 0, 100);
Y1 = getDataRange('Enter the location of Y1:', 0, 75);
Y2 = getDataRange('Enter the location of Y2:', 0, 75);
Y3 = getDataRange('Enter the location of Y3:', 0, 75);
Y4 = getDataRange('Enter the location of Y4:', 0, 75);
Y5 = getDataRange('Enter the location of Y5:', 0, 75);
Y6 = getDataRange('Enter the location of Y6:', 0, 75);
end
[V1, V2, V3, V4, V5, V6] = getVolumes()
function v = getDataRange
v = input('Enter the location of V1');
if x >0, x<0;
fprintf(Inputvalue)
getDataRange
else
end
end
% Prompt the user for the customer volumes
function [V1, V2, V3, V4, V5, V6] = getVolumes()
% Get the six volumes
V1 = getDataRange('Enter the location of V1:', 0, 1e99);
V2 = getDataRange('Enter the location of V2:', 0, 1e99);
V3 = getDataRange('Enter the location of V3:', 0, 1e99);
V4 = getDataRange('Enter the location of V4:', 0, 1e99);
V5 = getDataRange('Enter the location of V5:', 0, 1e99);
V6 = getDataRange('Enter the location of V6:', 0, 1e99);
end
% Find the optimal location
% Print results from the optimization
function printResults(X1, X2, X3, X4, X5, X6, Y1, Y2, Y3, Y4, Y5,
Y6, V1, V2, V3, V4, V5, V6, xOpt, yOpt, minCost)
fprintf('\t\t X1%5.2 \n',X1)
fprintf('\t\t X2%5.2 \n',X2)
fprintf('\t\t X3%5.2 \n',X3)
fprintf('\t\t X4%5.2 \n',X4)
fprintf('\t\t X5%5.2 \n',X5)
fprintf('\t\t X6%5.2 \n',X6)
fprintf('\t\t Y1%5.2 \n',Y1)
fprintf('\t\t Y2%5.2 \n',Y2)
fprintf('\t\t Y3%5.2 \n',Y3)
fprintf('\t\t Y4%5.2 \n',Y4)
fprintf('\t\t Y5%5.2 \n',Y5)
fprintf('\t\t Y6%5.2 \n',Y6)
fprintf('\t\t V1%5.2 \n',V1)
fprintf('\t\t V2%5.2 \n',V2)
fprintf('\t\t V3%5.2 \n',V3)
fprintf('\t\t V4%5.2 \n',V4)
fprintf('\t\t V5%5.2 \n',V5)
fprintf('\t\t V6%5.2 \n',V6)
fprintf('\t\t xOpt%5.2 \n',xOpt)
fprintf('\t\t yOpt%5.2 \n',yOpt)
fprintf('\t\t minCost%5.2 \n',minCost)
end
end
function [optX, optY, optCost] = findOptimal(X1, X2, X3, X4, X5,
X6, Y1, Y2, Y3, Y4, Y5, Y6, V1, V2, V3, V4, V5, V6)
% FINDOPTIMAL findOptimal(xLoc, yLoc,
shipVolumes) is function that uses
% a brute force algorithm to find the optimal location
of a warehouse.
%
% The function returns three values; the optimal x and
y coordinates and
% the minimum cost
%
% Name: Scott Lawrence
% Date: 3/27/2019
% Class: CMPSC 200
%
%
% Set a minimum value for the cost -
this should be a big number (1e99)?
optCost = 1.0e99;
% Set the starting the optimal locations -
make it impossible (-1, -1)?
optX = -1;
optY = -1;
% Create two nested for loops that step
through all of the possible
% (x, y) pairs
for x = 0:100
for y = 0:75
% Calculate the n
distances and n costs
%
d1 = sqrt((X1 - x).^2 + (Y1 - y).^2);
c1 = sqrt*d1*V1;
d2 = sqrt((X2 - x)^2 + (Y2 - y)^2);
c2 = sqrt*d2*V2;
d3 = sqrt((X3 - x)^2 + (Y3 - y)^2);
c3 = sqrt*d3*V3;
d4 = sqrt((X4 - x)^2 + (Y4 - y)^2);
c4 = sqrt*d4*V4;
d5 = sqrt((X5 - x)^2 + (Y5 - y)^2);
c5 = sqrt*d5*V5;
d6 = sqrt((X6 - x)^2 + (Y6 - y)^2);
c6 = sqrt*d6*V6;
totalCost = c1+c2+c3+c4+c5+c6;
if totalCost < optCost
optCost = totalCost;
optX = x;
optY = y;
% Now check the cost
against the current minCost - this is an
% simple if. If the new
cost is less then change the min cost and
% set optX and optY to
the new locations (x, y). If it is not
% then you don't need
to do anything
end
end
end
end
The problem in input values was due to the incorrect definition of datarange() function. Please see the corrected version below:
function x = getDataRange(str,xbl,xul)
x = input(str); % display the message
if x > xul % check if input value exceed the upper limit
fprintf('\nOut of range! Resetting it to upper limit,
x=%d\n',xul);
x=xul;
elseif x<xbl % check if input value crosses the lower
limit
fprintf('\nOut of range! Resetting it to lower limit,
x=%d\n',xbl);
x=xbl;
end
end
=========== SAMPLE OUTPUT
MATLAB only please I am trying to get my getdatafuntion to work. I am also trying to get all my x...
How can I make these equations into 6 first order equations to input them in MATLAB as : function yp = ivpsys_fun_oscillator(t, y) % IVPSYS_FUN evaluates the right-hand-side of the ODE's. % Inputs are current time and current values of y. Outputs are values of y'. % Call format: yp = ivpsys_fun_oscillator(t, y) global m k l %% Define ODE for IVP % Reduce high order derivative to first order % y1 -> x1, y2 -> x2, y3 -> x3...