Need help setting up diff equation in matlab

  • MATLAB
  • Thread starter Pepsi24chevy
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses how to plot the direction field for the equation dy/dt = y^2-ty, using a large enough rectangle to show possible limiting behaviors. The unique constant solution is identified and it is evident from the differential equation. If a solution curve is below the constant solution, its limiting behavior as t increases must be negative infinity. For solutions above the constant solution, two possible limiting behaviors as t increases are described. There is also a solution curve that lies along the boundary of the two limiting behaviors, and its behavior as t increases is unclear. The individual is having trouble plotting the field and asks for help.
  • #1
Pepsi24chevy
65
0
The problem reads as followed: Plot the direction field fo rthe equation dy/dt = y^2-ty

again using a rectangle large enough to show the possible limiting behavors. Identify the unique constant solution. Why is this solution evident from the differential equation? If a solution curve is ever below the constant solution, what must its limiting behavor be as t increases? For solutions lying above the constant solution, describe two possible limiting behavors as t increases. there is a solution curv e that lies along the boundary of the two limiting behavors. What does it do as t increases.

ok, now i am having problems plotting the field. I get all the direction vectors pointing down no matter what domain i choose. Here is how i have been typing it in.
>> [T,Y] = meshgrid(-5:0.2:5, -5:0.2:5);
>> S = Y^2 - T*Y;
>> L = sqrt(1 + S.^2);
>> quiver(T, Y, 1./L, S./L, 0.5), axis tight
 
Physics news on Phys.org
  • #2
anyone? any help is appreciated
 
  • #3


To set up the differential equation in MATLAB, you can use the "ode45" function. This function solves a system of differential equations of the form dy/dt = f(t,y) using the fourth and fifth order Runge-Kutta method. In your case, the function f(t,y) would be y^2-ty.

To set up the equation, you can define a function handle for f(t,y) using the "@" symbol and then pass it as an argument to the "ode45" function. For example:

f = @(t,y) y^2 - t*y;
[T,Y] = ode45(f, [tspan], [y0]);

Here, "tspan" is the time interval over which you want to solve the equation and "y0" is the initial value of y at t=0.

To plot the direction field, you can use the "quiver" function. This function plots arrows representing the direction and magnitude of the vector field at each point in the meshgrid. To create the meshgrid, you can use the "meshgrid" function, as you have done in your code. However, in order to use the "quiver" function, you need to pass it the values of the vector field at each point, which can be calculated using the function handle "f". So, your code would look something like this:

[T,Y] = meshgrid(-5:0.2:5, -5:0.2:5);
S = Y.^2 - T.*Y;
L = sqrt(1 + S.^2);
quiver(T, Y, 1./L, S./L, 0.5), axis tight

Note that you need to use the element-wise operators "." and ".*" to perform calculations on the entire matrix.

To identify the unique constant solution, you need to find the values of y for which dy/dt = 0. In this case, it would be when y = 0 or y = t. These values are evident from the differential equation because when y = 0, dy/dt = 0 and when y = t, dy/dt = 0. This means that y = 0 and y = t are constant solutions.

If a solution curve is ever below the constant solution (y = 0 or y = t), its limiting behavior as t increases would be to approach the constant solution. This is because as t
 

1. How do I set up a differential equation in MATLAB?

To set up a differential equation in MATLAB, you will first need to define the variables and constants involved in the equation. Then, you can use the "diff" function to represent the derivatives in the equation. Finally, you can use the "ode45" function to solve the equation numerically.

2. What is the syntax for setting up a differential equation in MATLAB?

The syntax for setting up a differential equation in MATLAB is: dy/dx = f(x,y), where "dy/dx" represents the derivative of the dependent variable, "f(x,y)" represents the function that defines the equation, and "x" and "y" represent the independent variables.

3. Can I solve a system of differential equations in MATLAB?

Yes, MATLAB has built-in functions such as "ode45" and "ode23" that can be used to solve a system of differential equations. These functions use numerical methods to approximate the solutions.

4. How can I plot the solution to a differential equation in MATLAB?

To plot the solution to a differential equation in MATLAB, you can use the "odeplot" function. This function will plot the dependent variable against the independent variable, showing how the solution changes over time.

5. Is there a way to check the accuracy of the solution to a differential equation in MATLAB?

Yes, you can use the "ode45" function with the "reltol" and "abstol" options to specify the relative and absolute tolerances for the solution. This will help ensure that the solution is accurate within a given error margin.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
999
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
939
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
Back
Top