Trying to fit equation with sqlcurvefit to integral function

Hello,
I have been trying for the past 4 hours to fit the following equation:
I have the values of R(phi,n), the value of alpha and an initial estimate for R(0). What I would like to find is the fitted values (using a least square method) of R(0) and n. In order to achieve this, I tried using the sqlcurvefit function with the following code:
fun= @(x,xdata) x(1)*integral(@(y) (cos(y).^(x(2))),xdata-0.5410,xdata+0.5410,'ArrayValued',true);
x0=[6.5, 1.5];
x= sqlcurvefit(fun, x0, xdata,ydata);
xdata is a vector containing the radian values of phi and ydata is the recorded values of R(phi,n).
The errors that I get are: Error using integral (line 85) A and B must be floating-point scalars.
Error in @(x,xdata)x(1)*integral(@(y)(cos(y).^(x(2))),xdata-0.5410,xdata+0.5410,'ArrayValued',true)
Error in lsqcurvefit (line 199) initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.
I have been trying all sorts of alternatives from other posts but none of them seemed to work. Does somebody have a suggestion about how should I modify the code?
Kind regards,
A

Answers (1)

1. The limits of integration for MATLAB's "integral" are not allowed to be arrays.
2. cos(x)^n can not be evaluated if cos(x)<0 and n is not an integer.
Best wishes
Torsten.

Categories

Asked:

A A
on 27 Oct 2016

Answered:

on 28 Oct 2016

Community Treasure Hunt

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

Start Hunting!