MATLAB Fitting a Curve to Data: MATLAB vs Excel

AI Thread Summary
To fit the curve defined by the equation y=20-a*10*log(x), MATLAB offers several functions, particularly from the Optimization toolbox, which allows for custom equations and nonlinear fitting. Users can also rewrite equations as matrix equations for direct solutions using least squares. Excel provides a more intuitive interface for curve fitting through its plot window, where users can select fitting tools after plotting data points. Both platforms support custom equations, but MATLAB offers more flexibility with complex functions and data handling. For MATLAB users, the Ezyfit toolbox can simplify the fitting process with specific commands for the given equation.
ACLerok
Messages
194
Reaction score
0
I have a set of data and I need to fit a curve to it. The equation of the curve is:
y=20-a*10*log(x)
My problem is just getting a curve fit to this equation. What function in MATLAB should I be looking for? How do I get the value of 'a'?

Is it easier to achieve this in Excel? How?
 
Physics news on Phys.org
Plot it, and then look in the menus in the plot window for a fitting tool.

All of the functions available in that menu are also available on the command line, but I find curve fitting to be much more intuitive when done in a plot window.

- Warren
 
will i be able to enter in my own custom equation? thanks
 
In excel if you have all the points plotted out, it will curve fit the points to whatever order of polynomial you want.

In Matlab I am sure you can enter your custom equations.
 
ACLerok said:
will i be able to enter in my own custom equation? thanks

Yes, you can fit to whatever function you want.
Note that if you use functions from the Optimization toolbox (if you have that installed) you can quite easily fit to a nonlinear Matlab function, i.e. you can "fit" to a piece of code which generates an output that depends on an number of inputs, even if the function includes e.g. interpolation (which is often used conventient when fitting to a large set of experimental data), if-then statements etc. This is often very useful.

Also, if you are able to rewrite your equations as a matrix equation (e.g. a sum of exponentials with unknown prefactors) you can of course also solve it directly, i.e. using something like "X\b" which gives you the best result in the least-square sense.
 
Fit in matlab

You can also try Ezyfit, a free curve fitting toolbox for Matlab:
www.fast.u-psud.fr/ezyfit
In your case just type
showfit('y=20-a*10*log(x)')
if your data are plotted in a figure, or
f = ezfit(x,y,'y=20-a*10*log(x)')
if your data are stored into the vectors x,y.
 

Similar threads

Replies
2
Views
3K
Replies
2
Views
1K
Replies
6
Views
5K
Replies
2
Views
3K
Replies
4
Views
2K
Replies
5
Views
3K
Replies
12
Views
4K
Replies
5
Views
2K
Back
Top