How can I solve a system of linear equations in Excel? - excel

I have a system of 22 linear equations (exactly 22 equations and 22 unknowns) which are dynamically generated in an Excel spreadsheet. Is there a way to have Excel solve the system and produce a value for each of the unknown variables?
Another SO question has a lot of good information about the algorithms used to solve such equations. Cramer's rule in particular looks promising, but I'm not sure how to implement it in Excel.
Any help is appreciated!

This page gives the following simple method:
Enter the coefficient matrix in an nxn
range.
Enter in the vector of
constants in a n-tall column. Select a
blank n-tall column. It is important
that you not have only one cell
selected.
Type,
=MMULT(MINVERSE(coefficients_matrix_range),
constants_vector_range) in the formula
text box and press
[CTRL][SHIFT][ENTER]. It is important
that you not simply press [ENTER].
This should work adequately, since you only have a small system (22x22). While, ideally, you wouldn't invert the matrix directly, it shouldn't matter in this case.
You definitely don't want Cramer's rule. Due to its fairly poor numerical properties, it's more of theoretical than practical interest.

The Excel LINEST function should do it - and will return better results than MMULT(MINVERSE(...)...) in many cases.
You might also find the LOGEST, GROWTH and TREND functions useful.

What about Microsoft's Solver Foundation? I seem to remember there's some example for a smaller set of simultaneous equations in the documentation that comes with the express version.

You should not ever consider Cramer's rule to solve a linear system! It is so inefficient it is impossible to carry out for even small systems.
Excel is not the right tool to solve a linear system. If I were you I'd write a simple python script that reads the excel file, solve the equation (with numpy) and save the result in a file that excel can read. (even better, avoid Excel altogether if you can).

If you have any problems with in the inverse matrix calc, e.g. over / under flow / truncation etc, you could always use the Solver - else get a copy of numerical recipes in C and translate into VBA.

that can be linear equation solver we can do with mathematical solver by using maths equation of root lies between two more number of exponent part of the solver but find the better way of linear equation solver.

Related

Excel Interpolate with logarithmic prediction

Is there a function within Excel to Interpolate while taking into account a logarithmic prediction?
At the moment I am using linear interpolation but would like to find a better way to fill in the blanks if possible.
There's no logarithmic regression or interpolation in Excel, even in the Anlaysis ToolPak. You'll need much more advanced software for that, such as MatLab.
If you're stuck working in Excel... here's a possible mathematical solution:
Rather than working with the raw data x and y, instead try plotting x and a^y, where a is the base. (Or plotting log(x,a) against y.) If you have the correct base a (and there's no vertical offset), you will then have a linear relationship from which you can perform a linear interpolation as normal, then convert the interpolated values back to actual values by taking the log of them.
If you don't know what a is, then you can instead calculate a line of best fit for an arbitrary a, calculate the standard residuals, and then use Problem Solver to modify a until you get the lowest possible standard residuals, at which point you have the best estimate of a.
Similarly if there is a vertical offset b, you'll need to test some variables there that also result in a linear relationship. Plot x against a^(y-b)

VBA EXCEL Fitting Curve with freely chosen function

As start situation, I have an xy-chart with some values on it whose progression resemble an exponential function. I need to write a code that draws a fitting curve on the chart, but I have to use a particular function which is not exponential (because I need to get some coefficients from it).
One of the functions i need to use is K(C-x)²/(1+x) whereby k and C are the parameters I need.(They are two and it makes it a lot more complicated) Obviously you can't find this kind of structure on the fitting curve tool in Excel. Is there any possibility to have a fitting curve to a chart where you can write yourself the structure of the function?
Sorry if I don't add any written code, but i just need a hint to start writing.
Thank you
I did something to similar to this a while ago. The approach I took was to use the solver (as gary's student suggests). I think it was fired from VBA but that's unimportant.
Basically you'd have two input cells per row of data with your variables K and C. Then you need to find the difference (errors) between the values the function produces with the values in the input cells compared to the actual values (I think using errors^2 gives quicker conversion). You then sum the differences in another cell. When running the solver, you ask it to minimise the sum of differences by changing K and C.
Does that makes sense...?

Microsoft Excel. Piece-wise Least-Squares Fit with Solver. My excel sheet produces right answers sometimes, wrong answers other times

I am trying to do a non-linear regression with data I have for my research. Since it is nonlinear, I can't use Simplex LP. Instead I was doing GRG Nonlinear with upper and lower bounds on all parameters.
It is weird because Excel produces answers that are right sometimes, and other times it is wrong. I have to manually change the parameters to arbitrary numbers, run Solver again, and hope that it is right. Let me show you my excel sheet.
https://drive.google.com/a/case.edu/file/d/0Bw0aJV0lW2eTaHFRUFhobVZ4NWs/edit?usp=sharing
Basically, I am looking to two linear lines to fit the data I have. The raw data can be divided into two portions, both linear. The point which the two lines cross is the Critical Value.
The correct output with my raw data is where the Critical Value = 0.006707. The last time I ran it, which is on the excel sheet, you can see that Critical Value = 3.36E-06.
If it would help you to understand this better in context, I am measuring surface tension of various systems. The critical value is so called Critical Micelle Concentration in my field.
Thanks Guys.
If you are using Excel solver, I think it is falling in local optima. Restarting the solver after setting the different variables to random values may help getting out of local optima values. Before restarting the solver, record the values of the objective function and compare it with the new value found by the solver.
Alternatively, use a better solver outside Excel. There are plenty of open source solvers available on the Internet.

Direct Power Regression in Excel

I want to obtain the R^2 values for several pairs of X v/s Y data.
It can be easily done in Matlab.
But in excel, I believe one needs to create new columns with logarithmic values or something.
Is there a direct, neat, formulas-based, Matlab-esque way to do this in Excel?
Matalb is the next generation of Excel ;) So definitely Excel is dull compared to Matalb. But dont' get demotivated, coz it's still a matrix based (Row,Col) arena...
Here is a function to try out:
RSQ function.
RSQ(known_y's,known_x's)
References for different ways:
calculate R-square in Excel
Edit:
If you need the logarithmic then you may have to use the following:
=RSQ(y-range,LN(x-range))

Interpolate off a standard curve in Excel

Most simple thing to do on paper, but somehow near impossible to work out in Excel.
I need to interpolate off a standard curve in Excel.
I have a standard curve and need to find an unknown concentration of a known absorbance.
Just like this;
http://class.fst.ohio-state.edu/fst601/Lectures/spectt/Image161.gif
My lecturer would not give us any more hints than to either use the, linear regression equation (which i think i worked out but couldn't get it to calculate the concentration) or use the point finding/picking option (no idea what this could mean)
If anyone could help me out with this I would really appreciate it, and so would my whole class!
In excel, you can do it two ways:
Method 1: Use a standard interpolation/extrapolation formula. (Bingle)
Method 2: Plot any existing data points that you have as an x-y(scatter) plot. Right-click on the data line in the chart and choose 'Add trendline'. Excel will calculate a best-fit line for your data (using linear regression) and display the line over the top of your existing data. If you right-click on this trendline, you can adjust its settings and display properties of it, including the equation used to draw it. Once you have that equation, you can plug in any value of x and get the corresponding value of y.

Resources