I need to write a code to solve a system of equations with formatted output (fprintf).

9 ビュー (過去 30 日間)
Aj
Aj 2022 年 5 月 13 日
回答済み: Dyuman Joshi 2022 年 5 月 13 日
%Code to linear equations with 3 unknowns
% x - 3y + 2z = -11
% 2x - 4y + 3z = 0
% 3x - 5y -4z = 5
A=[1, -3, 2; 2, -4, 3; 3, -5, -4]
B=[-11; -15; 5]
x=inv(A)*B
this is what i have so far. I'm having trouble with formatting the output with fprintf. I need the values to be x= 1 y=2 z=-3. Please and thank you.

回答 (1 件)

Dyuman Joshi
Dyuman Joshi 2022 年 5 月 13 日
A=[1, -3, 2; 2, -4, 3; 3, -5, -4];
B=[-11; -15; 5];
x=inv(A)*B;
fprintf('x=%d, y=%d, z=%d.', x(1:3))
x=1, y=2, z=-3.

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by