2

I wrote my script for a class but the next step is to convert that script into a function. What do I type in?

This is my script:

% Find max volume

b = 2.75; %ft for diameter
h = 3.00; %ft for height 

v = (b*h)/3; %ft^3
% use volume to find mass
p = 62.3;

m = p*v;

1 Answer 1

2

The following syntax is used to create a function in MATLAB:

function [y1,...,yN] = myfun(x1,...,xM)

In the example below, the maximumVolume() method takes 3 parameters (b, h, p) and returns the value of the m variable.

result = maximumVolume(2.75, 3.0, 62.3);

function m = maximumVolume(b, h, p)
    v = (b * h)/3;
    m = p * v;
end

References
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.