From: John on 8 Jul 2010 14:23 Hi All, I'm trying to rewrite a program in order to make it more "free-standing" so that I only have to change a few variable declarations in order to use the program for multiple data sets, but I'm having difficulty changing these 2 lines: myfit=inline('alpha(1)*exp(-(alpha(2)/(4.5504*1590))*(t-8567))+alpha(3)','alpha','t'); alpha=nlinfit(Tsample(1,:),Tsample(2,:),myfit,[1,1,1]); In the first line of code above, 4.5504 is the mass of the oil, 1590 is the specific heat capacity of the oil, and 8567 is the time it reaches peak temperature. There are physical reasons for fitting the data to this curve. All units are SI. The variables alpha are the parameters I want the "nlinfit" function to return. I want to make this the line of code, so that I don't have to go to the above lines and change the numbers every time: myfit=inline('alpha(1)*exp(-(alpha(2)/(moil*cpoil))*(t-t3))+alpha(3)','alpha','t'); alpha=nlinfit(Tsample(1,:),Tsample(2,:),myfit,[1,1,1]); As a result, I get the errors: ??? Error using ==> nlinfit at 113 Error evaluating inline model function. Error in ==> Zinc_Template at 165 alpha=nlinfit(Tsample(1,:),Tsample(2,:),myfit,[1,1,1]); Caused by: Error using ==> inlineeval at 15 Error in inline expression ==> alpha(1)*exp(-(alpha(2)/(moil*cpoil))*(t-t3))+alpha(3) Undefined function or variable 'moil'. This makes me believe that the inline function is simply unable to recognize the variables when they're part of the expression, but I don't know how to fix it. Here's the data I'm using: (Tsample(1,:) is time(s), and Tsample(2,:) is Temperature (degrees C)). Tsample = 1.0e+004 * 0.8566 0.9646 1.0726 1.1806 1.2886 1.3966 0.0032 0.0032 0.0031 0.0031 0.0030 0.0030 moil=4.5504; cpoil=1590; t3=8567; When I run the original lines of code, I get the following results for alpha: alpha = 7.0958 0.4553 24.9364 This may just sound like I'm lazy not wanting to change these decimal numbers every time, but please keep in mind that the point of this program is to do calculations for you, and it means I'm less likely to screw it up if I only have to change any variables in one location. Thanks all, John
From: Walter Roberson on 8 Jul 2010 15:12 John wrote: > myfit=inline('alpha(1)*exp(-(alpha(2)/(moil*cpoil))*(t-t3))+alpha(3)','alpha','t'); > As a result, I get the errors: > ??? Error using ==> nlinfit at 113 > Error evaluating inline model function. > > Error in ==> Zinc_Template at 165 > alpha=nlinfit(Tsample(1,:),Tsample(2,:),myfit,[1,1,1]); > > Caused by: > Error using ==> inlineeval at 15 > Error in inline expression ==> > alpha(1)*exp(-(alpha(2)/(moil*cpoil))*(t-t3))+alpha(3) > Undefined function or variable 'moil'. > > This makes me believe that the inline function is simply unable to > recognize the variables when they're part of the expression, but I don't > know how to fix it. Don't use inline() for this purpose: use anonymous functions. Unless, that is, you happen to be running one of the old Matlab releases that fell between the time they introduced inline() and they introduced anonymous functions ?
|
Pages: 1 Prev: Errors while compiling MATLAB GUI m-file Next: Reconstruction of Band limited signal |