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

In summary, the Excel Solver can solve an equation for x that is not linear, by finding a solution over and over for different sets of RAND values.
  • #1
zener
4
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
  • #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.
 
  • #3
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
 
  • #4
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:
  • #5
Here is my Data...
 

Attachments

  • Lambda.xls
    21 KB · Views: 234
  • #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.
 
  • #7
tyvm mate...
 

1. What is the difference between Matlab and Excel?

Matlab is a high-level programming language and interactive environment used for scientific computing, while Excel is a spreadsheet program used for organizing and analyzing data. Matlab is more suitable for complex mathematical calculations and data analysis, while Excel is better for basic data manipulation and visualization.

2. Can I import data from an Excel sheet into Matlab?

Yes, you can easily import data from an Excel sheet into Matlab by using the "xlsread" function. This allows you to access and use the data in your Excel sheet for further analysis or calculations in Matlab.

3. How can I export data from Matlab to an Excel sheet?

To export data from Matlab to an Excel sheet, you can use the "xlswrite" function. This allows you to save your results or data from Matlab into an Excel sheet, which can then be easily accessed and manipulated in Excel.

4. Is it possible to perform statistical analysis in Matlab?

Yes, Matlab has a variety of built-in functions and toolboxes that allow you to perform statistical analysis on your data. You can calculate descriptive statistics, perform hypothesis testing, and even create visualizations of your data using these functions.

5. Can I use Matlab and Excel together in my research or project?

Absolutely! In fact, using both Matlab and Excel together can be very beneficial in your research or project. You can use Excel to organize and manipulate your data, and then import it into Matlab for more complex analysis and calculations. You can also export your results from Matlab back to Excel for further visualization or sharing with others.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
950
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Other Physics Topics
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
Back
Top