Trouble using lsqcurvefit function to determine 2 unknowns
Show older comments
Keep recieving errors when we try and use the lsqcurvefit function to estimate heat transfer coefficent and thermal conductivity. T is tempature and xt is Time and location. h and k are inital guesses. First function works fine but having errors with second function. Any help would be greatly apreciated.
clear all
close all
clc
%calling data from txt file
tab = importdata('data4.txt');
Time0 = tab (:,1); %time
Time1 = [Time0 Time0 Time0 Time0 Time0 Time0];
Time = Time1(:);
TCB = tab(:,2); %Thermo Base
TC1 = tab(:,3); %Thermo 1
TC2 = tab(:,4); %Thermo 2
TC3 = tab(:,5); %Thermo 3
TC4 = tab(:,6); %Thermo 4
TC5 = tab(:,7); %Thermo 5
t = [TCB TC1 TC2 TC3 TC4 TC5];
T = t(:);
U = tab(:,8); %PID Gain
x0 = tab(:,9); %Distance
x1 = tab(:,10); %Distance
x2 = tab(:,11); %Distance
x3 = tab(:,12); %Distance
x4 = tab(:,13); %Distance
x5 = tab(:,14); %Distance
j = [x0 x1 x2 x3 x4 x5];
X = j(:);
xt = [X,Time];
% Knowns/IGuesses
T_amb = 26; % ambient Temperature in Celcius
T_base = 75; % set temperature of the heating element/base
rho = 7860; % density
d = 0.003175; % diameter
c = 500; % specific heat J/kg*Celcius
s = pi*d; % permimeter in meters
A = pi*d^2/4; % cross sectional area in meters squared
h = 132.918; % heating coefficient Guessed
k = 14; % thermal conductivity Guessed
L = 0.2032; % length of rod being used (to last thermcouple) in meters
alpha_guess = .04;
fun = @(y)((y(1)).*(1-exp(-y(2).*Time0)))-TCB
guess = [T_base,alpha_guess];
options.Algorithm = 'levenberg-marquardt';
y = lsqnonlin(fun, guess, [], [], options)
alpha = y(2);
T0 = y(1); %Tbase - Tamb
syms n
kappa = @(x,xt)x(2)/(rho*c);
v = @(x,xt)(x(1)*s)/(rho*A*c);
Bn = @(x,xt)((2*n-1)*pi*sqrt(kappa(x,xt)))/(2*L);
a = @(x,xt)((4*T0)/((2*n-1)*pi));
b = @(x,xt)(v(x,xt)/(v(x,xt)+(Bn(x,xt)^2)));
c = @(x,xt)(1-exp(-((Bn(x,xt)^2)+v(x,xt))*xt(:,2)));
d = @(x,xt)((v(x,xt)-alpha)/(v(x,xt)-alpha+(Bn(x,xt)^2)));
e = @(x,xt)(exp(-alpha*xt(:,2))-exp(-((Bn(x,xt)^2)+v(x,xt))*xt(:,2)));
f = @(x,xt)(sin((Bn(x,xt)*xt(:,1))/sqrt(kappa(x,xt))));
gx = @(x,xt)(a(x,xt)*(b(x,xt)*c(x,xt)-d(x,xt)*e(x,xt)).*f(x,xt));
fun1 = @(x,xt)(T0*(1-exp(-alpha*xt(:,2)))-symsum(gx(x,xt)));
guess1 = [h,k];
options.Algorithm = 'levenberg-marquardt';
lsqcurvefit(fun1,guess1,xt,T)
Heat_transfer_coefficient = x(1)
Thermal_conductivity_coefficient = x(2)
Error using sym/symsum (line 81)
Error using maplemex
Error, (in factor) floating point coefficients are incompatible with field extension; use 'real' or 'complex' instead
Error in Frank>@(x,xt)(T0*(1-exp(-alpha*xt(:,2)))-symsum(gx(x,xt)))
Error in lsqcurvefit (line 213)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in Frank (line 70)
lsqcurvefit(fun1,guess1,xt,T)
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
Answers (0)
Categories
Find more on Numeric Solvers 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!