Please help to solve this

2 次查看(过去 30 天)
menna sharaf
menna sharaf 2020-7-2
编辑: .. 2020-7-2
The following is an approximate conversion formula for converting Fahrenheit to Celsius:
Celsius≈(Fahrenheit-30)/2
Using this formula, and starting from a Fahrenheit temperature 0, using a Matlab loop determine when the approximate equivalence Celsius temperature differs from the exact equivalent value by more than four degrees.
Note: the exact conversion formula:
Celsius=(Fahrenheit-32)5/9
  2 个评论
Steven Lord
Steven Lord 2020-7-2
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
..
.. 2020-7-2
编辑:.. 2020-7-2
i tried to write it but somthing not right
Fahrenheit=0;
appCelsius=fix(Fahrenheit-30)./2;
while((realCelsius-appCelsius)>4)
Fahrenheit=Fahrenheit+1;
realCelsius=fix(Fahrenheit-32)*5./9;
end
disp(Fahrenheit);

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2020-7-2
You got the > sign wrong for the loop. Plus you never updated the temperature in the loop to "temp" - you used Fahrenheit, which is a constant. Plus you never updated appCelsius in the loop. Here's a few of them fixed. See if you can finish it now.
temp=1;
Fahrenheit=0;
appCelsius=(Fahrenheit-30)./2;
realCelsius=(Fahrenheit-32)*5./9;
loopCounter = 1
maxIterations = 500;
while((realCelsius-appCelsius) < 4) && temp < 500
temp=temp+1;
realCelsius = (temp-32)*5./9;
fprintf('Degrees F = %d, Real Celsius = %f, Estimated Celsius = %f\n', temp, realCelsius, appCelsius);
end
disp(realCelsius);

类别

Help CenterFile Exchange 中查找有关 Physical Units 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by