필터 지우기
필터 지우기

How to define a function CalculatePyramidVolume with inputs baseLength, baseWidth, and pyramidHeight

조회 수: 18 (최근 30일)
Define a function CalculatePyramidVolume with inputs baseLength, baseWidth, and pyramidHeight. The function returns pyramidVolume, the volume of a pyramid with a rectangular base. Relevant geometry equations:
* Volume = base area * height * 1/3
* Base area = base length * base width
Starter code
% Define a function CalculatePyramidVolume
% Function inputs: baseLength, baseWidth, and pyramidHeight
% Function output: pyramidVolume
Assessments
Check if function definition exists
Check functions input and output arguments
Check if CalculatePyramidVolume(1, 1, 1) returns 0.3333
Check if CalculatePyramidVolume(5.8, 4.0, 6.0) returns 46.4000

답변 (4개)

SAA
SAA 2020년 7월 25일
This is the function part:
function [VP] = PyramidVolume(l,w,h)
VP=(1/3)*l*w*h
end
You need to call it in a script like this
l = input('Base lenght: ');
w = input('Base width: ');
h = input('height: ');
VP = PyramidVolume(l,w,h)
Check it yourself it should work, you can also just define l w and h instead of making them inputs
  댓글 수: 3
SAA
SAA 2020년 7월 26일
You should not get an error, what error are you getting can you post a screenshot?
I tried the code and it worked
Alanah Baldwin
Alanah Baldwin 2020년 12월 4일
how do you define h and l so that theyre not inputs, also how do u add that the surface area is limited to a specifit number, in my example, 12

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


Michael Haracopos
Michael Haracopos 2021년 7월 7일
function [VP] = PyramidVolume(l,w,h)
VP=(1/3)*l*w*h
end

Milen
Milen 2023년 1월 4일
function [VP] = PyramidVolume(l,w,h)
VP=(1/3)*l*w*h

Aishly
Aishly 2023년 10월 30일
function [VP] = PyramidVolume(l,w,h)
VP=(1/3)*l*w*h
end

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by