Effacer les filtres
Effacer les filtres

How to solve for three equations from a large array of equations?

2 vues (au cours des 30 derniers jours)
Osman Ajmal
Osman Ajmal le 2 Août 2018
I've got a large array of equations (linear and non-linear) all defined as f(x,y,z) and i would like to solve for all three variables x,y,z where the program outputs all x,y,z values that solve for any combination of three equations from the large array of equations. Is there any way to do this other than using the solve funtion within loops to iteratively go through all combinations of equations?
  4 commentaires
Aquatris
Aquatris le 3 Août 2018
Obivously you cannot have a variable that is both equal to 2 and equal to 5. So if you try to solve all of it it is gonna give you no answer.
For the second part it is gonna give you 2 solutions since x and y are interchangeable in equation 3 and 5. So essentially you have 2 equations 3 unknowns, underdetermined system of equations. I do not get what your problem is?
Osman Ajmal
Osman Ajmal le 3 Août 2018
I intentionally put Z==2 and z==5 for this example. I'm looking for a way to solve for all possible solutions that satisfy three of the five equations.
the question rephrased: Is there a function in Matlab to solve for any combination of three of the five equations in eqn_A?
I realise at this scale it is easier just trying to solve for all combinations of three equations in loops, but i want to use this for an array with 100's of equations.

Connectez-vous pour commenter.

Réponses (1)

Eduard Reitmann
Eduard Reitmann le 3 Août 2018
Modifié(e) : Eduard Reitmann le 3 Août 2018
Step 1: Rewrite each equation to add to zero. For example:
  1. 5*x^2 + x*y = 4
  2. y^2 + z = 2
  3. x + 2*z = 0
becomes:
  1. 5*x^2 + x*y - 4 = 0
  2. y^2 + z - 2 = 0
  3. x + 2*z = 0
Write to function.
f = @(x,y,z) [5*x.^2+x.*y-4;
y.^2+z-2;
x+2*z];
Step 2: Iteratively solve using fminsearch.
fun = @(x) sum(f(x(1),x(2),x(3)).^2);
x0 = [0;0;0];
x = fminsearch(fun,x0)

Tags

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by