Help with ODE45 Running Forever

9 views (last 30 days)
Hi everyone,
I'm having a rough time with a line of my ode45 code, it's working for my y and z directions, but not my x-direction, which is weird because my X and Z are practically the same. Did I make any ovbious mistakes? Any ideas why the ode45 can't do my x-direction term?
close all, clear all, clc
vx0 = .1;
vy0 = .1;
vz0 = .1;
E = 10^4;
B = .1;
theta = atan(vx0/(vz0 - E/B));
q = -1.6*10^-19;
m = 9.11*10^-31;
wc = q*B/m;
vth = sqrt(vx0^2 + (vz0 - E/B)^2);
t_span = [0:pi/10:10*pi];
[t1,x] = ode45(@(t,x) (vth*sin((wc*t) + theta)), t_span, vx0);
[t2,y] = ode45(@(t,y) vy0, t_span, vy0);
[t3,z] = ode45(@(t,z) (vth*cos((wc*t) + theta)) + E/B, t_span, vz0);

Accepted Answer

Walter Roberson
Walter Roberson on 27 Oct 2020
For t1 you have a sin wave with frequency 17563117453.348 being integrated over 0 to 10*pi . This is a quite high frequency and ode45 needs to take very small steps to try to integrate it properly while maintaining relative accuracy.
For t3, you have a cos wave with frequency 17563117453.348, plus a fair-sized constant. The steps are often noise compared to the constant and ode45 does not have to take many steps to maintain relative accuracy.
  2 Comments
Daniel Beeson
Daniel Beeson on 27 Oct 2020
Is there any real fix to this then since those are the parameters of the problem I am required to plot?
Walter Roberson
Walter Roberson on 27 Oct 2020
Analytically, the function associated with t1 is about 5.6937e-6*cos(1.7563e+10*T + 1.0e-6) - 5.6937e-6 so it has a frequency of roughly 2E10. You cannot meaningfully plot that for more than a very very short period (a small number of nanoseconds)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!