Simultaneous Equation using reduced row method
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 件のコメント
Harry Austin
2020 年 11 月 3 日
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
Image Analyst
2020 年 11 月 3 日
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?
Harry Austin
2020 年 11 月 3 日
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
Harry Austin
2020 年 11 月 3 日
Thank you :)
Image Analyst
2020 年 11 月 3 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
