Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran And MatLab

Status
Not open for further replies.

jecstir2112

Instructor
Mar 25, 2010
3
US
Hey, so basically i need to be able to enter the dimensions of a matrix (nxn), take the inverse and, multiply it by another 1xn. I have written a Matlab equiv for this.

clc
Clear all
%% input variables
n = input('Input the number of nodes (n)')
W = input('Input the length of the slab(W)')

Sig_tr = 0.0362;
Sig_a = 0.1532;
vSig_f = 0.1570;
Rel_abs = 1;
S_o = 10^8;

Lambda_tr = 1/Sig_tr ;
D = Lambda_tr/3;
L = (D/Sig_a)^.5;


dx = W / (n-1);

k = S_o*L/(2*D);

%% matrix formation
%Slab Reactor
A = zeros(n,n);
B = zeros(n,1);

Y = zeros(n,n);
Z = zeros(n,1);

%matrix Parameter Values
Y(1,1) = ((D/dx)+(Sig_a*dx/2));
Y(1,2) = -D/dx;
Z(1,1) = S_o/2;

for icount = 2:n-1
Y(icount,icount) = (2*D)/dx+Sig_a*dx;
Y(icount,icount+1) = -D/dx;
Y(icount,icount-1) = -D/dx;
Z(icount,1) = 0;
end;

A= Y(1:n-1 , 1:n-1);
B = Z(1:n-1);


AAA = inv(A)*B;

% print this output
AAA(n) = 0
 
You'll probably find that Fortran doesn't have built in matrix inversion. You can get the source for matrix inversion from sites like
Fortran has a few matrix operations like assignment, addition, subtraction, dot products. I don't know whether the multiplication is matrix multiplication or element by element.

It is difficult to tell from the code, what is an array and what is not. Also difficult to tell what is an integer and what isn't. Can guess at some of them but not all of them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top