Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica:Having problem with my calculation(numerical)

  1. Aug 14, 2010 #1
    What wrong with my calculation.the problem is from the attachment.
    It keeps saying

    NMinimize::nnum:The function value .........is not a number at {x1,x2}=.....

    given x0=0 and x3=5
     

    Attached Files:

    Last edited: Aug 14, 2010
  2. jcsd
  3. Aug 14, 2010 #2

    phyzguy

    User Avatar
    Science Advisor

    Did you tell it what Y (capital Y) is? If so, you didn't tell us. NMinimize needs to know all of the values, it can't deal with variables.
     
  4. Aug 14, 2010 #3
    In[1]:=x0=0;x3=5;
    F[x_,y_]:=0.25`(4044.44444444445`-66.66666666666667`x+E^(-0.015x+0.015y)(-4044.44444444445`+66.66666666666667`y))^2;
    H[x_,y_]:=Integrate[0.25`(E^(-0.015`t)(E^(0.015`t)(4044.44444444445`-66.66666666666667`t)+E^(0.015`y)(-4044.44444444445`+66.66666666666667`y)))^2,{t,x,y}];
    NMinimize[{27+3*(F[x0,x1]+F[x1,x2]+F[x2,x3])+0.2*(H[x0,x1]+H[x1,x2]+H[x2,x3]),x0≤x1&&x1≤x2&&x2≤x3},{x1,x2}]

    Out[4]={4.457054464608864`*10^8, {x1 -> 0.06690213249753463`, x2 -> 1.1629357790698616`}}

    If I did not make an error typing this all back in again then I cannot explain what your problem is. But I believe you have larger problems than this. Quit kernel and restart

    In[1]:=a=1/4;b=4044+4/9;c=66+2/3;d=15/1000;x0=0;x3=5;
    F[x_,y_]:=a*(b-c*x+E^(-d*x+d*y)*(-b+c*y))^2;
    H[x_,y_]:=Integrate[a*(E^(-d*t)*(E^(d*t)*(b-c*t)+ E^(a*y)*(-b+c*y)))^2,{t,x,y}];
    NMinimize[{27+3*(F[x0,x1]+F[x1,x2]+F[x2,x3])+ 1/5*(H[x0,x1]+H[x1,x2]+H[x2,x3]),x0≤x1&&x1≤x2&&x2≤x3},{x1,x2}]

    Out[4]={7.388367735069655`*10^6, {x1 -> 2.4650125379662637`, x2 -> 3.9306108222644514`}}

    So very tiny changes in your coefficients give very different results.

    I would suggest you spend a few days reading about the details of approximate and exact and machine precision mathematics as provided by Mathematica. Much of that is probably not what you would expect it to be.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook