Help with ODE45 Running Forever

조회 수: 9 (최근 30일)
Daniel Beeson
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);

채택된 답변

Walter Roberson
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
Daniel Beeson
Daniel Beeson 2020년 10월 27일
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 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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by