how can I Compute the value of d for the following values of x , Outcome equation d=((34.63/x)-5.126)/2.54

2 ビュー (過去 30 日間)
Is my code right i am beginner in matlab.
>>clc
>>clear
for x=[0.1000,0.1500,0.2000]
fprintf("\n\t%g\n",x)
else d=((34.63/x)-5.126)/2.54
disp ("ANSWER")
end
"OUTCOME WANTED RESULT "

回答 (2 件)

DGM
DGM 2021 年 4 月 15 日
編集済み: DGM 2021 年 4 月 15 日
I have no idea what that code is intended to do, but if you just want to evaluate the expression all x:
x=[0.1000,0.1500,0.2000]
d=((34.63./x)-5.126)/2.54
I guess if you're trying to get it to display formatted results to console, you could do that as well.
for l=1:numel(x)
fprintf('\t%g\t%g\n',x(l),d(l))
end
  7 件のコメント
Hamada Alkhlif
Hamada Alkhlif 2021 年 4 月 15 日
編集済み: Hamada Alkhlif 2021 年 4 月 15 日
actually iam getting the answer right but it look deferent .
answer after submitte above code :
>> Untitled3
0.1 134.32
answer =
0.1000 134.3205
0.1500 88.8743
0.2000 66.1512
0.15 88.8743
answer =
0.1000 134.3205
0.1500 88.8743
0.2000 66.1512
0.2 66.1512
answer =
0.1000 134.3205
0.1500 88.8743
0.2000 66.1512
>>
i just want the code to give 1 answer like this
answer =
0.1000 134.3205
0.1500 88.8743
0.2000 66.1512
how can i modify the last code @DGM ?
Steven Lord
Steven Lord 2021 年 4 月 15 日
Every time this line of code executes:
answer=[x' d']
it assigns a value to the variable named answer then displays the contents of that variable. If you just want to assign a value to the variable but not display it, end the line of code with a semicolon.
answer=[x' d'];
Then if you want to display it at the end of the code you can.
disp(answer) % or just plain
answer

サインインしてコメントする。


VBBV
VBBV 2021 年 4 月 15 日
編集済み: VBBV 2021 年 4 月 15 日
%true
d = [];
for x=[0.1000,0.1500,0.2000]
d=[d ((34.63/x)-5.126)/2.54];
disp ("ANSWER");
end
x=[0.1000 0.1500 0.2000];
fprintf("\t%4g\t\t%4g\n",[x;d])
  2 件のコメント
Hamada Alkhlif
Hamada Alkhlif 2021 年 4 月 15 日
this is almost the wanted code just is that the x values not in 4 decimals and it the code out put display 3 words of answers ,it required only one .
VBBV
VBBV 2021 年 4 月 15 日
編集済み: VBBV 2021 年 4 月 15 日
d = [];
for x=[0.1000,0.1500,0.2000]
d=[d ((34.63/x)-5.126)/2.54];
end;
disp ("ANSWER");
x=[0.1000 0.1500 0.2000];
fprintf("\t%.4f\t\t%.4f\n",[x;d])
Try this

サインインしてコメントする。

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by