Help with ODE45 Running Forever
4 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
Walter Roberson
2020-10-27
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 个评论
Walter Roberson
2020-10-27
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!