User Specifying a Fit Function in a Separate File

  • Context: MATLAB 
  • Thread starter Thread starter teroenza
  • Start date Start date
  • Tags Tags
    File Fit Function
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 2K views
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.
 
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.