Function that computes derivative - pleaseee help!

edited December 2008 in Science & Tech
You have water in a 10cm tall cylindrical can with a hole in it at the bottom. The flow from a hole depends on the water pressure, which is proportional to the height of the water above that hole: when water is W cm above a hole, then the flow from that hole will decrease the water height at a rate of 0.1*W cm/sec.

Write the function hprime = can1(t, h) that models the flow, then call ode45(@can1, [0 60], 10); to plot the water height over 60 secs starting full (10cm) . At roughly what time is there 1cm left?

I don't even know where to start ... ANY help would be soo appreciated!! :)
«1

Comments

  • Y-F-N-C-G-Y-F-N-C-G- Silver Spring, MD
    edited December 2008
    This is why I didn't go to college :confused:
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    you need to start by figuring out the differential equation that applies to the situation you gave, then you can translate it into matlab.
  • edited December 2008
    The differential equation would be F = -0.1*W correct? But I don't get where the height comes in? Thanks!
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    you need to relate h' (the rate of change of the height of the water) to h (the current height of the water).
  • edited December 2008
    oh so like ... hprime = 10 - 0.1*W ?
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    close...it should be hprime = -0.1*h

    so, now that you know the relation between h' and h, you can write the function:
    function hprime=can1(t,h)
         %use the relation above...
    


    and then use ode45 as given
  • edited December 2008
    ok so our teacher said we need to include F = -0.1 before our code so it would be ...

    function hprime = can1(t,h)

    F = -0.1;
    hprime = -0.1*h;

    ... but then where does the F come in? I don't think this is right but would it need to be followed by something like W=F*hprime?
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    yes.
    function hprime = can1(t,h)
    F=-0.1;
    hprime = F*h;
    
  • edited December 2008
    Is that it though? Does W not need to be in it? I ran with ode45 like given and it gave me an error :(

    (Thanks soo much for the help again)
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    i don't have matlab on this computer right now.

    can you post the error that it gave you?
  • edited December 2008
    >> ode45(@can1, [0 60], 10);
    ??? Error using ==> feval
    Undefined function or method 'can1' for input arguments of type 'double'.

    Error in ==> odearguments at 111
    f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

    Error in ==> ode45 at 173
    [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    is the can1 function in your path?

    test it out by calling it:

    can1(1,9)

    it should return -0.9
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    also, if you don't mind letting me know, what did you search for (on google?) to get to this website?
  • edited December 2008
    ohh i see what you mean. i think i got it :)

    there's also a second part that says modify your function to model it with another hole 5 cm above the hole at the bottom ... any suggestions about how i would go about that one?

    oh and i google searched "matlab help forum" i think!
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    it will be similar, but you'll need to use an 'if' statement to see if the height of the water is above or below the hole that is 5cm high.

    so:
    function hprime = can2(t,h)
     F=-0.1;
      if( h > 0.5)
        %it goes out through two holes
      else
        %it goes out through only one hole
      end
    

    thanks for letting me know how you found us
  • edited December 2008
    No problem thank YOU for all the help you've been amazing :)
  • edited December 2008
    Oh and also ... for the second part, would you just multiply the equation by 2 when there are 2 holes like this:

    F = -0.1; %flow rate from 1 cm of water
    if h > 0.5
    hprime = 2*F*h; %it goes out through 2 holes
    else
    hprime = F*h; %it goes out through one hole
    end

    end

    or am I thinking about it wrong?
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    remember that the rate going out depends on how high the water is above the hole. so it will go out of the top hole slower than the bottom hole.
  • edited December 2008
    hmm so would it be 1/2 instead or 1/h or something like that?
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    nope.

    you know that the rate of flow out depends on the height of the water above the hole.

    let's pretend that the water is 10 cm high (completely full). What's the rate of flow out of the hole that's 5cm high, and what's the rate of flow out of the bottom hole? Assume that they don't affect each other.
  • edited December 2008
    hmm well the flow out of the bottom hole would be the same as before right? then i know the flow out of the top hole would be slower than out of the bottom hole but i guess i dont understand how you would know exactly how fast that would be.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    the flow out the bottom is the same, correct.

    how high is the water above the top hole?
  • edited December 2008
    5 cm when it's full
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    if we pretend that the top half of the can is its own can, how fast would the water come out of a hole if the water was 5cm above the hole?
  • edited December 2008
    um it would still be multiplied by -0.1 right? so -0.1*5?
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    right.

    so you need to find how high the water is above the 5cm hole, determine the flow rate out of it, and add it to the rate out the bottom hole, and this will be the total h' when the water is > than 5cm deep
  • edited December 2008
    so would it be something like this? ...

    function hprime = can2(t,h)
    F = -0.1; %flow rate from 1 cm of water
    if h > 0.5
    hprime = 1/2*F*h + F*h; %it goes out through 2 holes
    else
    hprime = F*h; %it goes out through 1 hole
    end

    ... sorry, i understand the concept im just so bad at putting stuff into matlab terms
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    test it for another value...

    let's say the water is at 8cm.

    then the water is 3cm above the top hole, and 8cm above the lower. this means:
    hprime = 3*-0.1 + 8*-0.1 = -1.1

    is this the same thing your formula gives?
  • edited December 2008
    Ohh ok I see what you mean so ...

    function hprime = can2(t,h)
    F = -0.1; %flow rate from 1 cm of water
    if h > 0.5
    hprime = F*(h-5) + F*h; %it goes out through 2 holes
    else
    hprime = F*h; %it goes out through 1 hole
    end
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2008
    looks good.
Sign In or Register to comment.