Using ODE45 on Matlab to Integrate A Problem

Click For Summary
SUMMARY

The discussion focuses on the use of the ODE45 function in MATLAB for integrating differential equations, specifically regarding the management of step sizes. Users inquired about modifying the step size, with a particular emphasis on lines 3 and 20 of the provided code. The consensus is that the step size is determined by the input vector in line 20, where 'x = linspace(0, 17.1, 10000)' creates a fixed grid of 10,000 points. The ODE45 function employs an adaptive step size algorithm, which adjusts the step size dynamically based on the solution's behavior.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with numerical methods for solving ordinary differential equations
  • Knowledge of the ODE45 function and its parameters
  • Basic concepts of step size control in numerical integration
NEXT STEPS
  • Research the adaptive step size algorithm used by ODE45 in MATLAB
  • Learn how to implement custom step sizes in MATLAB ODE solvers
  • Explore the differences between fixed and adaptive step size methods
  • Investigate the impact of step size on the accuracy of numerical solutions
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly engineers and scientists working with numerical simulations, as well as students learning about numerical methods for solving differential equations.

ver_mathstats
Messages
258
Reaction score
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
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?
 

Similar threads

Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K