80.0k views
4 votes
Question: MATLAB Problem MUST use nargin and nargout - Write a function called compute that has two output arguments and three input arguments - The input argument(s) will be either the radius of a sphere or the three sides of a triangle - If the caller requests no output(s), the function will do nothing except return the message: "No outputs requested" - If the

MATLAB Problem

MUST use nargin and nargout

- Write a function called compute that has two output arguments and three input arguments

- The input argument(s) will be either the radius of a sphere or the three sides of a triangle

- If the caller requests no output(s), the function will do nothing except return the message: "No outputs requested"

- If the caller requests just one output and supplies just one input, the function will return the volume of the sphere: V=(4/3)*pi^3

- If the caller requests just one output and supplies three inputs, the function will return the perimeter of the triangle: C=s1+s2+s3

- Anything else, the function will return the message: "Error: Something went wrong"

User EFreak
by
7.6k points

1 Answer

7 votes

Final answer:

In this MATLAB problem, we need to write a function called compute that has two output arguments and three input arguments. The function should use nargin and nargout to determine the number of inputs and outputs requested by the caller.

Step-by-step explanation:

In this MATLAB problem, we need to write a function called compute that has two output arguments and three input arguments. The function should use nargin and nargout to determine the number of inputs and outputs requested by the caller.

If no output(s) are requested, the function should return the message: "No outputs requested".

If only one output is requested, the function should check if one input or three inputs are provided. If one input is provided, it should calculate the volume of the sphere using the formula: V=(4/3)*pi*r^3. If three inputs are provided, it should calculate the perimeter of the triangle using the formula: C=s1+s2+s3.

For any other combination of inputs and outputs, the function should return the message: "Error: Something went wrong".

User Gokhan Arik
by
7.0k points