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

3 views (last 30 days)
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 "

Answers (2)

DGM
DGM on 15 Apr 2021
Edited: DGM on 15 Apr 2021
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 Comments
Hamada Alkhlif
Hamada Alkhlif on 15 Apr 2021
Edited: Hamada Alkhlif on 15 Apr 2021
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 on 15 Apr 2021
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

Sign in to comment.


VBBV
VBBV on 15 Apr 2021
Edited: VBBV on 15 Apr 2021
%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 Comments
Hamada Alkhlif
Hamada Alkhlif on 15 Apr 2021
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 on 15 Apr 2021
Edited: VBBV on 15 Apr 2021
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

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!