How to input this finite element analysis matrix in matlab?
Show older comments
hi there, I have no idea how to input this matrix in Matlab. This matrix is derived from a finite element analysis problem. It is a ne*ne matrix where ne represents the number of element. A is a vector, it is a function of x, and x is a vector of ne elements.

thanks in advance!
Answers (1)
Andrei Bobrov
on 4 Jun 2017
Edited: Andrei Bobrov
on 5 Jun 2017
example:
create of A vector
ne = 7;
L = 0.5;
dx = L/ne;
x = (dx:dx:L)';
A = pi* (0.03-0.017455*L+0.017455*x).^2;
one way
out = full(spdiags([[-A(2:end);0],conv2(A,[1;1],'same'),[0;-A(2:end)]],-1:1,ne,ne));
other way
out = zeros(ne);
out(1:ne+1:end) = conv2(A,[1;1],'same');
out(2:ne+1:end-1) = -A(2:end);
out(ne+1:ne+1:end) = -A(2:end);
more
out = full(gallery('tridiag',-A(2:end),conv2(A,[1;1],'same'),-A(2:end)));
1 Comment
Andrei Bobrov
on 5 Jun 2017
I'm corrected.
Categories
Find more on Mathematics 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!