Please Help Me Simple Question

조회 수: 5 (최근 30일)
Antoni Ho
Antoni Ho 2019년 4월 14일
편집: TADA 2019년 4월 14일
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
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?
Antoni Ho
Antoni Ho 2019년 4월 14일
편집: Antoni Ho 2019년 4월 14일
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

댓글을 달려면 로그인하십시오.

답변 (2개)

TADA
TADA 2019년 4월 14일
This is a simple linear equation:
price = 10 + 4*floor(depth);
  댓글 수: 3
TADA
TADA 2019년 4월 14일
편집: TADA 2019년 4월 14일
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 2019년 4월 14일
편집: TADA 2019년 4월 14일
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

댓글을 달려면 로그인하십시오.


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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by