Need help with user made Functions and Sub functions.
3 次查看(过去 30 天)
显示 更早的评论
Create a function that finds the volume, surface area and perimeter of a rectangular prism of height h, width w and depth d.
It should use separate sub functions to calculate the volume, surface area and the perimeter. The main function should be called and three arguments should be passed as such: function_name(h,w,d).
I have this so far, but I need help. If anybody can help or point me in the right direction, it would be much appreciated. Thank you.
0 个评论
回答(1 个)
GEEVARGHESE TITUS
2017-3-17
The assignment operations were not right, and have rectified the code. The invoking format was also not correct, as you require three arguments and the one you provided was a single variable with four values.
function [v,sa,p] = Rectangle(w,h,d)
v = volume(w,h,d);
sa = surface_area(w, h, d);
p = perimeter(w, h, d);
function v = volume(w, h, d)
v = w*h*d;
function sa = surface_area(w, h, d)
sa = 2*(w*d+h*d+h*w);
function p = perimeter(w, h, d)
p = 2*d + 2*w;
%to run the function use [v,sa,p] = Rectangle(1,2,3)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!