From: Sean Flynn on
Hi,

I am using ode45 to solve an initial value problem. I am trying to solve the ordinary differential equation diff_eq defined below, for p as a function of u. My tspan is from
-1.828427124746190 to 3.828427124746190. My initial condition is
p0 = -1.828427124746190 - value
value can take on any positive value. When I try value = 0.8 ==> initial condition is
-2.628427124746191. I get a solution curve up to a certain point, and then it returns NaN. I'm wondering exatly why is it returning NaN. Does that mean that there is no solution there? Thank you very much in advance for you help.

All the best,
Sean

function [dp] = diff_eq(u,p,params)
mean_x = params(1,1);
var_x = params(2,1);
var_z = params(6,1);
mean_u = params(7,1);
var_u = params(8,1);

b = var_z/(var_u);
eval_pt = p-b*(u-mean_u);

density = normpdf(eval_pt,mean_x,sqrt(var_x));
cum_density = normcdf(eval_pt,mean_x,sqrt(var_x));

dp = b* density*(u-p)/(density*(u-p)-cum_density);