Clear Filters
Clear Filters

Problem 56313. Find Air Temperature from Cricket Stridulation Rate

3 views (last 30 days)
%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 Comments
Image Analyst
Image Analyst on 25 Apr 2024
Not sure what your edit was, but my answer, scroll down below John's comment, still stands.
aashka
aashka on 25 Apr 2024
No thats not the correct answer ,kindly revisit that question i have rectified my error and provided the complete ques with expectecd output

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 24 Apr 2024
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 Comment
Image Analyst
Image Analyst on 25 Apr 2024
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

Sign in to comment.


Voss
Voss on 25 Apr 2024
function y = getTemperature_F(x)
y = x+40;
end

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!