system of linear equations with unorganized unknowns

Hi everybody
First, I want to apologize if my question is answered already, but I couldn't find proper easy answer.
I have system of equation formed as [k]*[u]=[f] in which [k] is known and [u] and [f] have known and unknown variables. the matrix [k] is n by n and [f], [u] are n by 1 matrixes. I want to know what is the simplest way to solve this system of equation?
I am beginner in MATLAB and thanks in advance.

4 comentarios

darova
darova el 11 de Abr. de 2020
Are number of uknowns and number of equations equal?
Yes they are equal
darova
darova el 11 de Abr. de 2020
Try equationsToMatrix if the system is linear
Try fsolve if it's not
The system is linear but the problem is that the eqntomatrix command converts equations to matrix But the problem is that I don’t have the equations to convert. I have the matrix form of equations as I said before with unknowns on both sides.

Iniciar sesión para comentar.

Respuestas (2)

darova
darova el 11 de Abr. de 2020
Here you go
u = sym('u',[10 1]);
f = sym('f',[10 1]);
f([2 4 6]) = 1; % constants
u([1 3 5 7:10]) = 1; % constants
k = rand(10); % coefficinet matrix
eqns = k*u-f; % symbolic equations
vars = symvar(eqns); % get all unknown variables
[A,B] = equationsToMatrix(eqns,vars);
A = double(A);
B = double(B);
res = A\B;
str = arrayfun(@char, vars, 'uniform', 0)';
table(str,res)
Ameer Hamza
Ameer Hamza el 11 de Abr. de 2020
Editada: Ameer Hamza el 11 de Abr. de 2020
In most cases, if your matrix k is general, then the most efficient way is
u = k\f;
The above method is also recommended by MATLAB's documentation. But if matrix 'k' has some special properties such as it is a triangular matrix, then linsolve can give speed gain: https://www.mathworks.com/help/releases/R2020a/matlab/ref/linsolve.html#mw_f405bef0-76ac-4c5b-8c40-c65d1a0a331e.

Preguntada:

el 11 de Abr. de 2020

Respondida:

el 11 de Abr. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by