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.

Answer by TADA
on 14 Apr 2019

This is a simple linear equation:

price = 10 + 4*floor(depth);

Antoni Ho
on 14 Apr 2019

it is not like that

the first one meter is $10, next $1.4, next $1.8m

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

yes, the area is constant

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
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.

Answer by 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.

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
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.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Image Analyst (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/456297-please-help-me-simple-question#comment_693939

## Antoni Ho (view profile)

## Direct link to this comment

https://de.mathworks.com/matlabcentral/answers/456297-please-help-me-simple-question#comment_693941

Sign in to comment.