Undefined variable when performing nonlinear curve fitting
Show older comments
I have the following code:
clc,clear all,close all
filename='d5D21Re50.csv';
M=csvread(filename,1,0);
d=5e-3; % particle diameter (m)
U0=10e-3; % superficial velocity (m/s)
eps=0.47; % average porosity
Uavg=U0/eps; % average axial velocity (m/s)
C0=6; % inlet tracer concentration (mM)
cellsize=2.5e-4; % grid size (m)
nx=320; % number of cells in the x (axial) direction
ny=86; % number of cells in the y direction
nz=86; % number of cells in the z direction
L=nx*cellsize; % length of the column (m)
R=0.5*(ny-2)*cellsize; % radius of the column (m)
Ri=0.5e-3; % radius of the tracer tube (m)
flag=reshape(M(:,1),[nx,ny,nz]);
Ux=reshape(M(:,2),[nx,ny,nz]);
Uy=reshape(M(:,3),[nx,ny,nz]);
Uz=reshape(M(:,4),[nx,ny,nz]);
C=reshape(M(:,6),[nx,ny,nz]);
N=29; % number of intervals
radp=1:N;
radgrid=[0 radp];
i=20; % index for the axial position
for m=1:N
jcen=ny/2;
kcen=nz/2;
centerValue=C(i,jcen,kcen);
r1=radgrid(m);
conc=0;
counter=0;
for j=1:ny
for k=1:nz
r=sqrt((j-jcen)^2+(k-kcen)^2);
r2=radgrid(m+1);
if r>=r1 && r<=r2 && (flag(i,j,k)==0 || flag(i,j,k)==0.5)
conc=conc+C(i,j,k);
counter=counter+1;
end
end
end
radCprof(m)=conc/counter;
end
radCprof=[centerValue radCprof];
radialpos=R*radp/max(radp);
myArray=[0 radialpos];
roots=30;
z=i*cellsize;
beta=besselzero(1,roots,1);
value=0;
for i=1:roots
value=value+besselj(1,beta(i)*Ri/R)*besselj(0,beta(i)*r/R)/(beta(i)*(besselj(0,beta(i)))^2)*(z/R)*exp(-beta(i)^2*z/(PeT*R));
end
modelfun=@(PeT,r)C0*(1+(2*R/Ri)*value);
x=lsqcurvefit(modelfun,12,myArray,radCprof);
And I receive the following error when I launch it:
Undefined function or variable 'PeT'.
Error in TransverseDispersionBessel (line 70)
value=value+besselj(1,beta(i)*Ri/R)*besselj(0,beta(i)*r/R)/(beta(i)*(besselj(0,beta(i)))^2)*(z/R)*exp(-beta(i)^2*z/(PeT*R));
How could I solve this problem?
Accepted Answer
More Answers (1)
Walter Roberson
on 7 Jan 2019
Change
value=0;
for i=1:roots
value=value+besselj(1,beta(i)*Ri/R)*besselj(0,beta(i)*r/R)/(beta(i)*(besselj(0,beta(i)))^2)*(z/R)*exp(-beta(i)^2*z/(PeT*R));
end
modelfun=@(PeT,r)C0*(1+(2*R/Ri)*value);
to
value = @(PeT,r) sum( besselj(1,beta(i)*Ri/R)*besselj(0,beta(i)*r/R)/(beta(i)*(besselj(0,beta(i)))^2)*(z/R)*exp(-beta(i)^2*z/(PeT*R));
end
modelfun=@(PeT,r)C0*(1+(2*R/Ri)*value(PeT,r));
Categories
Find more on Get Started with Curve Fitting Toolbox 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!