Ax = 0 with 2 values of x known
Afficher commentaires plus anciens
I have a matrix in the form Ax = 0, and for x I know the first and last position. How can I solve this system?
Réponse acceptée
Plus de réponses (3)
Torsten
le 31 Mar 2022
Use lsqlin for the problem
min : ||A*x||_2
s.c.
x(1) = known_value_1
x(n) = known_value_2
if A has n columns.
b=-A(:,[1,end])*[xInitial;xFinal];
x=A(:,2:end-1)\b;
x=[xInitial, x', xFinal]';
2 commentaires
b = -(xInitial*A(:,1) + xFinal*A(:,end));
x = A(:,2:end-1)) \ b;
x = [xInitial ; x ; xFinal];
Matt J
le 2 Avr 2022
Right.
Fabio Freschi
le 16 Mai 2022
The post is old but the question arises many times, so I post here my solution. It is a generalization of @Matt J solution.
Suppose you have a matrix with unknowns partitioned in free x and dirichlet
. And by chance the partition is such that the free variables come first
The free unknowns can be obtained by solving the first block row:
The second block row is of no interest, since
is known.
In the general case when
are not at the end of the unknown vector, but they are identified by the index vector idFix and the corresponding Dirichlet values xFix, you can write the function
function x = solveproblem(A,b,idFix,xFix)
% get number of unknowns
n = length(b);
% move to rhs the Dirichlet values
b = b-A(:,idfix)*xfix;
% get indices of free variables
iFree = setdiff(1:n,idFix);
% reduce stiffness and rhs
A = A(:,iFree);
A = A(iFree,:);
b = b(iFree,:);
% solution
xRed = A\b;
% re-assemble the unknown vector
x(idFree) = xRed;
x(idFix) = xFix;
end
This method preserves the original properties of the original matrix (in particular if it's SPD). There is also an interesting way to include in this approach that a selection of the vector of unknowns has the same value, for example a floating potential of an equipotential object, but it goes beyond the original question
Catégories
En savoir plus sur Structural Mechanics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
