# MATLAB How to do you use matlab to solve this?

1. Mar 24, 2013

### ngheo1128

How to do you use matlab to solve this?
dh/dt = 0.079577-0.066169*squareroot(h)
where ho = 1.75 and hf = 1.46 and to=0

2. Mar 24, 2013

### Simon Bridge

Welcome to PF;
There are a number of numerical methods.

If we write D as the operator for d/dt, then your problem has form Dh=b-ah,
You know you can write operators and constants as matrices and h as a vector.... do that and you have an equation that matlab can handle.

3. Mar 28, 2013

### hunt_mat

You could write a method from scratch, you have two boundary conditions but only 1 constant to play with.

4. Mar 28, 2013

### NegativeDept

MATLAB has several built-in ODE solvers. The instructions are here.

I think you have to write ODEs in the form
$\frac{d\mathbf{h}}{dt} = \mathbf{g}(t,\mathbf{h})$
where $\mathbf{h}$ is the thing you're trying to find and $t$ is the independent variable. In your case, $\mathbf{h}$ and $\mathbf{g}$ are one-dimensional, and your ODE is already in the form we want.

Define a function handle for $\mathbf{g}$ like this:

generator = @(t,h) 0.079577-0.066169*sqrt(h)

You don't have to name it "generator," but I always do. (It's a group-theory thing.)

Now call ode45 and give it a start time, stop time, and initial condition:

[times,solution] = ode45(generator,[0,1.46],1.75)

That will start at $t=0$, stop at $t=1.46$, and use the initial condition $h(0) = 1.75$. It produces two columns named times and solution. times is a list of sample times at which $h(t)$ was calculated, and solution is a list of values of $h(t)$ at those times. (You also don't have to call them "times" and "solution.")