User Specifying a Fit Function in a Separate File

In summary, the conversation discusses using a Matlab fitting program to determine constants in a function with two independent variables and three undetermined constants. The speaker has tried to call their function in a separate file but has encountered an error message. They have also attempted to specify that both x and y are independent variables, but have not been successful.
  • #1
teroenza
195
5
I have five data points (x,y,z), with two independent variables (x,y), and have written a function in a separate file z = f(x,y,A,B,C), with three undetermined constants (A,B,C).

How can I use a Matlab fitting program to try and determine the constants? I've written a fit function before where I included a string as the user-spesified fitting function, but am not sure how to tell it to call my function in a separate file.
 
Physics news on Phys.org
  • #2
I have tried, for example:

Code:
x               = [11/2 11/2 11/2 13/2 13/2]'; % F
y               = [9/2 11/2 13/2 11/2 13/2]'; % Fprime
z               = [0.117 0.114 0.110 0.156 0.151]';

ft = fittype('HyperfineShiftFunction( [x, y], Aprime, Bprime, offset )');
f  = fit( [x, y], z, ft )

Where HyperfineShiftFunction is the separate function file. Matlab complains that "The name y cannot be used for both a coefficient and the dependent variable.". I've tried looking into how to tell it that both x and y are independent, but have not succeeded.
 

What is a fit function?

A fit function is a mathematical function used to describe the relationship between a set of input variables and a corresponding set of output variables. It is typically used in scientific and statistical analyses to model and analyze data.

Why would a user want to specify a fit function in a separate file?

Specifying a fit function in a separate file allows for easier organization and management of code. It also allows for the fit function to be easily reused in multiple analyses or experiments.

How does a user specify a fit function in a separate file?

A user can specify a fit function in a separate file by defining the function in a separate file and then importing it into the main code or analysis. The function can then be called and used as needed.

What are the benefits of using a separate file for a fit function?

Using a separate file for a fit function allows for better code organization, easier maintenance and debugging, and increased code reusability. It also helps to avoid cluttering the main code with large and complex functions.

Can a fit function be shared among different users?

Yes, a fit function can be shared among different users as long as they have access to the separate file containing the function. This can be useful for collaborations and sharing of code among researchers and scientists.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • Calculus and Beyond Homework Help
Replies
6
Views
651
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • General Math
Replies
2
Views
730
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top