Need help with user made Functions and Sub functions.
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
GEEVARGHESE TITUS
il 17 Mar 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 Commenti
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!