Please help to solve this

조회 수: 7 (최근 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에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by