MATLAB Using Excel Sheet Values as Variables in MATLAB: How Can I Solve for X?

  • Thread starter Thread starter zener
  • Start date Start date
  • Tags Tags
    Excel Matlab
AI Thread Summary
To use Excel values as variables in MATLAB for solving the equation (x+1)=(1+g1*x)*(1+g2*x)*(1+g3*x)*(1+g4*x)*(1+g5*x), the Excel Solver can be utilized effectively. Users should set x in one cell and the g coefficients in a row or column, creating equations for each term in the product. The target can be defined as the difference between (x+1) and the product of the equations, allowing the Solver to adjust x until the target equals zero. Some users have confirmed that the Solver can find solutions, including x=0 and approximately -1, while also yielding complex solutions. This method provides a practical approach for integrating Excel data with MATLAB calculations.
zener
Messages
4
Reaction score
0
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)


solve('(x+1)=(1+g1*x)*(1+g2*x)*(1+g3*x)*(1+g4*x)*(1+g5*x)')
 
Physics news on Phys.org
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.
 
Bill Simpson said:
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.

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
 
A1 is my x, Initially I had that set to zero but the Solver changes that to the solution.
-0.999998474

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)
0.000459223
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:
Here is my Data...
 

Attachments

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.
 
tyvm mate...
 
Back
Top