5
$\begingroup$

I am processing SNe Ia data and using FindMinimum to try and extract two values: t1 and a0. The FindMinimum value works only if I supply values that are close to the answer. If I provide no starting values or arbitrary starting values (e.g. t1=1, a0=1), then the function doesn't converge. If I give it values close to the answer (e.g. t1=1*^18, a0=1*^-14), then I get an answer. Here's the code:

c = 2.99792*^5;
megaParsec = 3.08567758*^19;
alpha = 0.147;
beta = 3.13;
mag = -19.34;

chiSquared[t1_, a0_] := 
 Sum[residual[i, t1, a0]^2/error[i]^2, {i, 1, Length[data]}]

error[i_] := (distance = observedDistance[i]; 
  distanceModuli = 
   Log10[distance/megaParsec]*5 + 25; (data[[i, 6]]/distanceModuli)*
   distance)

luminousDistance[z_, t1_, a0_] := -((a0*t1^2*z + 
      2*c*((-t1)*(1 + z) + Sqrt[t1^2*(1 + z)]))/(2 + z))

residual[i_, t1_, a0_] := (z = data[[i, 2]]; 
  observedDistance[i] - luminousDistance[z, t1, a0])

observedDistance[i_] := (magnitude = 
   data[[i, 3]] + alpha*(data[[i, 4]] - 1) - beta*data[[i, 5]] - mag; 
  10^((magnitude - 25)/5)*megaParsec)

And here is the data:

