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

  • Context: MATLAB 
  • Thread starter Thread starter zener
  • Start date Start date
  • Tags Tags
    Excel Matlab
Click For Summary

Discussion Overview

The discussion revolves around using values from an Excel sheet as variables in a MATLAB equation to solve for x. Participants explore methods for importing data from Excel, solving the equation, and exporting results back to Excel. The equation in question is non-linear, which raises questions about the applicability of different solving methods.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks assistance on how to use Excel values as variables in a MATLAB equation to find x.
  • Another participant suggests using Excel's Solver to find the solution, outlining a method to set up the equation in Excel.
  • A later reply challenges the effectiveness of Excel's Solver for this non-linear equation, suggesting it may not yield accurate results.
  • One participant shares their experience using Excel's Solver, reporting that it consistently finds solutions for different random sets of g values, often converging to x = -1.
  • Another participant tests the equation using Mathematica, finding multiple solutions including complex numbers and confirming that zero is a solution for x.
  • Participants express uncertainty about the reliability of the Solver method and the implications of different g values on the solutions.

Areas of Agreement / Disagreement

There is no consensus on the best method to solve the equation. While some participants find success with Excel's Solver, others question its validity for non-linear equations. Multiple competing views on the reliability of different approaches remain unresolved.

Contextual Notes

Participants note that the equation is non-linear and that the number of g values may vary, which could affect the solving process. There are also concerns about the limitations of Excel's Solver in handling such equations.

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...
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K