Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Jeffrey
Posts:
3
Registered:
10/15/13


Re: complex results using ODE45 solved!
Posted:
Oct 22, 2013 2:25 PM


"Jeffrey" wrote in message <l427u6$455$1@newscl01ah.mathworks.com>... > "Nasser M. Abbasi" wrote in message <l3k0lp$fad$2@speranza.aioe.org>... > > On 10/15/2013 12:53 PM, Jeffrey wrote: > > > I have the two m files given below. "a" and "T" are returned as complex with > > > > > > Why are values becoming complex? > > > > > > Please help. > > > > > > Jeff > > > _______________________________ > > > %this is in file alpha.m > > > function dadT = alpha(T,a) > > > b = 20 > > > l= 50.1 > > > k=exp(l) > > > ner = 36108.73 > > > n=1.269 > > > dadT = (k/b)*(exp(ner/T)) *((1a)^n > > > ________________________________________ > > > > > > > You have missing ")" above btw. Last line. > > > > But besides this, which I assume a cut/paste issue only, > > look at the expression itself. > > > > What happens for (1a)^n, and "a" happens to be > > larger than one? > > > > EDU>> (11.5)^(1.269) > > > > ans = > > > > 0.2754  0.3104i > > > Nasser, > > yes ")" was missing and thanks for the explanation. > > On inspection, all coefficients of "i" for "T" were zero. Coefficients of "i" for "a" only became nonzero near the end, as the real value "a" approaches 1. > > Physically "a" must be < or = to 1. > > The real part of "a" gives an accurate solution. > > I think that the "a's" that become >1 are the intermediate values of "a" are being computed to in order to evaluate the "a" at "T+h" using the RungeKutta formulation. > > Anyway to limit the value of these intermediate "a's" to a maximum value of 1?
I have solved the problem by changing 'RelTol' from default of 1e3 to 1e4, and by changing 'AbsTol' from default of 1e6 to 1e7
hence
tol= odeset('RelTol',1e4,'AbsTol',1e7) [T,a] = ode45(@post,Tspan,a0,tol);



