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

조회 수: 2 (최근 30일)
Osman Ajmal
Osman Ajmal 2018년 8월 2일
편집: Eduard Reitmann 2018년 8월 3일
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
Aquatris
Aquatris 2018년 8월 3일
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 2018년 8월 3일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Eduard Reitmann
Eduard Reitmann 2018년 8월 3일
편집: Eduard Reitmann 2018년 8월 3일
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)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by