Re: Solving Polynomial equation

*To*: mathgroup at smc.vnet.net*Subject*: [mg100979] Re: Solving Polynomial equation*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Fri, 19 Jun 2009 20:45:13 -0400 (EDT)

On 6/18/09 at 4:50 AM, leekosal at yahoo.com (kosal lee) wrote: >I need help and I am new to Mathematica. >Suppose I want to solve for the equation: aX^2 + bx +c ==0, however >I have a list of parameters a and b in my microsoft excel where a >and b are columns and its value are in rows. >I dont want to key every a and b each time to find the root of above >equation. >Are there anyway to tell Mathematica to import each a and b value >from excel, put it in the above equation, and find its root and it >export the list of results back to excel? Yes. First. to move the data from Excel to Mathematica use Import. That is, doing data = Import[filename, "XLS"]; will read the data from filename. Now assuming there is only one sheet in the workbook and it only has the three columns described above with numeric data, the Mathematica variable data will be a n X 3 array of numbers. I will also assume a, b and c are in columns 1,2 and 3 respectively. Given those assumptions, roots of the quadratic equations can be found by doing sol={x/.First[#],x/.Last[#]}&@NSolve[#==0,x]&/@(data.{x^2,x,1}) Note, I've used NSolve here since you indicated the solutions are to be sent back to Excel. Excel will not like Mathematica's exact solutions that Solve will return if the coefficients a,b and c are integers. Also, if you don't want the solutions displayed by Mathematica you should terminate the above with a semicolon. =46inally, the solutions can be returned to Excel using Export. Doing Export["solutions.xls", sol, "XLS"] will create an Excel spreadsheet with the desired data.