How to solve for three equations from a large array of equations?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Aquatris
am 3 Aug. 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?
Antworten (1)
Eduard Reitmann
am 3 Aug. 2018
Bearbeitet: Eduard Reitmann
am 3 Aug. 2018
Step 1: Rewrite each equation to add to zero. For example:
- 5*x^2 + x*y = 4
- y^2 + z = 2
- x + 2*z = 0
becomes:
- 5*x^2 + x*y - 4 = 0
- y^2 + z - 2 = 0
- 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)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!