MATLAB User Specifying a Fit Function in a Separate File

AI Thread Summary
To determine constants A, B, and C using a fitting program in MATLAB with a user-defined function in a separate file, the user needs to correctly specify the fit type and ensure that the independent variables are properly defined. The error encountered indicates a naming conflict where 'y' is being interpreted as both a coefficient and a dependent variable. To resolve this, the user should rename the coefficients in the function definition to avoid overlap with the independent variable names. Additionally, the correct syntax for calling the function from a separate file must be adhered to, ensuring that the fitting function is properly recognized by MATLAB. Properly addressing these issues will allow for successful fitting of the data points.
teroenza
Messages
190
Reaction score
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
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.
 

Similar threads

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