How Do You Solve a Differential Equation in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter ngheo1128
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary

Discussion Overview

The discussion revolves around solving a specific differential equation using MATLAB. The equation presented is dh/dt = 0.079577 - 0.066169 * sqrt(h), with given initial and boundary conditions. The focus is on numerical methods and MATLAB's capabilities for solving ordinary differential equations (ODEs).

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant asks how to use MATLAB to solve the given differential equation.
  • Another participant suggests that the problem can be expressed in matrix form, indicating that MATLAB can handle such representations.
  • A different participant notes the presence of two boundary conditions but mentions having only one constant to work with, implying a potential challenge in the solution process.
  • Further, a participant explains that MATLAB has built-in ODE solvers and provides a specific format for writing the ODE, suggesting the use of a function handle for the equation.
  • The same participant details how to call the ode45 function in MATLAB, specifying the start and stop times along with the initial condition.

Areas of Agreement / Disagreement

Participants generally agree on the methods available in MATLAB for solving the differential equation, but there are differing views on the implications of the boundary conditions and the formulation of the problem.

Contextual Notes

There are unresolved aspects regarding the formulation of the problem in terms of boundary conditions and the potential limitations of the numerical methods discussed.

ngheo1128
Messages
1
Reaction score
0
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
 
Physics news on Phys.org
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.
 
You could write a method from scratch, you have two boundary conditions but only 1 constant to play with.
 
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.")
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 23 ·
Replies
23
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K