Problem 56313. Find Air Temperature from Cricket Stridulation Rate

조회 수: 2 (최근 30일)
aashka 2024년 4월 23일
편집: Walter Roberson 2024년 4월 27일
%Stridulation is the process that creates a cricket's “chirp” by rubbing their wings or legs. According to the Old Farmer's Almanac (https://www.almanac.com/predict-temperature-cricket-chirps), the sum of the number of chirps in 14 seconds and 40 is the air temperature in degrees Fahrenheit.
%Crickets generally do not sing at temperatures below 55 F or above 100 F. (https://entomology.unl.edu/k12/crickets/temperature.htm)
%Use this formula to find the approximate outdoor temperature.
% Above is the given question and 4 test provided to answer that are as
% following
%test 1 input is x = 20; output is y_correct = 60;
% test 2 input is x = 30; output is y_correct = 70;
%test 3 input is x = 40; output is y_correct = 80;
%test 4 input is x = 50; output is y_correct = 90;
%for that given test below is my answer
function y = getTemperature_F(nchirps_in_14s)
x=[20 30 40 50]
F=0;
y=x;
y=fliplr(y);
while F<=50
F=F+110;
y=F-y;
end
end
%whats wrong with my answer i am not getting it.
댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Image Analyst 2024년 4월 25일
Not sure what your edit was, but my answer, scroll down below John's comment, still stands.
aashka 2024년 4월 25일
No thats not the correct answer ,kindly revisit that question i have rectified my error and provided the complete ques with expectecd output

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst 2024년 4월 24일
Not sure why you have a while loop. It will enter the while loop because F=0 is less than 50 but then you add 110 to it so the next F is 110 and it will not enter the while loop again because F is more than 50.
And there is no need for x since you just set y equal to it. You could just set y equal to those numbers directly and not even have x. In other words instead of
x=[20 30 40 50]
F=0;
y=x;
y=fliplr(y);
have
F = 0;
y = [50, 40, 30, 20];
Another problem is that you do not have any comments in your code like all good programmers put in.
댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Image Analyst 2024년 4월 25일
Why not simply add 40 like it said?
y_correct = getTemperature_F(20)
y_correct = 60
y_correct = getTemperature_F(30)
y_correct = 70
y_correct = getTemperature_F(40)
y_correct = 80
y_correct = getTemperature_F(50)
y_correct = 90
function y_correct = getTemperature_F(nchirps_in_14s)
y_correct = nchirps_in_14s + 40;
if nchirps_in_14s == 0
y_correct = 0;
end
end

댓글을 달려면 로그인하십시오.

Voss 2024년 4월 25일
function y = getTemperature_F(x)
y = x+40;
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Test Model Components에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by