Variables in a Matrix unable to be called
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I really need help. I am supposed to solve a triadagonal matrix that I populate with the code to follow. However I can use a matrix solver to solve the equation. For some reason I am unable to call the variables I assigned each matrix spot of the flux. So I can not back calculate as I had planned. If anyone could help I would greatly appreicate it.
Cheers.
clc;
clear all;
%Initial conditions
cellNum=10; %Number of cells
a = 10; %Width of slab (cm)
D =0.3733; %Diffusion coeffecient (cm)
sigA =0.0158; %Absorbption cross section (1/cm)
sigS =0.0158; %Scatt cross section (1/cm)
sigT =0.0158; %Total cross section (1/cm)
Source = 1; % source strength (neutrons/(cm3*s))
dx =a/cellNum; % Cell width
%flux matrix production and initial guess
flux = sym('a', [1 cellNum]);
%for i =1:cellNum
%flux(i)=sym('a');
%end
%Right Boundary Reflecting -[D d_flux/dx] = 0
B(1)=0;
A(1)=sigA;
%Left Boundary Condition
flux(cellNum)=0;
A(cellNum)=(2*D/dx^2+sigA);
%Middle Boundary conditions
for i=2:cellNum-1
C(i)=-D/dx^2;
B(i)=-D/dx^2;
A(i)=2*D/dx^2+sigA;
end
M = diag(A.*ones(1,cellNum)) + diag(B.*ones(1,cellNum-1),1) + diag(C.*ones(1,cellNum-1),-1);
Q = flux.*M;
Z=sum(Q,2);
for i=1:cellNum-1;
flux(cellNum-i)=solve(Z(cellNum-i)==1,flux(cellNum-i));
end
0 个评论
回答(1 个)
Sibi
2020-11-14
clc;clear all;cellNum=10;
a = 10; %Width of slab (cm)
D =0.3733; %Diffusion coeffecient (cm)
sigA =0.0158; %Absorbption cross section (1/cm)
sigS =0.0158; %Scatt cross section (1/cm)
sigT =0.0158; %Total cross section (1/cm)
Source = 1; % source strength (neutrons/(cm3*s))
dx =a/cellNum; % Cell width
flux = sym('a', [1 cellNum]);
for i =1:cellNum
flux(i)=sym('a');
end
%Right Boundary Reflecting -[D d_flux/dx] = 0
B(1)=0;
A(1)=sigA;
%Left Boundary Condition
flux(cellNum)=0;
A(cellNum)=(2*D/dx^2+sigA);
%Middle Boundary conditions
for i=2:cellNum-1
C(i)=-D/dx^2;
B(i)=-D/dx^2;
A(i)=2*D/dx^2+sigA;
end
M = diag(A.*ones(1,cellNum)) + diag(B.*ones(1,cellNum-1),1) + diag(C.*ones(1,cellNum-1),-1);
Q = flux.*M;
Z=sum(Q,2);
for i=1:cellNum-1;
flux(cellNum-i)=solve(Z(cellNum-i)==1,flux(cellNum-i));
end
flux(1:end)
round(flux,4)
what do you mean you cant call the values in matrix? i think its working.
if you have an inital flux and dont want to change your inital flux, then you just need to change last few lines as
for i=1:cellNum-1;
fluxnew(cellNum-i)=solve(Z(cellNum-i)==1,flux(cellNum-i));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!