# Variables in a Matrix unable to be called

1 view (last 30 days)
Thaddeus Rahn on 5 Nov 2020
Answered: Sibi on 14 Nov 2020
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

Sibi on 14 Nov 2020
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

### Categories

Find more on Logical 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!

Translated by