a code for gauss-jacobi and gauss-seidel (in one m-file, using switch case , press 1 for gauss-jacobi and 2 for gauss-seidel ) methods to solve the following system until the percent relative error falls below 0.001
-3x11-6x2+2x3=-61.5
10x1+2x2-x3=25
x1+x2+5x3=-21.5

回答 (1 件)

Roger Stafford
Roger Stafford 2016 年 4 月 26 日

0 投票

You could use matlab's 'ldivide' (back-slash) operator. (I assume the first equation was meant to be "-3x1-6x2+2x3=-61.5" with x1 replacing x11.)
A = [-3,-6,2;10,2,-1;1,1,5];
b = [-61.5;25;-21.5];
x = A\b;
The elements of x will be solutions for x1, x2, and x3.
Solving linear equations like this is what matlab is all about.

カテゴリ

ヘルプ センター および File ExchangeMathematics and Optimization についてさらに検索

タグ

タグが未入力です。

質問済み:

2016 年 4 月 26 日

編集済み:

2016 年 4 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by