Simultaneous Equation using reduced row method
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi, I am new to the software and am wondering how you would write a code which would solve any number of simultaneous equations. ie a code that when 3 equations were inputted would work out the answers as well as if you inputted 10 equations
채택된 답변
Image Analyst
2020년 11월 3일
Put the coefficients into a matrix, then divide.
Syntax
Description
x = A\B solves the system of linear equations A*x = B. The matrices A and B must have the same number of rows. MATLAB® displays a warning message if A is badly scaled or nearly singular, but performs the calculation regardless.
- If A is a scalar, then A\B is equivalent to A.\B.
- If A is a square n-by-n matrix and B is a matrix with n rows, then x = A\B is a solution to the equation A*x = B, if it exists.
- If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with m rows, then A\B returns a least-squares solution to the system of equations A*x= B.
Example:
% 2x + 4y + 3z = 3
% 3x + 5y + 2z = 8
% 1x + 2y + 5z = 9
A = [2,4,3; 3,5,2; 1,2,5]
B = [3;8;9]
xyz = A\B
% Other example from the help
A = magic(3)
B = [15; 15; 15];
x = A\B
If you still need help, give us your set of equations.
댓글 수: 6
Thank you for the help that is brilliant!
The problem I was given to work on after my lecture was as follows:
A system was modelled using first principles and the following set of linear equations was developed to describe it
Develop a script using MATLAB that will compute the reduced row echelon form of the augmented matrix developed, using only the basic operations of addition, subtraction, multiplication, and division, and the identifier for rows and columns Extra credit will be awarded for a script that can solve any set of three linear equations, and full credit will be awarded for a script that can solve any set of any number of linear equations.
Would your solution work for this?
Thanks in advance, Harry
If you can get the matrices, then yes, for sure. But what is your input? Is it the matrices? Or is it a character string with the equation and you have to parse out the numbers from it?
The way I’ve understood it is that A would be [2,4,6; 7,3,0; 2,0,1] and B would be [3;-2;-3] and I would have to use these to transform the inverse of A into a 3x3 identity matrix which in turn B into the answers for a b c. I wouldn’t know how to script this.
If you want, you can do the regular multi-matrix solution for least squares using ' to do the transpose, and inv() to do the inverse : inv(A' * A) * A' * B.
Here it is both ways. They both give the same answer:
A =[2,4,6;
7,3,0;
2,0,1]
B = [3;
-2;
-3]
% Method 1 : using \
abc = A \ B;
a = abc(1)
b = abc(2)
c = abc(3)
% Double check. We should recover B when we multiply things out.
b1 = A(1,1) * a + A(1,2) * b + A(1,3) * c
b2 = A(2,1) * a + A(2,2) * b + A(2,3) * c
b3 = A(3,1) * a + A(3,2) * b + A(3,3) * c
% Method 2 : using matrix solution
abc2 = inv(A' * A) * A' * B
a = abc2(1)
b = abc2(2)
c = abc2(3)
% Double check. We should recover B when we multiply things out.
b1 = A(1,1) * a + A(1,2) * b + A(1,3) * c
b2 = A(2,1) * a + A(2,2) * b + A(2,3) * c
b3 = A(3,1) * a + A(3,2) * b + A(3,3) * c
You'll see:
A =
2 4 6
7 3 0
2 0 1
B =
3
-2
-3
a =
-1.22413793103448
b =
2.18965517241379
c =
-0.551724137931035
b1 =
3
b2 =
-2
b3 =
-3
abc2 =
-1.22413793103448
2.18965517241379
-0.551724137931035
a =
-1.22413793103448
b =
2.18965517241379
c =
-0.551724137931035
b1 =
3
b2 =
-2
b3 =
-3
Thank you :)
My pleasure. To thank people in the forum, you can award them "reputation points" by "Accepting" their answer and also clicking on the "Vote" icon. Thanks in advance.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
