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 Commenti

Are number of uknowns and number of equations equal?
Yes they are equal
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.

Accedi per commentare.

Risposte (2)

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 il 11 Apr 2020
Modificato: Ameer Hamza il 11 Apr 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.

Richiesto:

il 11 Apr 2020

Risposto:

il 11 Apr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by