Using ODE45 on Matlab to Integrate A Problem

In summary, the conversation discusses the topic of step size in a specific problem. The person is trying to change the step size in line 3, but encounters an error message. They are unsure if changing line 20 would affect the step size. The code also includes a function and a call to ode45. The conversation ends with a question about how ode45 determines the step size and where to find more information about it.
  • #1
ver_mathstats
260
21
Homework Statement
The homework statement is given below in a picture.
Relevant Equations
ODE 45 Matlab
Screen Shot 2022-12-05 at 12.53.10 PM.png

I got the answer for this question but I was wondering about stepsize when it comes to a problem like this? Is there a way to change the step size? Would my step size change in line 20, or would it change in line 3? I tried changing line 3 to be t=0:100:17.1 but then I get a error message, so would I just be changing line 20? x = linspace (0,17.1,10000); so 10 000 would be a fixed step size? I don't know how to proceed from this so any help would be appreciated.

Matlab:
mu = 0.012277471;
mu_hat = 1 - mu;
t = [0, 17.1];
u1_0 = 0.994;
u1_prime_0 = 0;
u2_0 = 0;
u2_prime_0 = -2.001585106379082522420537862224;
y_0 = [u1_0, u1_prime_0, u2_0, u2_prime_0]';
% y’ = f(y);
% y = (u1, u1’, u2, u2’)T;
Func = @(t, y)[
y(2);
y(1) + 2*y(4) - mu_hat*(y(1)+mu)/(((y(1)+mu)^2+y(3)^2)^(3/2))...
- mu*(y(1)- mu_hat)/(((y(1)-mu_hat)^2+y(3)^2)^(3/2));
y(4);
y(3) - 2*y(2) - mu_hat*y(3)/(((y(1)+mu)^2+y(3)^2)^(3/2)) - ...
mu*y(3)/(((y(1)-mu_hat)^2+y(3)^2)^(3/2))];

solution = ode45(Func, t, y_0,[10^-2,0]);
x = linspace (0,17.1,10000);
y1 = deval(solution,x,1);
y2 = deval(solution,x,3);
plot (y1,y2);
print -depsc ’odeorbit.eps’
 
Physics news on Phys.org
  • #2
Given that line 20 comes after the call to ode45, do you think it could affect the step size?

How do you think ode45 works out what step size to use? Do you think it uses a fixed step size? Where do you think you could find out these things?
 

1. What is ODE45 and how does it work?

ODE45 is a built-in function in Matlab that uses the Runge-Kutta method to numerically solve ordinary differential equations (ODEs). It works by breaking down the ODE into smaller time intervals and using a combination of previous and current values to approximate the solution.

2. How do I use ODE45 to integrate a problem in Matlab?

To use ODE45, you first need to define the ODE you want to solve and the initial conditions. Then, you can call the function with the appropriate inputs, including the ODE, initial conditions, and the time interval you want to integrate over. ODE45 will return the solution as an array of values at each time step.

3. What are the advantages of using ODE45 compared to other integration methods?

ODE45 is a versatile and efficient integration method that can handle a wide range of ODEs. It also automatically adjusts the step size to ensure accuracy and stability. Additionally, ODE45 is a built-in function in Matlab, making it easily accessible and user-friendly.

4. Can ODE45 handle stiff systems of ODEs?

Yes, ODE45 is specifically designed to handle stiff systems of ODEs. It uses a combination of the fourth and fifth order Runge-Kutta methods, making it suitable for both non-stiff and stiff systems.

5. Are there any limitations or potential issues when using ODE45?

One limitation of ODE45 is that it may not be as efficient for very large systems of ODEs. It also requires the user to have a good understanding of the ODE they are trying to solve in order to choose appropriate initial conditions and time intervals. Additionally, ODE45 may have difficulty handling discontinuities or singularities in the ODE.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
823
  • Engineering and Comp Sci Homework Help
Replies
1
Views
938
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top