Solving Matrices with multiple variables

8 vues (au cours des 30 derniers jours)
Emma Haines
Emma Haines le 24 Juin 2021
Commenté : Walter Roberson le 24 Juin 2021
I am really struggling to work out how to solve this, can anyone help with any suggestions of how to solve this for a beginner?
I have tried to search how to solve but all the videos and tutorials I can find are solving simulatneous equations with only variables in one matrix.
I think I mostly need to know how to input variables within the matrices themselves, this should help me with solving the rest.

Réponses (1)

Walter Roberson
Walter Roberson le 24 Juin 2021
Example:
M = randn(6,6)
M = 6×6
0.0373 -1.0836 -1.1469 0.1980 0.1078 0.8221 0.5644 -0.8136 0.2201 0.2133 -0.6369 0.2241 0.9454 0.8694 1.8952 0.8920 -0.4400 0.4640 1.3960 -0.6729 -2.1750 -0.4647 0.5789 -0.9932 1.2544 -0.7392 -0.1625 0.1822 0.1910 -1.0507 -0.6796 -1.0151 -0.3467 -0.1365 -1.3496 0.4000
guesses = randn(1,6);
f = @(x) [x(1),0,1,2,x(2),x(3)].' - M*[0;x(4);x(5);x(6);0;0]
f = function_handle with value:
@(x)[x(1),0,1,2,x(2),x(3)].'-M*[0;x(4);x(5);x(6);0;0]
fsolve(f, guesses)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
ans = 1×6
2.8099 0.7598 -0.6862 0.7500 -2.2618 5.1956
  2 commentaires
Emma Haines
Emma Haines le 24 Juin 2021
Sorry to be a pain, can you explain the steps? I am very new to using MATLAB and I am still getting up to speed with all the coding phrases etc.
Walter Roberson
Walter Roberson le 24 Juin 2021
The general idea is that when you have sets of equations, you can often rewrite them as sets of zero finding.
L1(x) = R1(x)
L2(x) = R2(x)
can be rewritten as
L1(x) - R1(x) = 0
L2(x) - R2(x) = 0
then you drop the = 0 part and build a vector out of the rest,
[L1(x) - R1(x);
L2(x) - R2(x)]
and wrap it in an anonymous function
F = @(x) [L1(x) - R1(x);
L2(x) - R2(x)]
and now you have a function that you can pass to a numeric root-finder such as fsolve .
fsolve() has several algorithms. Estimates of the jacobian might be used to figure out which direction to go in.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by