Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB User Specifying a Fit Function in a Separate File

  1. May 30, 2017 #1
    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.
  2. jcsd
  3. May 31, 2017 #2
    I have tried, for example:

    Code (Text):

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted