Cannot declare a costum fit type using a function file

조회 수: 5 (최근 30일)
Martin Nors Pedersen
Martin Nors Pedersen 2013년 9월 27일
Hello everyone
i have some experimental data i would like to try to fit a theoretical model to. specifically, i have a data-curve(x,y) where i would like to see if i can fit a theorical datacurve.
i have made a function file which calculates the theoritcal curve and would like to use it to make a costum fit type. to do that, i have tried to follow the guidelines given here: GUIDE . The guide also uses a function file to generate a theoretical curve(piecewiseLine) and fit it to data so i believe i should be able to use it.
my situation is, however, a little bit different. My measured data is on arbitrary scale and needs to be scaled down by a multiplier. Furthermore i would like add a constant to address experimental artifacts*. so the fit-type becomes (theoretical curve)*k+c. notice that it is the multiplier and constant i want to use for fitting - i will not change the parameters for the theoretical curve (yet).
here is the code for my function file:
function P = ElipCurve(R,L)
% Function for calculating the scattering from an ellipsoid particle
% R is the semis axises, L is the length of the particle
Q = 0.001:0.001:0.5; % Qrange
funPhi = @(x1) R.*(sin(x1).^2+(L/R)^2.*cos(x1).^2).^0.5;
funTot = @(x) (3.*(sin(Q.*funPhi(x))-Q.*funPhi(x).*cos(Q.*funPhi(x)))./(Q.^3.*funPhi(x).^3)).^2.*sin(x);
P = integral(funTot,0,pi/2,'ArrayValued',true);
end
and here is the code for defining the fittype
R = 30; % Semi-axes in ångstrøm
L = 120; % length in ångstrøm
File = 1; % the specific observation you want to fit the model to
xdata = DataFiles{1,File}.data(:,1);
ydata = DataFiles{1,File}.data(:,2);
F = fittype(ElipCurve(R,L).*k+c,'independent',{'k','c'});
i get the error: Undefined function or variable 'c'.
I really don't understand the error message - i define "c" as an independent variable that can be varied to improve? can anyone suggest other methods or see any mistakes in my code?
*sounds shady i know, but i will report the constant. it is only thought of a measure of discrepancy between the perfect model and reality - if the constant is larger than the uncertainty i will not use the fit.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by