# Given a temperature, return windchill as a vector.

42 ビュー (過去 30 日間)
Nirav Patel 2015 年 11 月 7 日

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.

サインインしてコメントする。

### 回答 (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 件のコメント表示非表示 1 件の古いコメント
Image Analyst 2015 年 11 月 7 日
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?

サインインしてコメントする。

Ousmane Diop 2021 年 1 月 22 日
windChills = 35.7 + 0.6*T - 35.7*W^0.16 + 0.43*T*W^0.16 ;

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by