Efficient matrix inverse/solving linear equation with syms
显示 更早的评论
Hi, sorry for the bad title. I am trying to solve the following equation
as λ varies over ℝ. My current implementation seems slower than I would expect.
as λ varies over ℝ. My current implementation seems slower than I would expect.n=100;
lambda = 0:0.1:10;
syms a;
OneVector = repmat(1,n,1);
%Definitions of A and B - these don't really matter
A = diag(repmat(2,n,1)) + diag(repmat(-1,n,1),1) + diag(repmat(-1,n,1),-1) + diag(-1, -n +1) + diag(-1, n-1);
B = diag(rand(n, 1));
M = A + a*B;
%The whole process until now takes under a second for n = 100
x = linsolve(M, OneVector); %This is the long step, as it should be
y = x.^{-1}; %The actual vector I am interested in
SurfaceData = double(subs(y, a, lambda));
surf(SurfaceData);
One immediate question I had was if it is more efficient to subsitute the syms before inverting the elements of the vector or to do it after as I am currently doing. The other question is if there is a faster method for doing this computation. I realize that the linsolve uses an
algorithm and that its not reasonable to expect too much from it, but scaling it up from
to
is more than
times the processing time.
algorithm and that its not reasonable to expect too much from it, but scaling it up from
is more than 回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!