How do I use a function containing symsum with lsqcurvefit?
3 views (last 30 days)
Show older comments
I have the following code, which is to fit a function to some data:
time=[10,15,17,25,30,34,40,43,51,55,68,70,84,104]; fraction=[1/18,2/18,6/18,7/17,8/18,10/18,11/18,12/18,13/18,14/18,15/18,16/18,17/18,18/18];
P0=[0.02 7]; syms k;
F=@(Q,xdata)1-symsum(((Q(1).*(xdata-Q(2))).^k.*exp(-Q(1)*(xdata-Q(2))))/factorial(k),k,0,4);
[Q,resnorm,~,exitflag,output]=lsqcurvefit(F,P0,time,fraction);
However, I get the following error: Error using lsqcurvefit (line 244) LSQCURVEFIT requires all values returned by user functions to be of data type double.
I think this is because class(F(P0,time))=sym, whereas lsqcurvefit requires it to be double.
Is there anyway to get around this?
Thanks, Caroline
0 Comments
Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!