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

Matlab Urgent

  1. Mar 17, 2013 #1
    Matlab... Please Help! Urgent...

    Hi mates,

    how can I use the values from an excel file as variable values in the equation below ?

    in other words...I need to use a lot of g values listed in an excel sheet and to find the value for x...or I ll import g values to matlab from excel and export the results for x to excel again...

    hope I made myself clear (english is not my native language)

  2. jcsd
  3. Mar 17, 2013 #2
    Since you already have the data in Excel and would be willing to get the result back in Excel, can you use the Excel solver to get the answer you need?

    Let x be in one cell in Excel,
    all your g coefficients are in a row or column,
    create and duplicate an equation for each of your 1+gi*x in a second row or column,
    find (x+1) minus the product of those equations,
    Excel calls that your "target" and you want the solver to change the x cell until your target=0.

    Some default installations of Excel do not include the Solver and you need to add that if not present and if you have your original install CD.
  4. Mar 17, 2013 #3
    the equation is "(x+1)=(1+g1*x)*(1+g2*x)*(1+g3*x)*(1+g4*x)*( 1+g5*x)" and I m sure this cannot be solved in solver...it is not lineer and even it were the number of g's are not the same in all
  5. Mar 17, 2013 #4
    A1 is my x, Initially I had that set to zero but the Solver changes that to the solution.

    A2:A11 are RAND() values for gi
    B2:B11 are 1+gi*$A$1
    0.28972287 0.710277572
    0.8695732 0.130428127
    0.345551191 0.654449336
    0.076889749 0.923110368
    0.146407246 0.853592977
    0.022394367 0.977605667
    0.889095924 0.110905433
    0.683400649 0.316600394
    0.374551682 0.625448889
    0.550775199 0.449225642
    and PRODUCT(B2:B11)-($A$1+1)
    and if the formatting of the forum doesn't ruin this then you can see in a fraction of a second Excel's solver finds a solution over and over for each different set of RAND I choose.

    For the RAND I'm getting Solver often tends to an x of -1, which makes sense when you look at you equations. But this has nothing to do with the gi coefficients that you have.

    Maybe it will work for you, without your data there is no way of knowing.
    Last edited: Mar 17, 2013
  6. Mar 17, 2013 #5
    Here is my Data...

    Attached Files:

  7. Mar 17, 2013 #6
    As an example I took your last four rows of your Excel sheet for g.
    I assume those 4 columns are 4 different sets of g, so I did it four times.
    I used the method I described and in each case it found x=0 as a solution.

    That made me think I had made an error so I threw this at Mathematica

    In[1]:= g1=.658;g2=.214;g3=.232;g4=.808; Solve[(1+g1*x)*(1+g2*x)*(1+g3*x)*(1+g4*x)-(x+1)==0,x]

    Out[5]= {{x->-5.39832-2.73116 I},{x->-5.39832+2.73116 I},{x->-0.943977},{x->0.}}

    In[6]:= g1=.698;g2=.254;g3=.256;g4=.838; Solve[(1+g1*x)*(1+g2*x)*(1+g3*x)*(1+g4*x)-(x+1)==0,x]

    Out[10]= {{x->-4.75246-2.4358 I},{x->-4.75246+2.4358 I},{x->-0.964328},{x->0.}}

    In[11]:= g1=.748;g2=.352;g3=.328;g4=.900; Solve[(1+g1*x)*(1+g2*x)*(1+g3*x)*(1+g4*x)-(x+1)==0,x]

    Out[15]= {{x->-3.67529-1.94965 I},{x->-3.67529+1.94965 I},{x->-0.987116},{x->0.}}

    In[16]:= g1=.776;g2=.372;g3=.400;g4=.924; Solve[(1+g1*x)*(1+g2*x)*(1+g3*x)*(1+g4*x)-(x+1)==0,x]

    Out[20]= {{x->-3.28315-1.76573 I},{x->-3.28315+1.76573 I},{x->-0.992783},{x->0.}}

    So it appears that the Excel Solver is correct, zero is a solution for x.
    And approximately -1 is also a solution for x.
    And you have a couple of complex solutions.
  8. Mar 17, 2013 #7
    tyvm mate...
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook