Given a temperature, return windchill as a vector.
12 次查看(过去 30 天)
显示 更早的评论
On a windy day, a temperature of 15 degrees may feel colder, perhaps 7 degrees. The formula below calculates the "wind chill," indicating the temperature that is felt based on the actual temperature (T, in Fahrenheit) and wind speed (W, in miles per hour):
windChill = 35.7 + 0.6T - 35.7W^0.16 + 0.43TW^0.16 In a previous problem you wrote a function to return the wind chill for a single temperature T and wind speed W. In this problem the function is given a single temperature T but a vector of wind speeds WV; your job is to return a vector of wind chills, one for each temperature and wind speed pair. For example, if T is 32 and WV is [1:5], then the function returns the vector [32.9600, 30.3867, 28.7437, 27.5116, 26.5161].
Here is the code given
function windChills = ComputeWindChills(T, WV) windChills = ... ; end
finish the code.
0 个评论
回答(2 个)
Image Analyst
2015-11-7
It seems like the question told you the answer, except maybe to put in a few operators like * and . (dot) to fix the syntax.
windChill = 35.7 + 0.6T - 35.7W^0.16 + 0.43TW^0.16
First of all, you'll need to change windChill to windChills to give it the desired name. Then, look up "times, .* - Element-wise multiplication" in the help. You'll also need size() or length() to verify that the size and shape of T and W are the correct and allowable. Inserting 7 characters into the above line of code will produce the correct syntax and correct answer (except for input validation like I mentioned, but you may not need to do that because the problem said you can assume a scalar and a vector are passed in).
2 个评论
Image Analyst
2015-11-7
编辑:Image Analyst
2021-1-22
You didn't look up "times, .* - Element-wise multiplication" like I suggested. If you had, you would have known to use .^ instead of ^.
function windChills = ComputeWindChills(T, WV, W)
windChills = 35.7 + 0.6 * T - 35.7 * W .^ 0.16 + 0.43 * T .* W .^ 0.16
end
If T and W are vectors, then windChill will be a vector. But the last term there is (0.43 * T) .* (W.^0.16), not (0.43 * T .* W) .^ 0.16 so make sure you use whichever one you're supposed to.
In your function you don't pass in W, you pass in WV. I don't know what WV is. You don't show it in your formula. What is the use of WV?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!