1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab: Problem with function inputs

  1. Jun 12, 2016 #1
    1. The problem statement, all variables and given/known data
    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.

    2. Relevant equations


    3. The attempt at a solution
     

    Attached Files:

  2. jcsd
  3. Jun 12, 2016 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
     
  4. Jun 12, 2016 #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.
     
  5. Jun 12, 2016 #4

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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.
     
  6. Jun 12, 2016 #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);
     
  7. Jun 12, 2016 #6

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    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 lets 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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Matlab: Problem with function inputs
Loading...