My plot is not showing the lines. Can someone please point me in the right direction? Thanks,

1 回表示 (過去 30 日間)
Tyler Gary
Tyler Gary 2019 年 7 月 29 日
回答済み: Jalaj Gambhir 2019 年 8 月 1 日
%clear
%clc
disp('Exotic Llama Enclosure Perimeter Fence Optimization')
disp('_____________________________________________________')
disp('Note - do NOT enter enclosure to take measurements!')
fprintf('\n\n')
disp('The Cost Equation in terms of Area & Radius is given below,')
disp('As solved from the Area and Perimeter Fence Costs equations:')
% Variables
% part 1 - all symbolic versions of variables below
% part 2: R - radius of curve (m), A - Area of enclosure (m^2), Cost_C -
% curved wall cost ($/m), Cost_S - Straight Wall Cost ($/m), FenceCost -
% cost of enclosure fence ($), Rmin - minimum curve radius (m), Rbest -
% radius that minimizes cost (m), Costbest - lowest cost at that Rbest($)
syms Area Cost Radius Length Cost_Curved Cost_Straight
Eq1 = (Area == 2*Radius*Length + pi*Radius^2/2);
Eq1b = solve(Eq1,Length);
Eq2 = (Cost == Cost_Straight*(2*Radius+2*Length)+Cost_Curved*(2*pi*Radius/2));
Eq2b = subs(Eq2, Length, Eq1b)
fprintf('\n')
Cost_S = input('Enter in a cost ($/m) for straight walls : ');
Cost_C = input('Enter in a cost ($/m) for curved wall : ');
Rmin = input('Enter in a minumum enclosure curve Radius (m) : ');
for A = 1000:1000:5000
for R = Rmin:1:50
FenceCost = Cost_S*(2*R + (A - (pi.*R^2)/2)/R) + pi*Cost_C*R;
hold all
plot(R,FenceCost)
xlabel('Radius (meter)')
ylabel('Perimeter Cost ($)')
ytickformat('usd')
title('Perimeter Costs vs Radius at various Floor Areas')
end
end
fprintf('\n\n')
A = input('Enter in a specific Area to determine the Radius to minimize cost (m^2) : ');
myfunction1 = @(R) Cost_S* (2*R + (A-(pi.*R^2)/2)/R)+pi*Cost_C*R;
[Rbest,Costbest] = fminbnd(myfunction1, Rmin, 50);
fprintf('The Radius to minimize cost is: %6.2f (m) at a cost of $%6.2f', Rbest, Costbest)
  1 件のコメント
Adam
Adam 2019 年 7 月 29 日
編集済み: Adam 2019 年 7 月 29 日
You should collect up all your results in an array in your for loop and do a single plot at the end. It will be faster and your plot will then have all the data on it, joined by lines. You are just plotting one point at a time and the default behaviour for plot is to use no marker, so plotting a single point with no marker shows nothing. If you want markers then you can look at
doc plot
to see how they are specified, though you should still do it all in one plot because the more individual graphics objects you have the more memory is used and the slower your plot will respond.

サインインしてコメントする。

回答 (1 件)

Jalaj Gambhir
Jalaj Gambhir 2019 年 8 月 1 日
Hi,
As pointed out correctly in the comments, the plot won't show anything if you plot a single point without a marker. It is because by default the function connects two points and creates a line. Try:
plot(R,FenceCost,'-o');

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by