Matlab: Problem with function inputs

  • Thread starter Thread starter jdawg
  • Start date Start date
  • Tags Tags
    Function Matlab
Click For Summary

Discussion Overview

The discussion revolves around a problem related to developing a MATLAB function for calculating the volume of liquid in a partially filled ellipsoid-shaped tank. Participants are attempting to create a plot of volume versus depth and are encountering issues with function inputs and definitions.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant presents the formula for the volume of the liquid and the initial lines of the MATLAB function, expressing uncertainty about the implementation.
  • Another participant notes that the variable h should only range from 0 to 2*a, questioning why it was initially set to run from 0 to 3*a.
  • A participant reports an error related to function definitions not being permitted in the context, indicating a potential issue with how the function is structured.
  • Another participant suggests that the function should be able to calculate the full volume of the ellipsoid given the dimensions, implying that further debugging is necessary if it cannot.
  • One participant encounters an error stating "Not enough input arguments," suggesting a mismatch between the function call and its definition.
  • A later reply proposes that there may be a misunderstanding regarding the number of arguments expected by the function, suggesting the possibility of using dummy variable names to troubleshoot the issue.

Areas of Agreement / Disagreement

Participants express varying levels of agreement on the nature of the errors encountered, with some focusing on the function definition and others on the input arguments. There is no consensus on the specific solution to the problem, and multiple viewpoints on the issues remain present.

Contextual Notes

Participants have not provided the complete function definition, which limits the ability to diagnose the issues fully. There is also uncertainty regarding how MATLAB handles numeric arguments and function definitions in this context.

jdawg
Messages
366
Reaction score
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: 684
  • watt.png
    watt.png
    4.8 KB · Views: 596
Physics news on Phys.org
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   Reactions: jdawg
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.
 
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   Reactions: jdawg
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);
 
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K