I'm trying to solve a problem in Matlab using FDE (Finite Difference method) which involves system of equations.
So I have
[A]{T}={C} -> [A]^(-1){C}={T}
I "know" all the values for [A] and {C}. As the matrix is mostly zeros I'm using sparse matrix.
But Matlab is giving me a warning while filling known values to the matrix.
This sparse indexing expression is likely to be slow.
Here is an example:
clear;clc;
% Number of nodes.
nodes = 5000;
% My
A = sparse(nodes,nodes); % Known parameters.
C = sparse(nodes,1); % Known parameters.
T = sparse(nodes,1); % Trying to find.
% Solving equation: [A]{T}={C} -> [A]^(-1){C}={T}
% I'm trying to fill my known values to [A]
% I have 40+ 'sections' with different values. For this example I use one
% section with all values equals to 1.
Section1 = [1, 30, 50, 60, 100, 430, 4500]; % Nodes in section 1.
% Random numbers for the example. (I generate them for each node.)
q = 10;
w = 400;
e = 1000;
r = 3500;
for i = 1:nodes
if any(Section1(:)==i)
A(i,q) = 1; % Error on this line
A(i,w) = 1; % Error on this line
A(i,e) = 1; % Error on this line
A(i,r) = 1; % Error on this line
end
end
T=A\C. Thats your solution. It's calledmldivideand does A LOT of things. And remember jut in case: NEVER EVER INVERT A MATRIX - Ander BiguriA(Section1,q) = 1and same for other three cases and avoid the loop? - Divakar