data = {{"sn2004s", 0.01, 14.183, 0.973, 0.035, 0.213}, {"sn1999ac", 
    0.01, 14.13, 0.987, 0.056, 0.177}, {"sn1997do", 0.011, 14.317, 
    0.983, 0.056, 0.204}, {"sn2006bh", 0.011, 14.347, 0.814, -0.045, 
    0.168}, {"sn2002dp", 0.011, 14.597, 0.973, 0.113, 
    0.203}, {"sn2005al", 0.012, 14.843, 0.871, -0.073, 
    0.179}, {"sn2001ep", 0.013, 14.904, 0.903, 0.088, 
    0.189}, {"sn1997e", 0.014, 15.118, 0.819, 0.036, 
    0.2}, {"sn2001fe", 0.015, 14.685, 1.077, -0.002, 
    0.194}, {"sn2005bo", 0.014, 15.646, 0.867, 0.236, 
    0.186}, {"sn2002ha", 0.014, 14.703, 0.867, -0.056, 
    0.202}, {"sn2006n", 0.015, 15.09, 0.787, -0.023, 
    0.196}, {"sn1999dq", 0.014, 14.409, 1.103, 0.075, 
    0.183}, {"sn1999aa", 0.016, 14.728, 1.12, -0.052, 
    0.167}, {"sn1992al", 0.014, 14.499, 0.959, -0.087, 
    0.187}, {"sn2001bt", 0.014, 15.317, 0.899, 0.18, 
    0.181}, {"sn2005el", 0.015, 14.842, 0.838, -0.08, 
    0.19}, {"sn1999dk", 0.014, 14.881, 0.991, 0.086, 
    0.198}, {"sn2001v", 0.016, 14.596, 1.111, 0.025, 
    0.176}, {"sn2005kc", 0.015, 15.502, 0.933, 0.176, 
    0.192}, {"sn1994s", 0.015, 14.801, 1.031, -0.037, 
    0.208}, {"sn2001cz", 0.016, 15.083, 1.007, 0.071, 
    0.19}, {"sn2001cn", 0.015, 15.306, 0.933, 0.145, 
    0.191}, {"sn2001bf", 0.015, 14.719, 1.1, 0, 0.215}, {"sn2004eo", 
    0.015, 15.104, 0.88, 0.058, 0.18}, {"sn2004ey", 0.016, 14.676, 
    1.001, -0.107, 0.201}, {"sn2001en", 0.015, 15.095, 0.877, 0.038, 
    0.309}, {"sn2006td", 0.016, 15.735, 0.841, 0.123, 
    0.208}, {"sn1996bv", 0.017, 15.353, 1.064, 0.162, 
    0.234}, {"sn2006ax", 0.017, 14.984, 1.001, -0.091, 
    0.174}, {"sn2001da", 0.017, 15.464, 0.778, 0.078, 
    0.412}, {"sn2000dk", 0.018, 15.361, 0.768, -0.001, 
    0.184}, {"sn1998v", 0.017, 15.105, 0.983, 0.004, 
    0.243}, {"sn1998ef", 0.018, 14.832, 0.892, -0.068, 
    0.203}, {"sn2007ci", 0.019, 15.909, 0.729, 0.066, 
    0.188}, {"sn1992bo", 0.019, 15.79, 0.771, -0.03, 
    0.182}, {"sn2002kf", 0.02, 15.664, 0.862, -0.032, 
    0.222}, {"sn2005ki", 0.02, 15.536, 0.844, -0.067, 
    0.171}, {"sn2003w", 0.021, 15.89, 0.993, 0.134, 
    0.178}, {"sn1992bc", 0.021, 15.145, 1.081, -0.086, 
    0.173}, {"sn2006ej", 0.02, 15.779, 0.853, 0.026, 
    0.204}, {"sn2007bc", 0.022, 15.912, 0.852, 0.011, 
    0.191}, {"sn2002jy", 0.022, 15.758, 1.109, -0.008, 
    0.2}, {"sn2008bf", 0.022, 15.739, 1.034, 0.013, 
    0.178}, {"sn2006bq", 0.022, 16.191, 0.848, 0.079, 
    0.191}, {"sn2006et", 0.022, 16.003, 1.11, 0.166, 
    0.215}, {"sn2006cp", 0.023, 16.015, 1.052, 0.099, 
    0.188}, {"sn2006ar", 0.023, 16.486, 0.903, 0.128, 
    0.198}, {"sn1995ak", 0.022, 15.982, 0.85, 0.011, 
    0.278}, {"sn2006mp", 0.023, 16.009, 1.092, 0.036, 
    0.188}, {"sn2005bg", 0.025, 15.833, 1.044, -0.003, 
    0.185}, {"sn2006ac", 0.023, 16.193, 0.895, 0.08, 
    0.174}, {"sn1994m", 0.025, 16.278, 0.83, 0.043, 
    0.208}, {"sn2000cn", 0.024, 16.554, 0.755, 0.115, 
    0.189}, {"sn2007f", 0.024, 15.914, 1.059, -0.02, 
    0.187}, {"sn2000ca", 0.023, 15.606, 1.062, -0.073, 
    0.194}, {"sn2007qe", 0.024, 16.074, 1.059, 0.067, 
    0.171}, {"sn2006sr", 0.024, 16.157, 0.852, 0.011, 
    0.195}, {"sn1993h", 0.024, 16.766, 0.726, 0.179, 
    0.193}, {"sn2002bf", 0.025, 16.358, 0.936, 0.169, 
    0.232}, {"sn2002he", 0.025, 16.271, 0.82, -0.012, 
    0.214}, {"sn1992ag", 0.025, 16.355, 0.95, 0.18, 
    0.231}, {"sn2005ms", 0.027, 16.18, 1.045, -0.01, 
    0.181}, {"sn1992p", 0.028, 16.097, 1.079, -0.063, 
    0.271}, {"sn2007cq", 0.025, 15.85, 0.938, 0.003, 
    0.198}, {"sn2005na", 0.027, 15.934, 0.95, -0.078, 
    0.183}, {"sn2004gs", 0.027, 17.146, 0.768, 0.167, 
    0.172}, {"sn1999gp", 0.027, 16.044, 1.182, 0.029, 
    0.186}, {"sn2007co", 0.027, 16.491, 0.964, 0.098, 
    0.186}, {"sn1998ab", 0.028, 16.089, 0.982, 0.066, 
    0.194}, {"sn2002de", 0.028, 16.699, 1.062, 0.139, 
    0.223}, {"sn2003u", 0.029, 16.521, 0.791, 0.003, 
    0.227}, {"sn2005eq", 0.029, 16.322, 1.159, 0.026, 
    0.184}, {"sn2001ba", 0.03, 16.244, 1.008, -0.095, 
    0.196}, {"sn1996c", 0.031, 16.654, 1.073, 0.087, 
    0.208}, {"sn2006qo", 0.03, 16.865, 1.048, 0.192, 
    0.18}, {"sn2003ch", 0.03, 16.725, 0.842, -0.001, 0.2}, {"sn1990o",
     0.03, 16.267, 1.047, -0.018, 0.229}, {"sn1997dg", 0.031, 16.84, 
    0.941, -0.024, 0.215}, {"sn2006az", 0.031, 16.517, 0.858, -0.064, 
    0.168}, {"sn2004as", 0.033, 17.011, 1.049, 0.077, 
    0.2}, {"sn2007bd", 0.032, 16.614, 0.844, -0.021, 
    0.18}, {"sn1999cc", 0.032, 16.783, 0.812, 0.015, 
    0.174}, {"sn2006s", 0.033, 16.898, 1.112, 0.074, 
    0.172}, {"sn2006bt", 0.031, 16.971, 1.011, 0.13, 
    0.181}, {"sn2004l", 0.033, 17.385, 0.925, 0.192, 
    0.234}, {"sn2005iq", 0.034, 16.76, 0.878, -0.085, 
    0.17}, {"sn2003iv", 0.035, 17.03, 0.741, -0.04, 
    0.25}, {"sn2006gr", 0.034, 17.009, 1.103, 0.1, 
    0.184}, {"sn2005eu", 0.035, 16.521, 1.101, -0.027, 
    0.213}, {"sn2002hd", 0.036, 16.867, 0.858, 0.081, 
    0.377}, {"sn1992bg", 0.035, 16.749, 0.956, -0.037, 
    0.281}, {"sn1996bl", 0.035, 16.677, 0.979, 0.006, 
    0.206}, {"sn2000cf", 0.037, 17.05, 0.916, -0.023, 
    0.193}, {"sn2006mo", 0.037, 17.486, 0.759, 0.065, 
    0.207}, {"sn2001eh", 0.037, 16.667, 1.185, -0.004, 
    0.198}, {"sn1999aw", 0.039, 16.791, 1.234, -0.032, 
    0.182}, {"sn2002hu", 0.038, 16.69, 1.045, -0.058, 
    0.183}, {"sn2003fa", 0.039, 16.763, 1.152, -0.01, 
    0.182}, {"sn2001az", 0.04, 16.986, 1.108, -0.049, 
    0.259}, {"sn2005lz", 0.041, 17.674, 0.844, 0.093, 
    0.201}, {"sn1992bl", 0.042, 17.345, 0.815, -0.035, 
    0.24}, {"sn1992bh", 0.042, 17.649, 0.99, 0.065, 
    0.215}, {"sn2004gu", 0.047, 17.439, 1.141, 0.101, 
    0.178}, {"sn2005hc", 0.045, 17.302, 1.078, -0.006, 
    0.18}, {"sn1993ag", 0.049, 17.865, 0.884, 0.085, 
    0.241}, {"sn1995ac", 0.049, 17.091, 1.085, -0.012, 
    0.184}, {"sn1990af", 0.05, 17.796, 0.741, -0.006, 
    0.198}, {"sn1993o", 0.053, 17.656, 0.906, -0.073, 
    0.196}, {"sn1999ao", 0.055, 17.906, 0.95, -0.017, 
    0.212}, {"sn1998dx", 0.054, 17.546, 0.844, -0.088, 
    0.24}, {"sn2006ob", 0.059, 18.302, 0.741, 0.022, 
    0.187}, {"sn2006oa", 0.058, 17.955, 1.131, 0.023, 
    0.196}, {"SDSS3901", 0.063, 18.015, 1.117, 0.051, 
    0.18}, {"sn1992bs", 0.063, 18.317, 0.966, -0.018, 
    0.237}, {"sn2006an", 0.065, 18.195, 1.061, 0.016, 
    0.222}, {"sn2007ae", 0.063, 17.832, 1.198, 0.002, 
    0.234}, {"SDSS10028", 0.065, 18.373, 0.891, 0.054, 
    0.2}, {"SDSS6057", 0.067, 18.641, 0.944, 0.129, 
    0.206}, {"sn2006al", 0.069, 18.485, 0.809, -0.063, 
    0.248}, {"sn1993b", 0.07, 18.497, 0.914, 0.057, 
    0.273}, {"sn2006on", 0.068, 18.494, 1.038, 0.104, 
    0.31}, {"sn1992ae", 0.075, 18.448, 0.944, -0.027, 
    0.266}, {"sn2005ir", 0.075, 18.4, 1.043, 0.014, 
    0.17}, {"sn1999bp", 0.078, 18.422, 1.065, -0.037, 
    0.198}, {"sn1992bp", 0.079, 18.335, 0.877, -0.075, 
    0.212}, {"sn2005ag", 0.08, 18.44, 1.029, -0.014, 
    0.179}, {"SDSS1241", 0.087, 19.103, 0.929, 0.072, 
    0.189}, {"SDSS3592", 0.087, 18.751, 0.975, -0.04, 
    0.178}, {"SDSS6773", 0.09, 18.663, 0.979, -0.011, 
    0.207}, {"SDSS2102", 0.095, 18.634, 1.133, -0.094, 
    0.217}, {"SDSS10434", 0.104, 19.185, 1.01, -0.053, 
    0.224}, {"SDSS3256", 0.108, 19.495, 0.942, -0.029, 
    0.222}, {"SDSS7147", 0.11, 19.516, 0.796, -0.034, 
    0.195}, {"SDSS8719", 0.116, 19.392, 0.992, -0.059, 
    0.199}, {"SDSS5395", 0.117, 19.459, 1.11, 0.002, 
    0.188}, {"SDSS2561", 0.118, 19.813, 0.993, 0.086, 
    0.193}, {"SDSS1371", 0.119, 19.073, 1.072, -0.076, 
    0.187}, {"SDSS5549", 0.121, 19.654, 1.02, 0.033, 
    0.182}, {"SDSS2916", 0.124, 19.937, 0.875, 0.066, 
    0.248}, {"06D2fb", 0.124, 19.772, 0.964, -0.004, 
    0.181}, {"SDSS6406", 0.125, 19.616, 1, 0.026, 0.188}, {"SDSS2992",
     0.127, 20.034, 0.889, 0.127, 0.21}, {"SDSS744", 0.128, 19.793, 
    1.149, 0.08, 0.25}, {"SDSS5751", 0.13, 20.136, 1.068, 0.191, 
    0.179}, {"SDSS1032", 0.13, 20.326, 0.717, 0.088, 
    0.219}, {"SDSS2635", 0.143, 19.83, 1.092, -0.015, 
    0.202}, {"SDSS1794", 0.143, 20.058, 1.136, 0.018, 
    0.244}, {"SDSS8921", 0.145, 19.961, 1.104, 0.007, 
    0.231}, {"SDSS5103", 0.146, 20.377, 0.963, 0.055, 
    0.191}, {"SDSS11300", 0.147, 20.309, 0.862, 0.11, 
    0.243}, {"SDSS10106", 0.147, 20.948, 0.99, 0.2, 
    0.233}, {"SDSS2308", 0.148, 19.587, 1.069, -0.164, 
    0.189}, {"SDSS2031", 0.153, 19.703, 1.049, -0.091, 
    0.195}, {"SDSS5550", 0.156, 19.844, 1.202, -0.055, 
    0.19}, {"SDSS2689", 0.162, 20.254, 1.165, 0.095, 
    0.202}, {"SDSS3087", 0.165, 20.266, 1.056, 0.025, 
    0.196}, {"05D3ne", 0.169, 20.251, 0.809, -0.147, 
    0.218}, {"SDSS5916", 0.172, 20.439, 0.922, 0.014, 
    0.206}, {"SDSS3080", 0.174, 20.236, 0.999, -0.038, 
    0.195}, {"SDSS5350", 0.175, 20.323, 0.913, -0.057, 
    0.248}, {"SDSS5635", 0.179, 20.923, 1.011, 0.002, 
    0.233}, {"SDSS2372", 0.181, 20.58, 1.032, 0.045, 
    0.21}, {"SDSS6936", 0.181, 20.575, 1.003, -0.007, 
    0.208}, {"SDSS1580", 0.183, 20.291, 1.099, -0.014, 
    0.215}, {"05D2ah", 0.184, 20.765, 0.991, 0.019, 
    0.184}, {"SDSS6422", 0.184, 20.274, 1.08, -0.097, 
    0.193}, {"SDSS8213", 0.185, 21.133, 0.923, 0.179, 
    0.226}, {"SDSS5994", 0.187, 20.476, 1.074, -0.041, 
    0.218}, {"SDSS6304", 0.19, 20.952, 0.927, 0.095, 
    0.207}, {"SDSS762", 0.191, 20.657, 1.102, 0.009, 
    0.211}, {"SDSS2440", 0.193, 20.653, 1.051, -0.062, 
    0.212}, {"SDSS7335", 0.198, 21.265, 0.781, 0.067, 
    0.243}, {"SDSS6780", 0.202, 20.947, 0.789, -0.004, 
    0.246}, {"SDSS7243", 0.204, 20.789, 1.079, 0.002, 
    0.237}, {"SDSS3331", 0.206, 21.089, 0.95, 0.076, 
    0.225}, {"04D1dc", 0.211, 21.084, 0.856, 0.023, 
    0.191}, {"SDSS7847", 0.212, 21.225, 1.017, 0.155, 
    0.224}, {"SDSS6933", 0.213, 20.832, 0.995, 0.002, 
    0.202}, {"SDSS8495", 0.214, 20.811, 1.098, -0.001, 
    0.246}, {"SDSS1316", 0.217, 20.907, 1.058, -0.073, 
    0.374}, {"SDSS9467", 0.218, 21.057, 0.83, -0.118, 
    0.269}, {"05D3kx", 0.219, 20.867, 1.069, -0.016, 
    0.179}, {"SDSS7512", 0.219, 21.104, 1.055, 0.027, 
    0.233}, {"SDSS5533", 0.22, 21.173, 0.976, 0.046, 
    0.21}, {"SDSS3452", 0.23, 20.799, 1.092, -0.068, 
    0.211}, {"SDSS10449", 0.244, 20.995, 1.109, 0.039, 
    0.285}, {"SDSS3377", 0.245, 20.791, 1.12, -0.06, 
    0.219}, {"05D3mq", 0.246, 21.521, 0.912, 0.034, 
    0.204}, {"SDSS3451", 0.25, 20.958, 1.055, -0.038, 
    0.22}, {"06D3gn", 0.25, 21.892, 0.949, 0.16, 0.186}, {"SDSS3199", 
    0.251, 21.539, 1.164, 0.03, 0.224}, {"SDSS5717", 0.252, 21.355, 
    1.175, -0.012, 0.211}, {"SDSS5736", 0.253, 21.421, 0.949, 0.011, 
    0.211}, {"SDSS9032", 0.254, 21.345, 1.075, 0.041, 
    0.271}, {"SDSS9457", 0.257, 21.453, 0.978, 0.022, 
    0.302}, {"SDSS1112", 0.258, 21.563, 0.918, 0.022, 
    0.302}, {"SDSS8046", 0.259, 21.633, 1.049, 0.077, 
    0.249}, {"SDSS6108", 0.259, 21.537, 1.065, 0.063, 
    0.246}, {"SDSS3241", 0.259, 21.01, 1.057, -0.168, 
    0.251}, {"SDSS1253", 0.262, 21.23, 0.871, -0.09, 
    0.253}, {"SDSS2017", 0.262, 21.286, 1.148, -0.085, 
    0.26}, {"04D3ez", 0.263, 21.697, 0.891, 0.089, 0.184}, {"05D1hk", 
    0.263, 21.184, 1.168, -0.006, 0.192}, {"SDSS2422", 0.265, 21.144, 
    1.112, -0.156, 0.215}, {"SDSS2943", 0.265, 21.372, 1.055, 0.007, 
    0.24}, {"SDSS6315", 0.267, 20.919, 0.971, -0.166, 
    0.233}, {"06D3fp", 0.268, 21.748, 0.999, 0.104, 0.18}, {"03D4cj", 
    0.27, 21.052, 1.124, -0.063, 0.184}, {"SDSS6192", 0.272, 21.698, 
    0.826, -0.018, 0.268}, {"SDSS5957", 0.28, 21.453, 0.983, -0.089, 
    0.245}, {"06D3dt", 0.282, 22.168, 0.986, 0.117, 0.192}, {"03D4ag",
     0.285, 21.277, 1.111, -0.043, 0.19}, {"SDSS2165", 0.288, 21.604, 
    1.063, -0.096, 0.245}, {"SDSS2789", 0.29, 21.576, 0.901, -0.077, 
    0.27}, {"03D3ba", 0.291, 21.984, 1.084, 0.146, 
    0.238}, {"SDSS6249", 0.294, 21.821, 1.086, 0.064, 
    0.256}, {"SDSS10550", 0.3, 22.02, 1.162, 0.105, 0.372}, {"06D4dh",
     0.303, 21.449, 1.052, -0.126, 0.185}, {"SDSS11864", 0.303, 
    22.299, 1.015, 0.07, 0.432}, {"SDSS5966", 0.31, 21.798, 1.02, 
    0.002, 0.315}, {"SDSS6699", 0.311, 21.796, 0.872, -0.126, 
    0.277}, {"SDSS5844", 0.311, 21.571, 1.015, -0.099, 
    0.254}, {"SDSS6649", 0.314, 21.598, 1.09, -0.057, 
    0.251}, {"SDSS7475", 0.322, 21.535, 1.025, -0.123, 
    0.251}, {"05D2ab", 0.323, 22.001, 0.987, -0.013, 
    0.191}, {"SDSS6924", 0.328, 21.633, 1.076, -0.041, 
    0.265}, {"03D1fc", 0.332, 21.866, 1.048, 0.016, 0.194}, {"04D3kr",
     0.337, 21.957, 1.127, -0.004, 0.184}, {"SDSS2533", 0.34, 21.79, 
    1.191, -0.04, 0.278}, {"04D3nh", 0.34, 22.142, 1.059, 0.009, 
    0.184}, {"03D1bp", 0.347, 22.421, 0.88, 0.002, 0.192}, {"04D2mc", 
    0.348, 22.58, 0.845, 0.142, 0.205}, {"05D2ie", 0.348, 22.249, 
    0.988, -0.046, 0.198}, {"SDSS9207", 0.35, 22.062, 1.126, 0.022, 
    0.322}, {"05D2hc", 0.35, 22.693, 0.931, 0.057, 0.194}, {"05D2mp", 
    0.354, 22.417, 1.138, 0.058, 0.208}, {"03D3bl", 0.355, 22.951, 
    1.002, 0.241, 0.211}, {"04D2fs", 0.357, 22.437, 1.01, 0.081, 
    0.191}, {"04D3fk", 0.358, 22.537, 0.96, 0.11, 0.184}, {"04D1hd", 
    0.369, 22.166, 1.071, -0.06, 0.179}, {"04D2cf", 0.369, 22.491, 
    0.882, 0.015, 0.265}, {"05D3jr", 0.37, 22.663, 0.902, 0.096, 
    0.189}, {"03D3ay", 0.371, 22.293, 1.054, -0.018, 
    0.234}, {"05D4bm", 0.372, 22.22, 1.02, -0.041, 0.183}, {"05D4fo", 
    0.373, 22.463, 0.924, -0.022, 0.183}, {"05D4cw", 0.375, 22.145, 
    0.911, -0.12, 0.187}, {"SDSS7779", 0.381, 21.943, 1.124, -0.049, 
    0.25}, {"SDSS5737", 0.393, 22.439, 1.27, 0.144, 
    0.339}, {"SDSS8707", 0.395, 22.272, 1.11, -0.088, 
    0.26}, {"05D4ff", 0.402, 22.615, 0.932, 0.028, 0.192}, {"06D3ed", 
    0.404, 22.615, 0.963, -0.036, 0.182}, {"05D4dt", 0.407, 22.808, 
    0.891, -0.023, 0.186}, {"06D4cq", 0.411, 22.562, 1.04, -0.005, 
    0.184}, {"04D2fp", 0.415, 22.559, 1.034, -0.012, 
    0.197}, {"05D2dw", 0.417, 22.488, 1.125, 0.021, 0.198}, {"05D3cf",
     0.419, 22.965, 0.97, 0.045, 0.203}, {"04D4gg", 0.424, 22.753, 
    1.131, 0.124, 0.207}, {"05D2cb", 0.427, 23.407, 1.1, 0.193, 
    0.206}, {"04D1rh", 0.435, 22.582, 1.085, -0.015, 
    0.203}, {"06D4co", 0.437, 22.521, 0.96, -0.027, 0.183}, {"06D2gb",
     0.442, 23.008, 0.829, 0.03, 0.23}, {"06D3df", 0.442, 22.685, 
    1.122, 0.021, 0.195}, {"03D3aw", 0.449, 22.654, 1.066, -0.053, 
    0.241}, {"04D2gb", 0.45, 22.916, 0.831, 0.042, 0.21}, {"04D3gt", 
    0.451, 23.259, 0.976, 0.223, 0.192}, {"03D3cd", 0.461, 22.593, 
    1.208, 0.012, 0.293}, {"05D3lc", 0.461, 22.982, 0.913, -0.021, 
    0.187}, {"03D4au", 0.468, 23.817, 1.048, 0.158, 0.239}, {"05D3mx",
     0.47, 23.043, 0.832, -0.057, 0.202}, {"04D4jr", 0.47, 22.642, 
    1.16, -0.026, 0.195}, {"04D3df", 0.47, 23.521, 0.787, 0.108, 
    0.199}, {"04D4ju", 0.472, 23.771, 1.045, 0.184, 0.214}, {"05D2bv",
     0.474, 22.719, 0.989, -0.096, 0.197}, {"05D2ac", 0.479, 22.677, 
    1.133, -0.012, 0.191}, {"05D3dd", 0.48, 22.941, 0.985, -0.015, 
    0.203}, {"05D1ix", 0.49, 22.879, 1.054, -0.034, 0.198}, {"03D1ax",
     0.496, 22.992, 0.925, -0.062, 0.196}, {"05D4af", 0.499, 23.108, 
    1.01, -0.013, 0.222}, {"06D2bk", 0.499, 23.273, 1.054, 0.036, 
    0.234}, {"03D1au", 0.504, 23.012, 1.137, 0.017, 0.203}, {"05D4av",
     0.509, 23.558, 1.095, 0.185, 0.204}, {"05D2dy", 0.51, 22.913, 
    1.099, -0.1, 0.211}, {"04D2mj", 0.513, 23.783, 1.154, 0.171, 
    0.216}, {"04D1pg", 0.515, 23.57, 1.092, 0.119, 0.218}, {"05D3ci", 
    0.515, 23.564, 1.166, 0.16, 0.278}, {"04D4in", 0.516, 22.902, 
    1.169, -0.034, 0.201}, {"06D3el", 0.519, 22.913, 1.08, -0.082, 
    0.196}, {"04D2gc", 0.522, 23.327, 1.133, 0.037, 0.219}, {"06D2ca",
     0.531, 23.301, 1.099, 0.06, 0.249}, {"06D2cc", 0.532, 23.468, 
    0.944, 0.089, 0.256}, {"05D2eb", 0.534, 23.006, 1.113, -0.036, 
    0.233}, {"05D4ek", 0.536, 23.303, 1.059, 0.081, 0.21}, {"05D4be", 
    0.537, 22.916, 1.1, -0.114, 0.199}, {"04D4bq", 0.55, 23.347, 
    1.095, 0.134, 0.23}, {"04D3hn", 0.552, 23.503, 0.935, 0.096, 
    0.21}, {"06D2ck", 0.552, 23.447, 1.05, -0.002, 0.249}, {"06D4bo", 
    0.552, 23.231, 1.098, -0.028, 0.227}, {"05D1ee", 0.559, 23.556, 
    0.953, 0.023, 0.222}, {"04D1hx", 0.56, 23.715, 1.042, 0.143, 
    0.215}, {"05D1kl", 0.56, 24.154, 1.075, 0.164, 0.246}, {"05D1cc", 
    0.563, 23.496, 0.981, -0.005, 0.211}, {"05D1dn", 0.566, 23.317, 
    1.129, 0.018, 0.222}, {"03D4gl", 0.571, 23.314, 1.238, 0.039, 
    0.831}, {"05D2dt", 0.574, 23.656, 1.024, 0.045, 0.249}, {"06D3et",
     0.576, 23.512, 0.861, -0.039, 0.213}, {"05D3jq", 0.579, 23.322, 
    1.161, 0.035, 0.209}, {"05D3gp", 0.58, 23.521, 0.946, -0.054, 
    0.286}, {"03D4gf", 0.58, 23.336, 1.095, 0.01, 0.236}, {"05D1dx", 
    0.58, 23.304, 1.078, -0.027, 0.205}, {"03D1aw", 0.582, 23.584, 
    1.098, 0.001, 0.235}, {"04D1jg", 0.584, 23.272, 1.028, -0.079, 
    0.219}, {"04D1kj", 0.585, 23.345, 1.034, -0.052, 
    0.211}, {"05D4ej", 0.585, 23.746, 1.034, 0.02, 0.222}, {"04D1sa", 
    0.585, 23.559, 0.94, -0.064, 0.237}, {"05D1hm", 0.587, 24.102, 
    1.126, 0.155, 0.244}, {"05D4bf", 0.589, 23.627, 1.029, 0.018, 
    0.235}, {"04D2mh", 0.59, 23.403, 1.163, 0.041, 0.215}, {"04D1oh", 
    0.59, 23.388, 1.01, -0.048, 0.227}, {"03D4gg", 0.592, 23.413, 
    1.098, 0.046, 0.264}, {"05D3lr", 0.6, 23.854, 1.02, 0.096, 
    0.251}, {"05D4ef", 0.605, 23.832, 0.839, -0.054, 
    0.225}, {"05D2he", 0.608, 23.953, 1.044, 0.073, 0.244}, {"03D4dy",
     0.61, 23.268, 1.127, -0.06, 0.231}, {"04D3do", 0.61, 23.577, 
    0.906, -0.097, 0.213}, {"03D1dt", 0.612, 23.3, 1.048, -0.054, 
    0.273}, {"04D4an", 0.613, 24.046, 0.987, 0.025, 0.27}, {"05D1ck", 
    0.617, 24.074, 1.007, 0.111, 0.231}, {"04D2an", 0.62, 23.597, 
    0.991, -0.019, 0.295}, {"04D3co", 0.62, 23.757, 0.936, 0.019, 
    0.245}, {"03D4dh", 0.627, 23.39, 1.13, -0.045, 0.225}, {"04D4fx", 
    0.629, 23.501, 1.115, 0.01, 0.23}, {"05D2ci", 0.63, 23.612, 0.901,
     0.045, 0.263}, {"05D1cb", 0.632, 23.715, 0.967, -0.001, 
    0.222}, {"03D4at", 0.634, 23.733, 1.019, -0.008, 
    0.261}, {"04D1pu", 0.639, 24.024, 0.843, 0.094, 0.291}, {"05D2ec",
     0.64, 23.672, 0.994, -0.063, 0.248}, {"05D4ag", 0.64, 23.895, 
    1.055, 0.068, 0.287}, {"05D3ax", 0.643, 23.62, 1.071, -0.034, 
    0.28}, {"04D3cy", 0.643, 23.8, 0.978, -0.011, 0.257}, {"05D3lb", 
    0.647, 23.896, 1.04, 0.035, 0.224}, {"05D3kt", 0.648, 23.965, 
    0.979, 0.085, 0.23}, {"04D1sk", 0.663, 24.058, 1.028, 0.1, 
    0.251}, {"05D3hs", 0.664, 23.501, 1.045, -0.141, 
    0.234}, {"05D3mh", 0.67, 24.106, 1.084, 0.053, 0.272}, {"03D1co", 
    0.679, 24.088, 1.084, -0.019, 0.266}, {"05D2bt", 0.68, 23.521, 
    1.067, -0.113, 0.239}, {"06D3cc", 0.683, 24.067, 1.082, 0.006, 
    0.312}, {"04D4ic", 0.687, 24.121, 0.9, -0.01, 0.276}, {"06D3em", 
    0.69, 24.377, 1.006, 0.149, 0.259}, {"05D1ke", 0.69, 23.611, 
    1.035, -0.077, 0.23}, {"03D4cz", 0.695, 24.045, 0.818, -0.071, 
    0.292}, {"05D2ck", 0.698, 24.474, 0.733, -0.015, 
    0.277}, {"04D4ib", 0.699, 23.595, 1.101, -0.093, 
    0.233}, {"04D2iu", 0.7, 24.246, 0.806, 0.021, 0.288}, {"06D4ba", 
    0.7, 23.761, 1.065, -0.081, 0.28}, {"05D2le", 0.7, 23.961, 
    1.054, -0.012, 0.247}, {"05D4cq", 0.701, 23.73, 1.077, -0.058, 
    0.24}, {"05D4bj", 0.701, 24.103, 1.012, 0.059, 0.249}, {"04D1si", 
    0.702, 23.867, 0.994, -0.003, 0.244}, {"04D4hu", 0.703, 23.92, 
    1.005, -0.078, 0.241}, {"05D3gv", 0.715, 24.001, 0.911, -0.043, 
    0.254}, {"05D3jh", 0.718, 23.753, 0.927, -0.096, 0.23}, {"06D3gh",
     0.72, 23.926, 1.034, -0.021, 0.27}, {"04D1aj", 0.721, 23.904, 
    1.03, -0.004, 0.266}, {"05D4ev", 0.722, 24.259, 0.896, -0.014, 
    0.259}, {"06D3do", 0.725, 23.898, 1.096, -0.044, 
    0.281}, {"06D3bz", 0.727, 23.959, 0.923, -0.057, 
    0.268}, {"04D2gp", 0.732, 24.219, 0.849, -0.091, 0.29}, {"06D4bw",
     0.732, 23.904, 1.066, 0.005, 0.25}, {"05D2fq", 0.733, 23.997, 
    1.084, -0.033, 0.249}, {"05D2ct", 0.734, 24.385, 1.042, 0.093, 
    0.293}, {"04D1pp", 0.735, 23.998, 0.865, -0.064, 
    0.236}, {"05D3jk", 0.736, 23.717, 1.082, -0.079, 
    0.227}, {"05D1eo", 0.737, 24.316, 0.854, -0.038, 
    0.255}, {"04D2ja", 0.74, 24.129, 1.04, -0.131, 0.281}, {"04D3fq", 
    0.742, 24.116, 0.956, -0.03, 0.264}, {"04D2kr", 0.744, 23.865, 
    1.057, -0.02, 0.247}, {"05D3jb", 0.745, 23.939, 1.102, -0.025, 
    0.235}, {"04D3ks", 0.75, 23.855, 1.075, -0.03, 0.257}, {"04D4im", 
    0.751, 23.852, 1.148, 0.043, 0.245}, {"04D3oe", 0.756, 24.06, 
    0.908, -0.161, 0.258}, {"05D2nt", 0.757, 24.099, 1.156, -0.006, 
    0.247}, {"05D3mn", 0.76, 24.043, 0.987, -0.021, 0.244}, {"06D3gx",
     0.76, 23.885, 1.043, -0.089, 0.296}, {"05D4cn", 0.763, 24.102, 
    1.111, 0.015, 0.243}, {"05D1if", 0.763, 24.059, 1.019, -0.035, 
    0.243}, {"05D3hh", 0.766, 24.319, 1.07, 0.018, 0.279}, {"04D1qd", 
    0.767, 24.228, 1.007, 0.012, 0.245}, {"04D1de", 0.768, 24.144, 
    1.101, -0.079, 0.241}, {"04D4id", 0.769, 24.212, 1.074, -0.1, 
    0.276}, {"04D1pc", 0.77, 24.553, 0.97, 0.067, 0.256}, {"05D4bi", 
    0.775, 24.051, 1.098, -0.094, 0.268}, {"04D1jd", 0.778, 24.425, 
    1.01, 0.051, 0.258}, {"05D4cs", 0.79, 23.967, 1.135, -0.061, 
    0.236}, {"03D4fd", 0.791, 24.232, 1.072, -0.024, 
    0.288}, {"04D1ks", 0.798, 24.145, 1.079, 0.076, 0.251}, {"05D3dh",
     0.8, 24.203, 1.009, 0.078, 0.26}, {"03D1fq", 0.8, 24.512, 
    0.87, -0.045, 0.272}, {"05D3cx", 0.805, 23.913, 1.051, -0.11, 
    0.266}, {"05D3ha", 0.805, 24.388, 0.972, 0.09, 0.287}, {"05D4gw", 
    0.808, 24.481, 1.025, 0.047, 0.288}, {"05D4dy", 0.81, 24.617, 
    0.956, -0.083, 0.275}, {"04D3ny", 0.81, 24.262, 1.024, 0.011, 
    0.31}, {"04D4dm", 0.811, 24.402, 0.981, 0.021, 0.267}, {"04D3mk", 
    0.813, 24.294, 0.954, -0.104, 0.254}, {"04D3nc", 0.817, 24.293, 
    1.139, -0.022, 0.28}, {"06D2ce", 0.82, 24.215, 1.219, 0.018, 
    0.333}, {"04D3lu", 0.822, 24.377, 0.934, -0.084, 0.25}, {"05D1cl",
     0.83, 24.353, 1.242, -0.018, 0.269}, {"04D3cp", 0.83, 24.111, 
    1.049, -0.18, 0.256}, {"04D2al", 0.836, 24.319, 0.933, -0.04, 
    0.372}, {"Elvis", 0.839, 24.397, 0.985, 0, 0.263}, {"05D4fg", 
    0.839, 24.195, 1.024, -0.102, 0.254}, {"06D2ga", 0.84, 24.29, 
    1.176, -0.001, 0.356}, {"05D1az", 0.842, 24.254, 1.184, 0.015, 
    0.269}, {"05D4hn", 0.842, 24.196, 1.122, 0.048, 0.319}, {"04D1hy",
     0.85, 24.307, 1.11, -0.026, 0.254}, {"06D4ce", 0.85, 24.205, 
    1.168, -0.059, 0.303}, {"05D3kp", 0.85, 24.139, 1.131, -0.082, 
    0.243}, {"05D4dw", 0.855, 24.438, 1.046, 0.008, 0.278}, {"04D1ff",
     0.86, 24.243, 1.08, 0.046, 0.257}, {"05D1iz", 0.86, 24.392, 
    1.095, -0.082, 0.336}, {"05D1er", 0.86, 24.618, 1.042, 0.062, 
    0.29}, {"03D1bk", 0.865, 24.345, 1.018, -0.167, 0.263}, {"05D1em",
     0.866, 24.283, 1.017, -0.1, 0.26}, {"04D4ii", 0.866, 24.399, 
    1.165, 0.039, 0.284}, {"03D1ew", 0.868, 24.359, 1.036, -0.036, 
    0.284}, {"05D2nn", 0.87, 24.395, 0.879, -0.147, 0.321}, {"04D4bk",
     0.88, 24.327, 1.181, -0.061, 0.28}, {"05D3cq", 0.89, 24.22, 
    0.96, -0.151, 0.278}, {"05D2by", 0.891, 24.568, 1.132, -0.008, 
    0.29}, {"03D4di", 0.899, 24.314, 1.146, -0.043, 0.29}, {"05D3ht", 
    0.901, 24.417, 1.118, -0.095, 0.282}, {"04D3gx", 0.91, 24.666, 
    0.94, -0.11, 0.293}, {"04D1ow", 0.915, 24.366, 1.004, -0.124, 
    0.268}, {"05D2bw", 0.92, 24.4, 0.972, -0.111, 0.319}, {"05D2ay", 
    0.92, 24.672, 0.983, 0.014, 0.349}, {"05D2ob", 0.924, 24.822, 
    1.103, 0.033, 0.318}, {"03D4cy", 0.927, 24.705, 1.103, -0.032, 
    0.346}, {"06D2cd", 0.93, 24.876, 1.166, 0.051, 0.49}, {"04D4jy", 
    0.93, 24.765, 1.022, -0.076, 0.345}, {"04D4ih", 0.934, 24.43, 
    1.03, -0.166, 0.276}, {"Vilas", 0.935, 24.473, 1.036, -0.028, 
    0.272}, {"04D4hf", 0.936, 24.811, 1.081, 0.028, 0.35}, {"05D3la", 
    0.936, 24.494, 0.967, -0.083, 0.267}, {"03D4cx", 0.949, 24.464, 
    0.947, 0.019, 0.331}, {"04D1pd", 0.95, 24.734, 1.039, 0.022, 
    0.298}, {"04D3ml", 0.95, 24.56, 1.117, -0.077, 0.29}, {"04D3nr", 
    0.96, 24.587, 0.99, 0.005, 0.299}, {"05D3km", 0.96, 24.773, 
    1.022, -0.123, 0.28}, {"04D4jw", 0.961, 24.848, 0.892, -0.173, 
    0.365}, {"Patuxent", 0.97, 25.026, 0.962, -0.129, 0.356}, {"Ombo",
     0.975, 24.891, 1.208, 0.018, 0.271}, {"05D2my", 0.981, 24.688, 
    1.13, -0.026, 0.305}, {"04D3lp", 0.983, 25.023, 0.816, -0.044, 
    0.378}, {"04D1rx", 0.985, 24.77, 1.081, -0.062, 0.307}, {"04D1iv",
     0.998, 24.624, 1.152, -0.074, 0.285}, {"06D4cl", 1, 24.578, 
    1.13, -0.065, 0.296}, {"04D3dd", 1.002, 25.234, 1.112, -0.016, 
    0.412}, {"Strolger", 1.01, 24.99, 1.195, -0.077, 0.433}, {"Eagle",
     1.02, 24.968, 1.017, -0.061, 0.289}, {"Ferguson", 1.02, 24.867, 
    1.023, 0.007, 0.329}, {"04D4dw", 1.031, 24.546, 1.127, -0.08, 
    0.326}, {"06D3en", 1.06, 24.756, 0.858, -0.139, 0.358}, {"Gabi", 
    1.12, 25.121, 1.048, -0.037, 0.278}, {"Greenberg", 1.14, 24.727, 
    1.09, -0.055, 0.325}, {"Lancaster", 1.23, 26.054, 0.969, 0.073, 
    0.335}, {"Torngasek", 1.265, 25.757, 1.04, 0.028, 
    0.354}, {"Aphrodite", 1.3, 25.691, 1.058, 0.013, 0.284}, {"Borg", 
    1.34, 25.87, 1.192, 0.09, 0.389}, {"Sasquatch", 1.39, 25.956, 
    1.193, 0.112, 0.535}, {"Primo", 1.54992, 25.7576, 
    0.168369, -0.197134, 0.6329682}, {" GND13Sto ", 1.8, 26.1369, 
    0.527158, -0.0156538, 0.9455797}, {"SN UDS10Wil", 1.914, 
    26.2, -0.5, -0.071, 0.85}, {"GND12Col", 2.25, 26.791, 1.1517, 
    0.0421647, 1.381078}};

