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

조회 수: 1 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by