加快蛮力,在MATLAB中找到具有特定均值的分布(Speed up brute force for finding distribution with specific mean in MATLAB)
我有一个关于课程成绩的以下信息,
- 共有
21
名学生。- 3个已知等级是:一个
1.3
,一个1.7
和一个1.8
。- 我知道有20名学生的成绩在
1.6
到2.5
之间。- 一名学生的成绩在
1.0
到1.5
之间 - 这显然是1.3
级。- 课程平均为
1.9
- 等级给出1位小数,例如
2.2
或2.3
但不是2.25
。以下代码计算其他18名学生的可能成绩,其中成绩必须在上述约束范围内。
我正在使用蛮力的方式来做到这一点,比如:
clear all grades = zeros([1,21]) %certain grades grades(1) = 1.3; grades(2) = 1.7; grades(3) = 1.8; a = 1.6 b = 2.59 cnt = 0; while 1 grades(4:end) = round(((b - a).*rand(21 - 3,1) + a)/0.1)*0.1; if mean(grades) == 1.9 cnt = cnt + 1; savedres(cnt,:) = grades; end end
首先,我想知道如何在没有“暴力攻击”的情况下解决这个问题,其次我想知道上述方法是否正确?
最后,有没有办法知道我有多少不同的解决方案(例如我可以预先分配
savedres
矢量)?I have the following information about grades in a course,
- There is a total of
21
students.- 3 known grades are: one
1.3
, one1.7
and one1.8
.- I know that 20 students have a grade in between
1.6
and2.5
.- One student has a grade in between
1.0
and1.5
- which is obviously the grade1.3
.- The course average is
1.9
- Grades are given to 1 decimal place, e.g.
2.2
or2.3
but never2.25
.The following code calculates the possible grades of the other 18 students, where the grades must lay within the above constraints.
I am using a brute force way to do this, like:
clear all grades = zeros([1,21]) %certain grades grades(1) = 1.3; grades(2) = 1.7; grades(3) = 1.8; a = 1.6 b = 2.59 cnt = 0; while 1 grades(4:end) = round(((b - a).*rand(21 - 3,1) + a)/0.1)*0.1; if mean(grades) == 1.9 cnt = cnt + 1; savedres(cnt,:) = grades; end end
Firstly, I want to know how to solve this without a "brute force attack", secondly I wonder if the above method is correct?
Lastly, is there a way of knowing how many different solutions I have to expect (so I could preallocate the
savedres
vector for example)?
原文:https://stackoverflow.com/questions/45707993
相关问答
更多-
您可以使用Windows 10 SDK中的Inspect.exe查看Microsoft Edge的辅助功能树。 如果从Inspect的“选项”菜单中选择“UI自动化模式”和“控制视图”,您将获得最准确的表示。 有关Edge中可访问性的更多信息,请参阅此博客文章: 可访问性:使用Microsoft Edge和Windows 10建立更具包容性的Web 。 You can view the accessibility tree of Microsoft Edge using Inspect.exe from t ...
-
如果您提供用户无法打开的文档,那么这是一个可用性问题。 如果您提供的用户因残疾而无法访问的文档(或者因为他们的辅助技术不支持它),则会出现无障碍问题。 只提供PDF可以完美无缺 如果您的用户有PDF阅读器,和 如果您可以访问PDF文档。 (对于任何其他文档文件格式也是如此。) 当然,用户可以打开哪些格式无法回答。 如果您不了解这个用户群:最安全的选择是使用HTML(显然)和Web浏览器通常支持的其他格式(例如,PDF,纯文本)。 提供多种格式的文档当然可以对您的用户有益(某些用户更喜欢某些格式/程序,因为性 ...
-
我在最新的网站上使用了一个js-framework(我的case中的spine.js)。 仍然我确保非js浏览器(当然不是过分热心:认为SEO)可以导航我的网站和消化内容。 作为一个例子,我将在搜索页面上显示产品。 产品可以进行分页,过滤,排序。 当然这是广义思想的一个例子。 PREREQ:使用可以呈现服务器端和客户端的模板引擎。 (我使用胡子)。 这确保您可以通过服务器端模板渲染模型,并通过客户端模板将js渲染模型。 最初:使用服务器端的胡须模板渲染产品。 还包括一个包含与JSON格式相同的产品的'boo ...
-
在尝试在官方Google产品论坛上寻求帮助后,我通过遵循关于构建自定义按钮的文档解决了这个问题,但是从那里显示的内容更改了标记,而是使用了定位标记。 最后,它看起来像这样: HTML: ... More markup here ... 使用Javascript: auth2.attachClickHandler( document.getElementById('google-signin'), { 'scope': ...
-
Kendo UI核心和可访问性(Kendo UI Core and Accessibility)[2023-05-15]
Kendo UI Core和Kendo UI Professional之间的区别在于小部件集,而不是功能集。 所以你的问题的答案是肯定的,在Kendo UI Core中也有可用性功能。 The difference between Kendo UI Core and Kendo UI Professional is in the widget set, not in the feature set. So the answer to your question is yes, the accessibili ... -
Web可访问性 - 图像按钮的描述 - 过时的解决方案?(Web accessibility - description for image button - outdated solution?)[2022-03-21]
按钮应该得到简短而有意义的描述,例如使用不可见的文本。 这对我来说似乎已经过时了。 你没错,这不是解决方案。 在谈论可访问性时,我们不必只关注使用屏幕阅读器的盲人,而是关注所有类型的残障。 将文本移出视口是完全无稽之谈。 当ARIA不受支持时,这曾经是使用屏幕阅读器的一小部分人群的(坏)解决方案,但这不再是一个真正的解决方案。 最好的解决方案仍然是撰写全文: [Font-Icon] Delete 是的,很明显,但值得一提。 第二种解决方案是使用title属性。 如果屏幕 ... -
结构化数据可访问性页面(Structured data accessibility page)[2021-11-23]
这是使用http://schema.org/WebPage加上http://schema.org/Book等的属性完成的,例如 ... -
Dart中的Web组件(Web Components in Dart)[2022-08-14]
对于1.)似乎它是通过document.query('#my-component-id')。xtag完成的 对于2.)似乎可以通过代码实现,但现在过于复杂 有关详细信息,另请参见http://www.dartlang.org/articles/dart-web-components/spec.html For 1.) Seems it is done via document.query('#my-component-id').xtag For 2.) Seems that's possible by co ... -
Web辅助功能和qTip(Web Accessibility and qTip)[2024-02-03]
我会沿着这些方向做点什么...... 在qTip HTML标记中添加你想要的内容(而不是在title属性中): 用CSS隐藏qTip内容(甚至更好用的是使用像modernizr这样的东西,只在用户启用JavaScript时隐藏内容, 即 : .js .hidden用于选择器): .h ... -
您是否阅读过: http : //www.dartlang.org/articles/dart-web-components/ 另见: http : //www.dartlang.org/articles/dart-web-components/tools.html 您可以在此处找到示例代码: https : //github.com/dart-lang/dart-web-components 更新 :Seth在这里写了一篇不错的博客文章: http : //blog.sethladd.com/2012/1 ...