To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
fhm793
Icrontic Convert
fhm793
19 Posts

Function that computes derivative - pleaseee help!

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!!
Y.F.N.C.G.
Just mindin' my own business
Y.F.N.C.G.
6 Posts
This is why I didn't go to college
__________________ "Your Friendly Neighborhood Computer Guy"
Aka: Matt
Follow me on my journey as I start my own part-time computer consulting business on my blog www.YFNCG.com
shwaip
elaborate bot
shwaip
5,731 Posts
you need to start by figuring out the differential equation that applies to the situation you gave, then you can translate it into matlab.
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
fhm793
Icrontic Convert
fhm793
19 Posts
The differential equation would be F = -0.1*W correct? But I don't get where the height comes in? Thanks!
shwaip
elaborate bot
shwaip
5,731 Posts
you need to relate h' (the rate of change of the height of the water) to h (the current height of the water).
fhm793
Icrontic Convert
fhm793
19 Posts
oh so like ... hprime = 10 - 0.1*W ?
shwaip
elaborate bot
shwaip
5,731 Posts
close...it should be hprime = -0.1*h

so, now that you know the relation between h' and h, you can write the function:

Code:
function hprime=can1(t,h)
     %use the relation above...

and then use ode45 as given
fhm793
Icrontic Convert
fhm793
19 Posts
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?
shwaip
elaborate bot
shwaip
5,731 Posts
yes.
Code:
function hprime = can1(t,h)
F=-0.1;
hprime = F*h;
fhm793
Icrontic Convert
fhm793
19 Posts
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)
shwaip
elaborate bot
shwaip
5,731 Posts
i don't have matlab on this computer right now.

can you post the error that it gave you?
fhm793
Icrontic Convert
fhm793
19 Posts
>> 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, ...
shwaip
elaborate bot
shwaip
5,731 Posts
is the can1 function in your path?

test it out by calling it:

can1(1,9)

it should return -0.9
shwaip
elaborate bot
shwaip
5,731 Posts
also, if you don't mind letting me know, what did you search for (on google?) to get to this website?
fhm793
Icrontic Convert
fhm793
19 Posts
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!
shwaip
elaborate bot
shwaip
5,731 Posts
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:
Code:
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
fhm793
Icrontic Convert
fhm793
19 Posts
No problem thank YOU for all the help you've been amazing
fhm793
Icrontic Convert
fhm793
19 Posts
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?
shwaip
elaborate bot
shwaip
5,731 Posts
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.
fhm793
Icrontic Convert
fhm793
19 Posts
hmm so would it be 1/2 instead or 1/h or something like that?
shwaip
elaborate bot
shwaip
5,731 Posts
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.
fhm793
Icrontic Convert
fhm793
19 Posts
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.
shwaip
elaborate bot
shwaip
5,731 Posts
the flow out the bottom is the same, correct.

how high is the water above the top hole?
fhm793
Icrontic Convert
fhm793
19 Posts
5 cm when it's full
shwaip
elaborate bot
shwaip
5,731 Posts
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?
fhm793
Icrontic Convert
fhm793
19 Posts
um it would still be multiplied by -0.1 right? so -0.1*5?
shwaip
elaborate bot
shwaip
5,731 Posts
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
fhm793
Icrontic Convert
fhm793
19 Posts
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
shwaip
elaborate bot
shwaip
5,731 Posts
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?
fhm793
Icrontic Convert
fhm793
19 Posts
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
shwaip
elaborate bot
shwaip
5,731 Posts
looks good.
fhm793
Icrontic Convert
fhm793
19 Posts
yayyy thank you so much again you have no idea how long that wouldve taken me by myself haha
edcentric
Must keep folding
edcentric
2,480 Posts
CODE???? what code. This is calculus. You can calculate a mathematical approximation, but until you write out the derivatives you can't start.
__________________ A couple of folding boxes;

DFI LP Nf4 U-D, A64X2, 2GB ram, is folding again
MSI P965 Pt, C2D E6300, 2GB ram, old reliable

2.5 million points and counting
fhm793
Icrontic Convert
fhm793
19 Posts
what??
primesuspect
The Icrontic Guy
primesuspect
27,803 Posts
ITT Shwaip teaches math
__________________ "I offer my genius to the world, all I ask is you pick up my expenses"
fhm793
Icrontic Convert
fhm793
19 Posts
haha you guys are confusing.

i think there is something wrong with the last part though because when i graph it it levels off at 2.5 and it should go down to 0 right?
shwaip
elaborate bot
shwaip
5,731 Posts
you have a typo in your code.
shwaip
elaborate bot
shwaip
5,731 Posts
CODE???? what code. This is calculus. You can calculate a mathematical approximation, but until you write out the derivatives you can't start.
What edcentric is saying is that you are having difficulty in two different areas. The matlab code to do this is fairly trivial - you'll get the hang of it quickly. However, you seem to be having trouble recognizing how to do the problem even outside of matlab. This is probably the simplest ODE that you'll find, and if you're having trouble with it, you need to read the book a little more or pay more attention in class. I mean, what are you going to do when you have a cone dripping into a cube, and the height of the water in the cone is decreasing by x cm/s and the question is how fast is the water in the cube rising.
fhm793
Icrontic Convert
fhm793
19 Posts
This is just a basic level course. This is the hardest assignment we will have to do.

If anyone is still looking at this, do you know how you would set up a more general function based off the other one that would accept a list of hole positions? I tried to set it up like this ...

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

but realized that can't be right bc that only accounts for 2 holes when there could be any number of holes....
Similar Threads
Thread Thread Starter Forum Replies Last Post
Function call tree software j General Software 3 17 Aug 2008 3:04am
MatLab problem - inline function zero finder PGolasze Matlab Help 4 10 May 2007 12:38am
PHP: Function call inside replace function Lincoln Web & Digital Media 7 7 Mar 2007 12:19am
Are you sure my dv8000t is Not a dv8000t? ~*~ Miska ~*~ General Hardware 19 25 Nov 2006 2:30am
need a good C++ sorting function - please help! jazzmuse Web & Digital Media 1 19 Feb 2006 3:14pm

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 11:25pm (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.