Need help with user made Functions and Sub functions.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
GEEVARGHESE TITUS
el 17 de Mzo. de 2017
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 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!