Mathematica to FindFit for multiple data set

In summary, the speaker conducted experimental work and has multiple sets of data. They want to use Mathematica to fit all sets at once using the function y=ax+b, with each set having a different value of a and b. The solution is to use the Map[] function.
  • #1
Sue Laplace
11
0
After conducting my experimental work I will have a number of sets of data.

It is easy to use Mathematica to find a fit of just one set, but I would like to fit all sets at once as they are too many to do them all ate once.
They will all be fitted by the same function say y=ax+b, every set having a different value of a and b.

How do I do this?
Thanks in advance.
Sue
 
Physics news on Phys.org
  • #2
Without a concrete specific example it is perhaps difficult to know exactly what the answer should be.

Usually if you want to "do the same thing to a collection of items" Map[] is the solution.

data1={...};
data2={...};
data3={...};
Map[FindFit[#,a x+b,{a,b},x]&,{data1,data2,data3}]

may do what you want.

http://reference.wolfram.com/mathematica/ref/Map.html
 
Last edited:
  • #3
Thank you very much Bill, it is working.
 

Related to Mathematica to FindFit for multiple data set

1. How do I use Mathematica's FindFit function for multiple data sets?

The FindFit function in Mathematica can be used for multiple data sets by simply inputting all the data sets into the function as a list, separated by commas. For example, if you have three data sets named data1, data2, and data3, the input for FindFit would be FindFit[{data1, data2, data3}, model, parameters, variables].

2. Can I use different models for each data set in FindFit?

Yes, you can use different models for each data set in FindFit. You can specify the model for each data set by using the syntax {model1, model2, model3} instead of just one model. The order of the models should correspond to the order of the data sets in the input list.

3. How can I specify initial values for the parameters in FindFit?

You can specify initial values for the parameters in FindFit by using the option "ParameterInitialConditions" and providing a list of initial values for each parameter. For example, if your model has two parameters a and b, the input would be "ParameterInitialConditions" -> {a -> 1, b -> 2}.

4. Is it possible to plot the fitted function for each data set in FindFit?

Yes, you can plot the fitted function for each data set in FindFit by using the option "ShowFit" -> True. This will plot the fitted function on top of the data points for each data set.

5. Can I use FindFit for non-linear models?

Yes, FindFit can be used for non-linear models. You can specify the model as a non-linear function, and the function will use the Levenberg-Marquardt algorithm to find the best fit for the data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
280
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Back
Top