0

I was assigned a program where I have to create a MATLAB model for the equation and figure as follows-- https://i.stack.imgur.com/wV0ro.png. Unfortunately, I've been stuck for quite a while.

or dh/dt = (-r^2*sqrt(2*g*h))/(0.5r+htan(phi))^2

where

g=386.4 in/s^2
h = 2+(34/64) in
r = 1/10 in
angle=30.519612098961595 degrees

I calculated for dh/dt, which is -0.185963075319895 in/s and time to empty t=13.611573134321043 s, which I did by t=h/-c1_solution.

My x and y range are:

t1_span = [0 t] 
y1_span = [0 ; h] 

My function is like this so far:

function hvt1 = leak(r,h,angle, g)

c1_solution_1 = (-(r(y1_span))^2 * sqrt(2*g*h(y1_span))) ;
c1_solution_2 = (0.5*r(t1_span)+h(t1_span)*tand(angle))^2 ;
c1_solution = c1_solution_1(1)/c1_solution_2(1) ; 
hvt1 = c1_solution ;

So, this definitely needs work. I'm very inexperienced with this type of thing. I'm wondering how I can model how the container drains as a function of time. I'm guessing I'll have to use ode45. I know how to format ode45 in my program, but I'm having trouble with creating the functions.

Thanks in advance. :)

Haru
  • 1
  • 1
  • I would flag this as "Unclear what you're asking", but you're new.. Your post needs editing: write the differential equations you are trying to simulate, and your current implementation, that's it. We don't need to know about the rest. – Jonathan H Oct 12 '14 at 08:19

1 Answers1

1

There is nothing mysterious or unclear about the documentation of ode45. As I said in comment, it's unclear what you are asking, and you should rewrite the differential equation in your post instead of linking to an external image...

In this example, you can replace solver by any matlab solver. r,g,phi are the constants defined by your problem, h0 is your initial state and tspan is the timespan in which you are considering your solution. Some solvers allow you to specify a timestep, others choose it dynamically.

[t,h] = solver( @dh_dt, tspan, h0 );

function dh = dh_dt(t,h)
    dh = - r*r*sqrt(2*g*h);
    dh = dh / (.5*r + h*tan(phi))^2;
end
Jonathan H
  • 7,591
  • 5
  • 47
  • 80
  • Unfortunately, my professor himself was unclear with his instructions. All he said to do was model a leaking, funnel-shaped tank. I think I have to model this by plotting the water level in the funnel over time. – Haru Oct 12 '14 at 15:00
  • Also, I understand how to use ode45, but my problem is with the functions I'm creating. – Haru Oct 12 '14 at 15:06
  • Two things: i) _you_, not your professor, are asking an unclear question to people that you don't know and who are giving of their free time trying to figure out what _you_ meant. If you think you got unclear instructions, you shouldn't go and ask unclear questions to strangers, but turn to your professor for details instead; ii) the differential function destined to Matlab's solvers is given in my answer, so does that answer your question? – Jonathan H Oct 12 '14 at 15:12
  • It looks like I have to make a model that predicts the drain time of the funnel. I'm assuming that means I use my estimated time to empty and plot the resulting curve of the way it drains as time progresses. It'll probably look something like the figure at the bottom of this page: http://diego.assencio.com/?index=62f54ab6114d473b6933ad5bf5a5fc88#post_62f54ab6114d473b6933ad5bf5a5fc88_fig_2 – Haru Oct 12 '14 at 17:00
  • Yes, it should look like this I think. Specifically, you should use the numerical estimate of `h(t)` to find the time at which it becomes 0. – Jonathan H Oct 12 '14 at 21:40
  • If I do it like that, I get values like " -5.1236e+02 + 4.0756e+02i." Also, my graphs look like this: http://i.imgur.com/4J67UrJ.png?1 – Haru Oct 13 '14 at 01:25