Create a 3d plot, by changing a variable while using linear programming and system optimization.

4 views (last 30 days)
IN MATLAB R2022b - academic use.
I need help creating a 3d plot.
I am using the function 'linprog' to find the least cost conservation plan for the Colorado River in Arizona, Nevada, and California. I have costs and conservation volums, as well as prepetual conservation (purchassing land from farmers, installing low-flow showers/toilets) and one year conservation (fallowing farm land/crop rotation).
As my time considered for conservation needs increases [line 2 variable 'yo'] the usefulness of the more expensive, propetual conservation, options become more ecconomical. My figure [line 45-51] plots the different conservation options and how much of each was sellected each year.
I want to turn this 2d plot into a 3d plot so the x and y become x and z (vertical height maintained) and the y axis shown the different amount of time considered
Then I want to do this again (seperatly) but with the change in Annual Budget [line 5] which also impacts the decision space.
I expect the function 'linprog' needs to be solved multiple times for each change in a variable. I dont know the best (or any) way to keep the data and display it in a 3d space.
Code Below:
For these varibles ['j' conservation and 'F' costs some are not never selected, that is fine]
clear,clc
yo=20; %Number of Years considered
gro=.01; %Growth of demand
int=.05; %Interest rate of money
ABudg=3E9; %Annual Budget
%Legend for conservation options
LegOpt={'Purchased', 'Toilets', 'Catchment', 'Fallowed','Rotated'};
j=[-4.5,-.03, -.01,-4,-2]; %Conservation Savings (ac-ft/y)
c=[1,1,1,0,0]; %Which Options are propetual Conservation 1/0 y/n
F=[20000, 150, 100, 950,300]; %Conservation Cost ($)
ub=repmat([inf,10000,10000,inf,inf],1,yo);
%annual limits to purchase options
c=j.*c;
opt=length(j);
o=zeros(1,opt); %Counting and manipulation
for i=1:yo %Creating the 'A' Matrix
A(i,:)=[repmat(c,1,i-1),j,repmat(o,1,yo-i)];
end
f=zeros(yo,opt);
b=zeros(1,yo);
b(1)=1200000;
f(1,:)=F;
for i=2:yo %Compound Interest for Costs, Demand
f(i,:)=f(i-1,:)*(1+int);
b(i)=b(i-1)*(1+gro);
end
f=reshape(f',1,[])';
value=repelem(eye(yo),1,opt).*f';
aBudg=repmat(ABudg,1,yo);
lb=zeros(1,yo*opt);
[x of]=linprog(f,[A;value],[-b,aBudg],[],[],lb,ub);
volum=reshape(x,opt,yo); %How much of each option selected each year
ACost=value*x; %Annual Cost of options selected
sum(ACost) %Total Outlay
figure(2)
for i=1:opt
plot(1:yo,volum(i,:)); hold on
end
legend(LegOpt)
xlim([1,yo])

Answers (1)

Varun
Varun on 18 Apr 2023
Hello William!
As per my understanding, you want to introduce new variables to your linear programming mechanism and expand its dimensionality to 3D. While I am not sure about exactly what results are expected from this analysis, I believe this sample plot (attached below) is similar to what you may be looking for:
Regarding the 3D plot, MATLAB has ready-to-go functions which you can use such as ‘plot3’. You may find the documentation for the same at https://www.mathworks.com/help/matlab/ref/plot3.html .
As for introducing the new variables, I think you’ll have to solve the system of equations for all existing variables repeatedly, each time the budget changes. You can store this new data generated as a cell array. Cell arrays are equipped to contain entire matrices in a single cell, so you don’t have to worry about merging/ appending your existing matrices with new data from the next iteration. You may find the relevant documentation here: https://www.mathworks.com/help/matlab/ref/cell.html.
Hope this helps!

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!