Please Help Me Simple Question
4 ビュー (過去 30 日間)
古いコメントを表示
Hello, i am newbie
I need a simple program that can calculate cut (digging) price,
because the difficulty of cut is increased per m depth, the price can't be equal.
For example:
for the first 1m depth of cut
the price for cut is $10/m^3
for 1m-2m depth of cut
the price for cut is $14/m^3
for 2m-3m depth of cut
the price for cut is $18/m^3
and so on (constant addition).
But, the value of the depth is random and can go really high, let's say 30 m, so using "if" is not edible,
Can anyone can help me to calculate this with a couple lines of codes only?
Thank you very much for your help.
2 件のコメント
Image Analyst
2019 年 4 月 14 日
If the depth is 1.5 m, is the price $14 for the whole depth, or $10 for the first one meter, and $14 for the next half meter? It makes a difference.
What is the price after 3 m? Does it stay at $18, OR does it increase by $4 for every meter of depth?
The price is per cubic meter, so to know the total price we need not only the depth, but also the area of the cut, and an assumption that the cut has perfectly vertical sides. So, what is the area of the cut?
回答 (2 件)
Star Strider
2019 年 4 月 14 日
Try this:
digprice = @(depth) 6 + ceil(fix((depth+1)))*4; % Digging Price As A Function Of Depth
dep = linspace(0, 30, 150); % Depth Vector
figure
plot(dep, digprice(dep))
grid
xlabel('Depth (m)')
ylabel('Digging Price ($)')
Experiment to get the result you want.
2 件のコメント
Star Strider
2019 年 4 月 14 日
I am not certain what you want.
Run my code, and view the plot to see what it does.
A sample of the output:
Depth Price
0.0 $ 10
0.5 $ 10
1.0 $ 14
1.5 $ 14
2.0 $ 18
2.5 $ 18
3.1 $ 22
3.6 $ 22
4.1 $ 26
4.6 $ 26
5.1 $ 30
5.6 $ 30
6.1 $ 34
The code that produced it:
Result = [dep(:) digprice(dep(:))];
fprintf(' Depth Price\n')
fprintf(' %4.1f $%3d\n', Result')
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!