Matlab: Problem with function inputs

In summary, the function myellipsoid expects three arguments, a, b, and plot_title. If you don't pass those arguments, the function will not work.
  • #1
jdawg
367
2

Homework Statement


The volume V of a liquid in a partially filled ellipsoid shaped tank is given by
V = (pi/3)*(3*a-h)*(((b^2)*(h^2))/(a^2))
Develop an M-file to create a plot of volume versus depth. Here are the first few lines:
function myellipsoid(a,b,plot_title)
% Volume of horizontal ellipsoid
% Inputs:
% a - vertical semiaxis
% b - horizontal semiaxis
% plot_title - string holding plot title Test your program with:
>> myellipsoid(2,5,'Volume versus depth for ellipsoid')

I'm having trouble with this function, I'm not really sure what I'm doing wrong.

Homework Equations

The Attempt at a Solution

 

Attachments

  • grph.png
    grph.png
    39.1 KB · Views: 612
  • watt.png
    watt.png
    4.8 KB · Views: 524
Physics news on Phys.org
  • #2
jdawg said:

Homework Statement


The volume V of a liquid in a partially filled ellipsoid shaped tank is given by
V = (pi/3)*(3*a-h)*(((b^2)*(h^2))/(a^2))
Develop an M-file to create a plot of volume versus depth. Here are the first few lines:
function myellipsoid(a,b,plot_title)
% Volume of horizontal ellipsoid
% Inputs:
% a - vertical semiaxis
% b - horizontal semiaxis
% plot_title - string holding plot title Test your program with:
>> myellipsoid(2,5,'Volume versus depth for ellipsoid')

I'm having trouble with this function, I'm not really sure what I'm doing wrong.

Homework Equations

The Attempt at a Solution

From the figures attached, it looks like h can run only between 0 and 2*a. IDK why you have h running between 0 and 3*a.

In any event, when the tank is full, you should obtain a finite, non-zero value for the volume.
 
  • Like
Likes jdawg
  • #3
Hmmm... I just retyped it as h = 0:(2*a); and got this error:

function myellipsoid(a,b,plot_title)

Error: Function definitions are not permitted in this context.
 
  • #4
jdawg said:
Hmmm... I just retyped it as h = 0:(2*a); and got this error:

function myellipsoid(a,b,plot_title)

Error: Function definitions are not permitted in this context.
Ya got something wrong somewhere in the function myellipsoid.

In any event, you should be able to calculate by hand the full volume of the ellipsoid given the dimensions of the axes. If your function can't do that, then further debugging is required.
 
  • Like
Likes jdawg
  • #5
oops, I tried rerunning it and it gave me the same message as earlier;

>> myellipsoid(2,5,'Volume versus depth for ellipsoid')
Not enough input arguments.

Error in myellipsoid (line 12)
h = 0:(2*a);
 
  • #6
jdawg said:
oops, I tried rerunning it and it gave me the same message as earlier;

>> myellipsoid(2,5,'Volume versus depth for ellipsoid')
Not enough input arguments.

Error in myellipsoid (line 12)
h = 0:(2*a);
You've apparently got some disagreement between the call to myellipsoid and its definition. Since you have not provided the definition, I can't really help further.

The function myellipsoid apparently is expecting more than 3 arguments to be passed to it, or the ones you are passing are not being recognized properly.

I don't know if Matlab let's you pass numeric arguments by value. You could make up a couple of dummy variable names and assign values of a and b to those variables and see if the error goes away.
 

1. What is Matlab and how is it used in scientific research?

Matlab is a high-level programming language and interactive environment designed for numerical computation, data analysis, and visualization. It is commonly used in scientific research for tasks such as data modeling, simulation, and analysis.

2. What is a function input in Matlab?

A function input in Matlab is a variable or value that is passed into a function when it is called. These inputs are used by the function to perform a specific task and can vary depending on the requirements of the function.

3. How do I troubleshoot problems with function inputs in Matlab?

To troubleshoot problems with function inputs in Matlab, you can check the input arguments to make sure they are of the correct data type and within the expected range. You can also use the debugging tools in Matlab to step through the function and identify any errors or unexpected behavior.

4. Can a function in Matlab have multiple inputs?

Yes, a function in Matlab can have multiple inputs. These inputs are separated by commas and can be of different data types. It is important to make sure the inputs are in the correct order when calling the function.

5. How can I handle errors with function inputs in Matlab?

To handle errors with function inputs in Matlab, you can use the try-catch statement to catch any errors and provide a specific response or action. You can also use the nargin and nargout functions to check the number of input and output arguments and make sure they match the function requirements.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
735
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
899
  • Engineering and Comp Sci Homework Help
Replies
2
Views
742
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
Back
Top