Help with ODE45 Running Forever
9 ビュー (過去 30 日間)
古いコメントを表示
Daniel Beeson
2020 年 10 月 27 日
コメント済み: Walter Roberson
2020 年 10 月 27 日
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!