Please Help Me Simple Question

4 views (last 30 days)
Antoni Ho
Antoni Ho on 14 Apr 2019
Edited: TADA on 14 Apr 2019
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 Comments
Image Analyst
Image Analyst on 14 Apr 2019
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?
Antoni Ho
Antoni Ho on 14 Apr 2019
Edited: Antoni Ho on 14 Apr 2019
the first one is $10 and next one $14 meter next one is $18,
always increase $4 per meter (to infinity actually)
the area of cut is 1 unit (constant) (m2)
it is like this
if the depth is 4.5m
total price = area x height x unit price
total price = 1 x 1 x 10 + 1 x 1 x 14 + 1 x 1 x18 + 1 x 1 x 22 + 1 x 0.5 x 26

Sign in to comment.

Answers (2)

TADA
TADA on 14 Apr 2019
This is a simple linear equation:
price = 10 + 4*floor(depth);
  3 Comments
TADA
TADA on 14 Apr 2019
Edited: TADA on 14 Apr 2019
Something like this should do it:
s = [ones(1,floor(depth)), mod(depth, 1)]; % cut portion of cubic meter depth
x = 1:numel(s);
ppcm = cumsum(10+x*4); % price per cubic meter
price = sum(ppcm.*s);
TADA
TADA on 14 Apr 2019
Edited: TADA on 14 Apr 2019
I made a mistake, cumsum is not needed:
depth = 4.5;
s = [ones(1,floor(depth)), mod(depth, 1)]; % cut portion of cubic meter depth
x = 0:(numel(s)-1);
price = sum(s.*(10+x*4))
price =
77

Sign in to comment.


Star Strider
Star Strider on 14 Apr 2019
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 Comments
Antoni Ho
Antoni Ho on 14 Apr 2019
i am sorry, but i don't understand that.
but, i think it also wrong (sorry to say that)
Star Strider
Star Strider on 14 Apr 2019
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')

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!