Help with ODE45 Running Forever
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Daniel Beeson
il 27 Ott 2020
Commentato: Walter Roberson
il 27 Ott 2020
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 Commenti
Risposta accettata
Walter Roberson
il 27 Ott 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 Commenti
Walter Roberson
il 27 Ott 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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!