How to solve for three equations from a large array of equations?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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?
답변 (1개)
Eduard Reitmann
2018년 8월 3일
편집: Eduard Reitmann
2018년 8월 3일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!