And here is the function that selects the minimum value:

FindMinimum[{chiSquared[t1, a0]}, {{t1, 1*^16}, {a0, 1}}]

This will return:

{111076., {t1 -> 6.65636*10^18, a0 -> 3.87928*10^-14}}

Which is pretty close, but if you remove the initializers, or set t1 to 1, then it's unable to find a minimum.

FindMinimum[{chiSquared[t1, a0]}, {t1, a0}]

{1.49713*10^7, {t1 -> 72.0749, a0 -> -2.21105*10^7}}

How do I get the FindMinimum function to work if I don't know the answer?

$\endgroup$
5
  • 3
    $\begingroup$ What's your question? $\endgroup$
    – Michael E2
    Commented Aug 10, 2016 at 21:24
  • 10
    $\begingroup$ "works only if I supply values that are close to the answer." - why yes, that's precisely how one uses methods based on Newton-Raphson and ilk. You either supply good brackets or good seeds, as these iterative methods have a propensity to shoot off into the wild blue yonder if not suitably restricted. I'm glad you realized that quickly. Most people get to their Ph.D.s without ever getting that insight. $\endgroup$ Commented Aug 10, 2016 at 21:40
  • $\begingroup$ I'm trying to move my code from Origin Lab 9 which uses the Levenberg Marquardt algorithm. That package is able to find a more accurate minimum starting with values of t1=0, a0=0 and constraints of 0 < t1 and 0 < a0. Why can't I get the Mathematica function to work with the same conditions and constraints? $\endgroup$
    – Quark Soup
    Commented Aug 10, 2016 at 21:45
  • 3
    $\begingroup$ Then why not use FindFit[]? That explicitly uses LM by default unless told otherwise. If you insist on using FindMinimum[] then set Method -> "LevenbergMarquardt" directly. But you still need to give good seeds, and that is something that you who (is supposed to) know the data should be able to supply. $\endgroup$ Commented Aug 10, 2016 at 21:56
  • 8
    $\begingroup$ When parameters in a model are orders of magnitude different from each other iterative methods can easily get lost and/or leap over solutions. (And here you've got 10^18 compared to 10^-14.) You might try scaling things so that the estimated parameters are both around 1 to 10. This might sound like you need to know the answer but there are plenty of clues from the data to get an approximate order of magnitude. $\endgroup$
    – JimB
    Commented Aug 10, 2016 at 21:56

3 Answers 3

8
$\begingroup$

This is more of an extended comment than an answer. First, building off @JackLaVigne's work, I think it's better to work in log of your parameters, so I defined a new objective function

chiSquared2[t1pow_, a0pow_] := Sum[residual[i, 10^t1pow, 10^a0pow]^2/error[i]^2, {i, 1, Length[data]}]

This still doesn't work well inside FindMinimum without a starting guess:

FindMinimum[{chiSquared2[t1pow, a0pow]}, {t1pow, a0pow}]
(* {1.49713*10^7, {t1pow -> 8.10751, a0pow -> -22095.5}} *)

With a good starting guess, it arrives at the same answer you found:

FindMinimum[{chiSquared2[t1pow, a0pow]}, {{t1pow, 18}, {a0pow, -14}}]
(* {111076., {t1pow -> 18.8232, a0pow -> -13.4112}} *)

Let's have a look at the objective function:

ContourPlot[Log10[chiSquared2[t1pow, a0pow]], {t1pow, 0, 20}, {a0pow, -16, 2},
Epilog -> {Red, Point[{18.823, -13.4112}]}]

Mathematica graphics

Looks like a large, flat plain in dark blue, bordered by a ramp in the northeast corner. If you start at (1,1) it'd be hard to know which direction takes you down to the minimum at the red dot. Our success with FindMinimum tells us the minimum is somewhere around that little horn in the landscape. Let's zoom in there:

ContourPlot[Log10[chiSquared2[t1pow, a0pow]], {t1pow, 16, 20}, {a0pow, -20, -12},
Epilog -> {Red, Point[{18.823, -13.4112}]}]

Mathematica graphics

Enhance!

ContourPlot[Log10[chiSquared2[t1pow, a0pow]], {t1pow, 18.0, 19.2}, {a0pow, -14, -13},
Epilog -> {Red, Point[{18.823, -13.4112}]}]

Mathematica graphics

So you can see why a good starting guess is required.

$\endgroup$
1
  • $\begingroup$ Love the way your graphics demonstrate the problem $\endgroup$ Commented Dec 24, 2019 at 16:27
7
$\begingroup$

Let's apply Jim Baldwin's idea of scaling the parameters so that they are in the same ball park.

I will use but not re-copy data from the question.

c = 2.99792*^5;
megaParsec = 3.08567758*^19;
alpha = 0.147;
beta = 3.13;
mag = -19.34;

I have some small modifications to your functions.

observedDistance[i_] := Module[
  {
   magnitude
   },
  magnitude = 
   data[[i, 3]] + alpha*(data[[i, 4]] - 1) - beta*data[[i, 5]] - mag;
  10^((magnitude - 25)/5)*megaParsec
  ]

luminousDistance[z_, t1_, a0_] := -(a0*t1^2*z + 
    2*c*(-t1*(1 + z) + Sqrt[t1^2*(1 + z)]))/(2 + z)

residual[i_, t1_, a0_] := Module[
  {
   z = data[[i, 2]]
   },
  observedDistance[i] - luminousDistance[z, t1, a0]
  ]

error[i_] := Module[
  {
   distance = observedDistance[i],
   distanceModuli
   },
  distanceModuli = Log10[distance/megaParsec]*5 + 25; 
  distance*data[[i, 6]]/distanceModuli
  ]

Update (get ball park values)

In order to get values that are in the ballpark Manipulate can sometimes be used (this won't work for all functions because they may have a restricted range). Your question indicates that you would like to allow your parameters to have a very wide range.

First I will take data and generate the magnitude from it and call it dataM:

dataM = Table[observedDistance[i], {i, Length@data}];

We will look at the logarithm of this distance or magnitude.

ListPlot[Transpose@Join[{data[[All, 2]], Log10[dataM]}]]

Mathematica graphics

We create a Manipulate to scan the parameters from 10^-40 to 10^40. We are going to use the exponent from -40 to 40 as the input to the Manipulate.

Manipulate[
 DynamicModule[
  {
   minLogChi = 
    Min[21.1479, Log10[luminousDistance[0.01, 10.^t1Exp, 10.^a0Exp]]],
   maxLogChi = 
    Max[23.6936, Log10[luminousDistance[2.25, 10.^t1Exp, 10.^a0Exp]]]
   },
  Show[
   Plot[
    Log10[luminousDistance[z, 10.^t1Exp, 10.^a0Exp]],
    {z, 0.01, 2.25},
    PlotStyle -> Red
    ],
   ListPlot[
    Transpose@Join[{data[[All, 2]], Log10[dataM]}],
    PlotStyle -> Black
    ],
   PlotRange -> {{0, 2.25}, {minLogChi, maxLogChi}}
   ]
  ],
 {{t1Exp, 18.0}, -40, 40, Appearance -> "Open"},
 {{a0Exp, -14.0}, -40, 40, Appearance -> "Open"}
 ]

Mathematica graphics

If you scroll the the exponents you will find that you can't get much bigger than 19 for t1Exp (or you get an error). Also you can't get much bigger than -13 for a0Exp.

You can type in values fort1Exp and/or a0Exp or make a second Manipulate with a tighter range.

Either way you will come to the conclusion that t1Exp = 18 is best. Also a0Exp must be less than or equal to -13.

Now proceed to the next phase.

Scaled Parameters

The key modification is to scale the parameters that are being optimized so they are within approximately one to ten.

chiSquared[t1Scaled_, a0Scaled_] := Module[
  {
   t1 = t1Scaled*10^18,
   a0 = a0Scaled*10^-14
   },
  Sum[residual[i, t1, a0]^2/error[i]^2, {i, 1, Length[data]}]
  ]

Now FindMinimum works fine without providing starting values

sol = FindMinimum[{chiSquared[t1Scaled, a0Scaled]}, {t1Scaled, a0Scaled}]

(* {111076., {t1Scaled -> 6.65636, a0Scaled -> 3.87928}} *)

You need to apply the scaling factor in order to get the unscaled parameters.

{t1, a0} = {t1Scaled*10^18, a0Scaled*10^-14} /. sol[[2]]

(* {6.65636*10^18, 3.87928*10^-14} *)
$\endgroup$
4
  • $\begingroup$ Thank you very much for the effort, but you've just moved the problem from the initial conditions to the scaling factors (Unless I'm missing something). My issue is how do I find these numbers if I don't know them already. The only way I found the scaling numbers in the first place was that the Origin Labs package found them for me without having to set the initial conditions. $\endgroup$
    – Quark Soup
    Commented Aug 11, 2016 at 9:49
  • 1
    $\begingroup$ @DR, the units of the quantities in your problem allow some choice, don't they? Why not choose units of the distance (apparently you are using parsecs) and the speed of light and other things so that the numbers are of comparable size? If you're working with parsecs already, convert everything else that uses a unit of length to use parsecs. That's what scaling is. $\endgroup$ Commented Aug 11, 2016 at 13:31
  • 3
    $\begingroup$ @DRAirey1 In the current form your problem is akin to asking a virus to find the highest elevation of a mountain range... Do you really expect that to succeed? (And actually I'm heavily exaggerating the size of a virus here, by approximately 28 orders of magnitude...) $\endgroup$
    – sebhofer
    Commented Aug 11, 2016 at 13:49
  • 1
    $\begingroup$ Check out this tutorial on Optimization as to why you need to supply a reasonable starting value. See the Update for how to get in the ball park. $\endgroup$ Commented Aug 11, 2016 at 19:17
-1
$\begingroup$

The root of the problem is the magnitude calculation which involves a Log10 operation, not the disparity between the power of the variables. The Log10 operation creates discontinuities in the solution space which the Mathematica solvers were not able to navigate.

The solution: instead of framing the problem in terms of the magnitude, I converted all the calculations and input values to kilometers. This made the solution space continuous and FindMinimum was able to find a solution that was reasonably close using very rough guesses for the initial conditions (t0 = 1*^14, a0 = 1). Then I used NMinimize and the original Log10 based calculations with a set of tight ranges around the result of the FindMinimum solution to find the absolute minimum in terms of magnitude and the magnitude errors.

Many thanks to Jack LaVigne for the effort he put into the scaled parameters solution but I think the real issue is that Mathematica's FindMinimum doesn't handle imaginary numbers well. The package from Original Labs, as it turns out, has a similar problem when the formula involves a Log10 operation: it can't navigate around the discontinuities.

Update:

Here is the code for the version that calculates the minimums using a continuous solution space by working in km instead of distance moduli (a notation similar to magnitude):

c = 299792.; 
megaParsec = 3.08567758*^19; 
alpha = 0.147; 
beta = 3.13; 
mag = -19.34; 
chiSquared[t1_, a0_] := Sum[residual[i, t1, a0]^2/error[i]^2, {i, 1, Length[data]}]
error[i_] := observedDistance[i, data[[i,6]]]
luminousDistance[z_, t1_, a0_] := -((a0*t1^2*z + 2*c*((-t1)*(1 + z) + Sqrt[t1^2*(1 + z)]))/(2 + z))
residual[i_, t1_, a0_] := observedDistance[i, 0.] - luminousDistance[data[[i,2]], t1, a0]
observedDistance[i_, error_] := (magnitude = data[[i,3]] + alpha*(data[[i,4]] - 1) - beta*data[[i,5]] - mag + error; 10^((magnitude - 25)/5)*megaParsec)
FindMinimum[{chiSquared[t1, a0]}, {{t1, 1*^16}, {a0, 1}}]

This will put you in the neighborhood using very rough guesses. The output is:

{3.00375, {t1 -> 6.76415*10^18, a0 -> 3.82816*10^-14}}

Which is close (like all the solutions that attempt to change the scale), but not the minimum. The chi-square on this solution is 0.74. Now that we're in the neighborhood, I can switch back to the Log10 version (the errors from Astronomy papers are always quoted in distance moduli, so it's the only valid test for Chi-Square). Here's the version using distance moduli:

c = 299792.; 
megaParsec = 3.08567758*^19; 
alpha = 0.147; 
beta = 3.13; 
mag = -19.34; 
chiSquared[t1_, a0_] := Sum[residual[i, t1, a0]^2/data[[i,6]]^2, {i, 1, Length[data]}]
luminousDistance[z_, t1_, a0_] := (distance = -((a0*t1^2*z + 2*c*((-t1)*(1 + z) + Sqrt[t1^2*(1 + z)]))/(2 + z)); 5*Log10[distance/megaParsec] + 25)
residual[i_, t1_, a0_] := observedDistance[i] - luminousDistance[data[[i,2]], t1, a0]
observedDistance[i_] := data[[i,3]] + alpha*(data[[i,4]] - 1) - beta*data[[i,5]] - mag
NMinimize[{chiSquared[x, y], 
  1*^17 < x < 1*^19 && 1*^-15 < y < 1*^-13}, {x, y}]

This version truly finds the minimum. The output is:

{342.207, {x -> 6.64112*10^18, y -> 3.87624*10^-14}}

And produces a chi-square of 0.72. So the solution is to first convert the formula to give a continuous solution space. Then the FindMinimum algorithms can navigate into the neighborhood of the minimum. Once you have the neighborhood, you can use NMinimize to find the absolute minimum.

$\endgroup$
7
  • $\begingroup$ I don't see anything in your answer substantiating the claim about "The Log10 operation creates discontinuities in the solution space". Would you supply the details in your answer? $\endgroup$
    – JimB
    Commented Aug 24, 2016 at 16:17
  • $\begingroup$ The distance moduli calculates the magnitude of the SNe Ia: distanceModuli = Log10[distance/megaParsec] * 5 + 25. As the minimizer algorithm (e.g. Levenberg-Marquardt) tries to calculate the slope of the function it will try values that create negative distances (because there's no reason not to try negative distances), thus creating imaginary distanceModuli. You can mark the solution down if you want, but messing with the magnitude produces a chi-square of 0.74. Using the NMinimize produces a chi-square of 0.72. $\endgroup$
    – Quark Soup
    Commented Aug 24, 2016 at 16:44
  • 1
    $\begingroup$ As you already accepted your "solution" you could at least post your code so that others can play with it. $\endgroup$
    – sebhofer
    Commented Aug 25, 2016 at 20:21
  • 1
    $\begingroup$ Using your original formulation, but setting c = 1; megaParsec = 1; (and thus getting rid of the ridiculously large and useless factors), and restricting t1 to positive values (which, I'm guessing, can be justified physically), we find an acceptable minimum without any more guessing of the starting values: FindMinimum[{chiSquared[t1, a0 ], t1 > 0}, {{t1, 1}, {a0, 1}}] results in {111076., {t1 -> 64670.5, a0 -> 0.0000133187}}... $\endgroup$
    – sebhofer
    Commented Aug 26, 2016 at 22:53
  • 1
    $\begingroup$ The whole point was to factor out c and megaParsec, as you should have from the very beginning and as people have been trying to tell you (although in different variations). Physically this means that all velocities are given in units of c, while all distances are given in megaParsec (or equivalently time is measured in megaParsec/c). As you can clearly see from the output I posted, the minimum found by FindMinimum is 111076 which coincides with the value in the OP and also what Jack found in his answer. (I didn't bother to crosscheck with the value 3.00375 found above though). $\endgroup$
    – sebhofer
    Commented Sep 5, 2016 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.