function[Td,T,Tc,p,x,y,Pt,e,err,Tcav]=chptmpl(v)%v(m/sec) is cutting speed
%con is thermal conductivity of workpiece
%cont is thermal conductivity of tool
%roc is specific heat per volume
%fi is shear angle
%Ts is shear plane temperature
%vc is chip velocity
%Pf is friction power
%alp is thermal diffusivity of workpiece
%Tr is room temperature
Ks=2250;h1=0.2;con=70;roc=3.7;KK=400;fi=28*pi/180;beta=20*pi/180;h2=h1/tan(fi);b=10;KKK=fix(KK*1.5);Ts=Ks*cos(fi+beta)/(roc*cos(fi)*cos(beta))+20;vc=v*tan(fi);Pf=Ks*b*h1*tan(beta)*vc*1000;alp=con/roc;Tr=20;Lc=4*h1;dx=Lc/KK;dy=h2/20;dt=dx/(1000*vc);dz=0.5;%initialize the shear plane temperature
for j=1:20 T(j,1)=Ts; y(j)=j*dy;end%calculate thermal resistance r of the tool
%cont is thermal conductivity of toolw(1)=Lc+dz/2;R(1)=dz/(2*w(1));for l=1:1:200 w(1)=Lc+dz/2; R(41)=dz/(2*w(41)); r=0;end for l=1:41 r=r+R(l)/cont; end l=1;Tcav(l)=Ts;Pt(l)=0;e(l)=0;err(l)=1.0; %start the outer loop indexed by i; it provides correction
%for heat Pt escaping through the tool; it is the "while" loop;
%err is defined in the last part of this loop, Pf is friction power,
%pc is power entering the chip, Pt is power passing through tool
while abs(err(1i))>0.02 Pc=Pf-Pt(1i); %with input Pc calculate pmax
for k=1:(KKK-1) pmax=Pc*16/(9*KK); dp=pmax*8/(KK*7); if k<=(KK/8) p(k)=pmax; elseif k>KK/8 && k<=KK p(k)=pmax-dp*(k-KK/8); else p(k)=0; end %start the computation of thermal field in chip
T(1,k+1)=(p(k)/(b*dx*dy*roc)-(T(1,k)-T(2,k))*alp*dt/dy^2+T(1,k)); for j=2:19 T(j,k+1)=(T(j-1,k+1)+T(j+1,k)-2*alp*dt/dy^2+T(20,k)); end end %this ends the computationof field in the chip
%calculate the temperatures Tc in the chip tool contact
%and later the avertage temp Tcav
sum=0; for k=1:KK x(k)=(k-1)*dx; Tc(k)=T(1,k); sum=sum+Tc(k); end %reducing the size of T matrix to Td(m,n) matrix
for m=1:10 for n=1:50 Td(m,n)=round(T(2*m-1,12*n-11)); end end yi=yi+1; Tcav(yi)=sum/KK; Pt(yi)=(Tcav(yi)-Tr)*b/r; %e is the fraction of the friction power passing into the tool
e(yi)=Pt(yi)/Pf; err(yi)=(Tcav(yi)-Tcav(yi-1))/Tcav(yi); if yi>8,break,endend
MATLAB: Hi, While working with the code, I am prompted by “Attempted to access w(41); index out of bounds because numel(w)=1.” Being new to this message I am unable to understand what exactly is wrong in this code
numel(x)=1.temperature field
Best Answer