There are two main bugs that we need to fix:
- define the correct function outputs.
- call the function with input and output arguments.
Lets have a look at them in detail.
1- Currently you define the function with exactly the same input and output arguments:
function [r, h] = cylind(r, h)
While this is perfectly valid and useful in some situations, in your case you want to return the values of the internal calculations, i.e. the variables v and sa, so these need to be defined as the output arguments, e.g. like this:
function [v, sa] = cylind(r, h)
2- You call the cylind function twice, but the first time with no input arguments (even though it requires two input arguments) and the secdon time with no output arguments. Calling a function with no output arguments is perfectly valid, but it just means that any outputs it calculates internally are simply discarded. If you want to use the outputs then you need to assign then to some variables, e.g.:
[Vout,SAout] = cylind(..)
Note that the names used internally are totally unrelated to the names used in the calling workspace!
So we can call the fixed function:
function [v,sa] = cylind(r,h)
v = pi*(r.^2).*h;
sa = (2*pi*(r.^2))+(2*pi*r.*h);
simply like this:
>> Rin = 2;
>> Hin = 3;
>> [Vout,SAout] = cylind(Rin,Hin)
Vout = 37.699
SAout = 62.832
̀>> fprintf("v is %g, sa is %g\n", Vout,SAout)
v is 37.6991, sa is 62.8319