im finding error in line 18

close all;
clc
Pav=30; %power of laser%
M=1670; %melting point of SS316%
De=8238*10^(-18); %Density of SS316%
cp=468; %specific heat capaityof material%
dx=2; %X direction increment%
dz=0.4; %y direction increment%
K=13.4*10^(-6) ; %thermal conductivity%
lm=300*10^3; %Latent heat of melting%
dt=10; %time increment from equation%
Du=75; %total laser pulse duartion%
f=148; %laser pulse frequemcy in kilo heartz%
D=K/De*cp; %dissusivity%
Ro=20; %laser spot radius%
for j=0:2:400 %x axis loop%
for k=0:0.4:80 %z axis loop%
T(0,j,k)=298; %initial condition% line 17
end
end
for i=1:10:75 %time loop%
T(1:10:75,0,0:0.4:80)=298; %boundry condition%
T(1:10:75,400,0:0.4:80)=298;
T(1:10:75,0,0)=298;
S=T(i,j,k);
if T(i,j,k)==M
T(i,j,k)=T(i-1,j,k)-(lm/cp); %temp check Melting point%
else
for j=1:0.2:400 %x axis loop%
for k=1:0.4:8 %y axis loop%
T(i+1,j,k)=T(i,j,k)*(1-2*dt*D/dx^2-2*dt*d/dz^2)+...
dt*D*((dz^2)*(T(i,j+1,k)+T(i,j-1,k))+(dx^2)*(T(i,j,k+1)+T(i,j,k-1)))/(dx^2)*(dz^2)+...
(dt*D)/K *AL *(Pav/(f*Du*pi*Ro^2))*exp*(-2*(j/Ro)^2-2*(i/Du)^2-(AL * K));
end
end
end
end
plot3(T(i,80/2,0:0.4:80),i,k) ;
im finding error in line 17
error
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in corsework (line 17)
T(0,j,k)=298; %initial condition%

Réponses (2)

KSSV
KSSV le 8 Jan 2022

0 votes

Note that the index of array starts from 1 in MATLAB. You have used index as 0, so error.
Also the logic you have used is not correct. This loop:
for j=0:2:400 %x axis loop%
for k=0:0.4:80 %z axis loop%
T(0,j,k)=298; %initial condition% line 17
end
end
The above has no logic. Note that.
  1. Index should be 1
  2. You are skipping the indices, so matrix will create extra zeros at places skipped.
  3. Index cannot be a fraction.
Rethink on your code and please read some basics of MATLAB.
Image Analyst
Image Analyst le 8 Jan 2022

0 votes

Perhaps instead of that loop assigning 298 to everything you simply want
% Get a list of all the j and k we want to iterate over.
allj = 0:2:400;
allk=0:0.4:80;
numj = length(allj)
numk = length(allk)
T = 298 * ones(76, numj, numk);

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Centre d'aide et File Exchange

Produits

Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by