フィルターのクリア

MATLAB not displaying answer correctly in command window

1 回表示 (過去 30 日間)
Kaylee Chavez
Kaylee Chavez 2021 年 3 月 30 日
回答済み: per isakson 2021 年 3 月 30 日
Hi there.
So I am currently working on a project that calculates a mixed triple product with all six permutations. I currently have the answers displaying in the command window. However, when I look at the answers, I do not get a numerical answer on three out of six, even though they are the same code formulas. Also, is there any way to limit the answer to be two digits, instead of 7 and an exponent? I have attached my code and a photo of my answer output.
P = [0, 3, 0];
Q = [0, 0, 5];
S = [2, 0, 0];
%%Cross Products
QS = cross(Q, S);
SP = cross(S, P);
PQ = cross(P, Q);
SQ = cross(S, Q);
PS = cross(P, S);
QP = cross(Q, P);
%%Dot Products
PQS = dot(P, QS);
QSP = dot(Q, SP);
SPQ = dot(S, PQ);
PSQ = dot(P, SQ);
QPS = dot(Q, PS);
SQP = dot(S, QP);
%%Display
fprintf ("The triple product of P*(QxS) is %s\n", PQS);
fprintf ("The triple product of Q*(SxP) is %s\n", QSP);
fprintf ("The triple product of S*(PxQ) is %s\n", SPQ);
fprintf ("The triple product of P*(SxQ) is %s\n", PSQ);
fprintf ("The triple product of Q*(PxS) is %s\n", QPS);
fprintf ("The triple product of S*(QxP) is %s\n", SQP);

採用された回答

per isakson
per isakson 2021 年 3 月 30 日
Look up the help on format specifier of fprintf().
Next replace the spec, %s, in your %%Display section by %+7.2f
The triple product of P*(QxS) is +30.00
The triple product of Q*(SxP) is +30.00
The triple product of S*(PxQ) is +30.00
The triple product of P*(SxQ) is -30.00
The triple product of Q*(PxS) is -30.00
The triple product of S*(QxP) is -30.00

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by