How to do you use matlab to solve this?

  • MATLAB
  • Thread starter ngheo1128
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses using MATLAB to solve a problem involving an ODE with two boundary conditions. The problem can be written in the form of an operator and constants as matrices, with h as a vector. MATLAB has built-in ODE solvers and the instructions can be found online. The conversation also provides an example of defining a function handle and using the "ode45" function to solve the problem.
  • #1
ngheo1128
1
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
  • #2
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
You could write a method from scratch, you have two boundary conditions but only 1 constant to play with.
 
  • #4
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.")
 
  • #5


MATLAB is a powerful tool for solving mathematical equations and models. To use MATLAB to solve the equation provided, you will need to first define the variables and their initial values. In this case, ho = 1.75 and hf = 1.46 and to = 0. Next, you will need to create a function that represents the equation dh/dt = 0.079577-0.066169*squareroot(h). This can be done using the "function" keyword in MATLAB. Once the function is defined, you can use the "ode45" function to numerically solve the equation and plot the results. This function takes in the defined function, the initial values, and the range of time for which you want to solve the equation. The output will be a graph showing the change in h over time. Additionally, you can use the "fzero" function to find the specific value of h at which the equation is equal to 0. This can be useful for finding the steady state solution of the equation. Overall, MATLAB provides a versatile and efficient way to solve mathematical equations and models.
 

1. How do I input data into MATLAB?

To input data into MATLAB, you can either type it directly into the Command Window or import it from an external file. To type data into the Command Window, simply use the following syntax: variable_name = [data1, data2, data3] To import data from a file, you can use the importdata() function.

2. How do I write a script in MATLAB?

To write a script in MATLAB, you can use the built-in editor by clicking on the "New Script" button in the Home tab. Alternatively, you can create a new file with the .m extension and open it in any text editor. Remember to save your script before running it.

3. How do I perform mathematical operations in MATLAB?

To perform mathematical operations in MATLAB, you can use the standard arithmetic operators: +, -, *, /. You can also use built-in functions such as sin(), cos(), sqrt() to perform more complex operations. Remember to use parentheses to indicate the order of operations.

4. How do I plot data in MATLAB?

To plot data in MATLAB, you can use the plot() function. First, input your data into MATLAB using the methods mentioned in question 1. Then, use the plot() function with the appropriate arguments, such as x and y values, to create a plot. You can also customize the plot using additional arguments, such as color and line style.

5. How do I save my work in MATLAB?

To save your work in MATLAB, you can use the save() function. This will save the current workspace variables to a file with the .mat extension. You can also use the diary() function to save all the commands and outputs from your current session to a text file for future reference.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
23
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top