Why am I getting imaginary values with ode45 ??
32 views (last 30 days)
%This is my program R=1;
options = odeset('RelTol',10^-12,'AbsTol',10^-8);
I am simulating a simple circuit, which is governed by two differential equations
I,Q are my variables. I am getting the simulated output but the problem is I am getting imaginary values
As the only possible cause could be 'log' term in the second differential equation,
from that 1+I/Is>0 ==> I>-Is 'to get real values'
so I used odeset to put obsolute tolerence limit as 10^-8.
But I am still getting imaginary values for 'y'!! Why??
Please let me know what I am doing wrong !!
Shoaibur Rahman on 29 Dec 2014
Your I has both negative and positive values, which are in the range of 10^(-7), but Is is in 10^(-12). So, I/Is gives high negatives for some negative values of I. In that case, log is getting a negative input, and thus resulting imaginary parts.
I is the current, and negative indicates the direction. So, when using inside log, you can use both I and Is in same direction, hence same signs. This is also equivalent to making I as abs(I) inside the log.
Jan on 30 Dec 2014
If you create a function instead of using an anonymous function, you can add a short test for imaginary values:
function dy = fun(t,y)
dy = [(-R*y(1)/L-(y(2)/(C*L)-(Vdo/L)*log(1+(y(1)/Is)))); ...