Problem Comments
-
11条评论
Nice
乐趣ction bmi = bmi_calculator(hw)
h_inch = hw(:,1);
h_m = h_inch。* 2.54/100;
w_pounds = hw(:,2);
w_kg = w_pounds .* 0.453592;
BMI = w_kg / (h_m .* h_m);
bmi= BMI(:,end);
end
我会得到断言错误。...即使它为我的计算机提供了精确的输出。有人对此有所了解吗?
正在遇到断言错误,但在头脑风暴15分钟后终于得到了错误
乐趣ction bmi = bmi_calculator(hw)
%将高度值从英寸转换为米
高度= hw(:,1)./(2.54*10^-2)
% Convert the weight values from lbs to kilograms
weight=hw(:,2)./2.2
% Calculate the bmi for height and weight combination and return the output variable 'bmi'
bmi = weight./(height.^2);
end
can anyone help me to find the aassertion error?
Nice one!
谁能解释为什么
"bmi = convmass(hw(:,2),'lbm','kg') ./ (convlength(hw(:,1),'in','m').^2);"
不起作用?
@michael Green:感谢您指出Convmass和Convlength ...我不知道这些存在。
Your attempt doesn't work because of conversion round-off. The author indicates that 1" = 2.54cm. That conversion is exact and matches convlength.
The author also indicates that 1kg = 2.2lbs. That conversion is rounded, whereas convmass utilizes a more accurate conversion factor (2.2046). If you use the conversion factor indicated by the author (i.e., don't use convmass), it will work.
我的解决方案通过了第一个测试,我有4个小数点的精度,但我未能在第二个测试中进行。即使转换因子不相同,也不知道这是怎么可能的。顺便说一句,我使用为第二个测试选择的值完全匹配使用NIH计算器计算的值的答案。
好问题
解决方案中的评论只是为了提供帮助。该解决方案可以在单个语句中完成以提高大小。
乐趣
解决方案评论
-
2 Comments
The tolerance in assert is very high. Its not worthwhile to tune the decimal places to get that tolerance.
Reconsider the problem and reduce the tolerance.
This is the standard tolerance used in Cody. You'll encounter that frequently with many problems involving floating point numbers. There is nothing unsolvable/hard specifically about it.
-
1条评论
有趣的问题
-
1条评论
好问题
-
1条评论
Your first verification is FALSE
-
1条评论
be careful about the unit convertion,
高度= hw(:,1) * 2.54 / 100;
-
2 Comments
I made a good answer. and I was able to test hem in my desktop MATLAB but I got error with testing the first status here "error using assert"
您的功能将结果返回为行矢量而不是列向量。当仅指定一个维度时,MATLAB默认将结果作为行矢量编写,因此,将您的前面分配更改为BMI(i,1)= ...强制列矢量(或循环后转置BMI)。
-
3条评论
Please, do we need to sum up values of all rolls and columns respectively to calculate the BMI?
否。使用ElementWise操作。
Using regex just to wrap the entire code is just a tricky way of winning. The solution is no better than the others.
-
4条评论
我解决了问题,但奇怪的是,我必须将BMI结果与10000 RO相乘,获得正确的结果。以某种方式没有乘法的结果并不是确切的结果。有人面对同样的事情吗?
Did you use height in cm instead of in metres?
You have converted inches to centimeters and not meters by using the conversion factor 2.54.
啊,是的,谢谢您指出的人,对不起,您的回复很晚:/
-
1条评论
"The condition input argument must be convertible to a scalar logical."
how this error is rectified?
-
1条评论
通过将39.37分开以英寸为英寸的高度失败。但是,39.3701通过了第一次测试,但在第二个测试中失败。我必须找到更接近的价值以满足第二个测试,即39.37008。您应该改进测试参数。
-
1条评论
bmi_correct和bmi_calculator相同。即使那样,我也会得到断言错误
-
1条评论
我这个代码有什么问题,最终答案也很匹配,但它显示为失败,我没有得到它。
-
1条评论
Leading solution is not correct. The code has comment to convert the height and weight seperately followed by the bmi computation. bmi should not be calculated in one line of code as in leading solution by crunching all the factors.
-
1条评论
一个非常狭窄的断言。解决方案是正确的,但由于断言的限制,无法进行。
-
1条评论
该问题指定输入HW是具有两个列的矩阵(不是表)。因此,错误是说您不能在矩阵上使用DOT索引。
-
1条评论
Didn't know this is how simple BMI is.
-
2 Comments
我有正确的价值观,但是我以某种方式失败了主张?
The expected output is a column vector containing ALL the bmi values, whereas your code returns a single bmi value i.e. the last one. Hope that helps!
-
1条评论
提高公差值..我必须非常具体才能匹配结果
-
1条评论
好的!
Problem Recent Solvers4953
建议的问题
3936求解器
Circular Primes (based on Project Euler, problem 35)
260个求解器
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
336 Solvers
Natural numbers in string form
632求解器
609求解器
来自作者的更多13
问题标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
开始狩猎!