Differential equation for matlab

In summary, the conversation discusses solving a differential equation using the runge-kutta method in MATLAB. The problem is to find the expression for f(t,y) given y(t) = e^(-t)*sin(t^2) with t0=0 and T=3.14159. The conversation also mentions trying a simpler equation to test the MATLAB code and provides a link to a simulation that may be helpful. The conversation concludes with a clarification on the given equation and a suggestion for f(t,y).
  • #1
cameuth
17
0
THE PROBLEM :

y(t) = e^(-t)*sin(t^2);
with t0 = 0 and T = 3.14159. Find y_0, and use it to deduce the corresponding expression
for f(t, y) (Your f should have both a t and a y in it. Simplify it to find the y!).

This is for a MATLAB project. I've solved this differential equation (which we get from the derivative of the problem above) , but apparently there's a way to solve it where we get y on the right hand side of the equation (and still have t's). This is the only way the code will work in matlab.

MY ATTEMPT: basically I took the derivative of y=e^(-t)*sin(t^2) to get

y'=-e^(-t)[sin(t^2)+(2t)cos(t^2)]

You then inegrate to get the original formula plus a constant

y=e^(-t)*sin(t^2)+C

Now if we apply the inital condition y(0)=0, we get the original equation. Again.

y=e^(-t)*sin(t^2)

This is not correct. What am I missing?

PS, if you want to see my code and think that will help I have that as well. Just ask. Thanks
 
Last edited:
Physics news on Phys.org
  • #2
are you doing something with FFT (aka Fourier transforms) on the equation?

Thats what people often use MATLAB for given a complicated signal and use FFT to determine the component frequencies.
 
Last edited:
  • #3
No, I'm trying to approximate this differential equation using the runge-kutta method, then plot the error. But, I can't really do any of that without the proper differential equation. Which is where I'm stuck.
 
  • #4
Okay so given a differential equation, you want to use MATLAB to numerically integrate your equation via runge-kutta and to then compare it to an exact solution.

Have you tried a simpler equation such as integrating a sin function to get a cos function to test your MATLAB code?

To be fair, I'm not a heavy MATLAB person. I've done some numerical integration using open source physics java code where we converted the differential equation into first order differentials and I figure that's how it may need to be done here.

I did find this predator prey simulation that compares two versions of runge-kutta in plot form that may help.

http://www.mathworks.com/products/m...products/demos/shipping/matlab/lotkademo.html

http://math.arizona.edu/~emcevoy/odes.pdf
 
Last edited:
  • #5
When you wrote:

[itex] y(t) = e^{-t}sin(t^2) [/itex], did you find this, or was this given to you? I'm confused. Precisely what does the problem give you?
 
  • #6
So, I'm still confused about what f(t,y) is supposed to be, but I got

[itex] \dot{y} = e^{-t}(-sin(t^2)+2tcos(t^2)) = -y+2te^{-t}cos(t^2) = f(t,y)[/itex]is this useful at all?
 

1. What is a differential equation and how is it used in Matlab?

A differential equation is a mathematical equation that describes the relationship between a function and its derivatives. In Matlab, differential equations are used to model and solve a wide range of problems in areas such as physics, engineering, and economics.

2. How do I define a differential equation in Matlab?

In Matlab, differential equations can be defined using the ode45 function, which stands for "ordinary differential equation 4th/5th order." This function takes in the differential equation, initial conditions, and a time interval as inputs and returns a solution to the equation.

3. Can Matlab solve any type of differential equation?

Matlab is capable of solving a variety of differential equations, including both ordinary and partial differential equations. However, depending on the complexity of the equation, it may require additional tools or methods to find a solution.

4. How do I plot the solution to a differential equation in Matlab?

After using the ode45 function to solve the differential equation, the solution can be plotted using the plot function. The independent variable should be on the x-axis and the dependent variable should be on the y-axis.

5. Are there any resources available for learning how to use differential equations in Matlab?

Yes, there are many resources available for learning how to use differential equations in Matlab, including online tutorials, textbooks, and courses. The MathWorks website also has a comprehensive documentation on the ode45 function and other related functions for solving differential equations in Matlab.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
135
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
997
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
Back
Top