From: Corey Smith on 27 Nov 2009 12:21 Hi: I am have a set of raw data of signal intensity along a distance, r and am trying to fit a specified equation to this data by manipulating the factor D, while keeping the rest constant. I am having trouble coming up with the code and keep getting an error saying "Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue." Below is what I have so far. Thanks in advance! function F = myfun(Co,a,r,D,t) I = linspace(200,6800); r = linspace(1,6); Co = 6895; t = 480; a = 1.92; D = 4E-4; %output = inline('((1/2).*(Co).*(erf((a-r)./(2.*(sqrt(D.*t))))+(erf((a+r)./(2.*(sqrt(D.*t)))))))-((Co./r).*(sqrt((D.*t)./pi)).*((exp((-((a-r).^2))./(4.*D.*t))-(exp((-((a+r).^2))./(4.*D.*t))))))','Co','a','r','D','t'); F = ((1/2).*(Co).*(erf((a-r)./(2.*(sqrt(D.*t))))+(erf((a+r)./(2.*(sqrt(D.*t)))))))-((Co./r).*(sqrt((D.*t)./pi)).*((exp((-((a-r).^2))./(4.*D.*t))-(exp((-((a+r).^2))./(4.*D.*t)))))); [D,resnorm]=lsqcurvefit('myfun',Co,a,r,D,t,I);
From: Godzilla on 27 Nov 2009 20:22 "Corey Smith" <csmit26(a)uwo.ca> wrote in message <hep1q0$c8u$1(a)fred.mathworks.com>... > Hi: > > I am have a set of raw data of signal intensity along a distance, r and am trying to fit a specified equation to this data by manipulating the factor D, while keeping the rest constant. I am having trouble coming up with the code and keep getting an error saying "Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue." > > Below is what I have so far. Thanks in advance! > > function F = myfun(Co,a,r,D,t) > > I = linspace(200,6800); > r = linspace(1,6); > Co = 6895; > t = 480; > a = 1.92; > D = 4E-4; > > %output = inline('((1/2).*(Co).*(erf((a-r)./(2.*(sqrt(D.*t))))+(erf((a+r)./(2.*(sqrt(D.*t)))))))-((Co./r).*(sqrt((D.*t)./pi)).*((exp((-((a-r).^2))./(4.*D.*t))-(exp((-((a+r).^2))./(4.*D.*t))))))','Co','a','r','D','t'); > F = ((1/2).*(Co).*(erf((a-r)./(2.*(sqrt(D.*t))))+(erf((a+r)./(2.*(sqrt(D.*t)))))))-((Co./r).*(sqrt((D.*t)./pi)).*((exp((-((a-r).^2))./(4.*D.*t))-(exp((-((a+r).^2))./(4.*D.*t)))))); > > [D,resnorm]=lsqcurvefit('myfun',Co,a,r,D,t,I); I believe the fitting program expects 'myfun' in a certain format (i.e. input and output). Check your myfun.
From: Corey on 4 Dec 2009 14:38 > I believe the fitting program expects 'myfun' in a certain format (i.e. input and output). Check your myfun. Thanks for your response. I have played with it more and gotten a bit closer, but the problem I am having now is that F wants me to define D when I run this code, but it should be finding D for me. Where am I going wrong now? function F = myfun(D,r) I = load('33323_MiddleTray4_xplot.txt'); x=I(:,1); y=I(:,2); r = x; I = y; Co = 6895; t = 480; a = 1.92; D0 = 4E-4; F = ((1/2).*(Co).*(erf((a-r)./(2.*(sqrt(D(1).*t))))+(erf((a+r)./(2.*(sqrt(D(1).*t)))))))-((Co./r).*(sqrt((D(1).*t)./pi)).*((exp((-((a-r).^2))./(4.*D(1).*t))-(exp((-((a+r).^2))./(4.*D(1).*t)))))); D = lsqcurvefit('myfun',D0,r,I);
From: Corey on 4 Dec 2009 15:09 I apologize, I have just made a great stride forward and it appears to be working the way I want it to. Now just to make it work so that it returns R^2 with D.
|
Pages: 1 Prev: plotting multiple functions in same axis, 2D. Next: quadl error |