首页 \ 问答 \ 加快蛮力,在MATLAB中找到具有特定均值的分布(Speed up brute force for finding distribution with specific mean in MATLAB)

加快蛮力,在MATLAB中找到具有特定均值的分布(Speed up brute force for finding distribution with specific mean in MATLAB)

我有一个关于课程成绩的以下信息,

  • 共有21名学生。
  • 3个已知等级是:一个1.3 ,一个1.7和一个1.8
  • 我知道有20名学生的成绩在1.62.5之间。
  • 一名学生的成绩在1.01.5之间 - 这显然是1.3级。
  • 课程平均为1.9
  • 等级给出1位小数,例如2.22.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, one 1.7 and one 1.8.
  • I know that 20 students have a grade in between 1.6 and 2.5.
  • One student has a grade in between 1.0 and 1.5 - which is obviously the grade 1.3.
  • The course average is 1.9
  • Grades are given to 1 decimal place, e.g. 2.2 or 2.3 but never 2.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
更新时间:2022-02-22 20:02

相关问答

更多
  • 您可以使用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 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 ...
  • 按钮应该得到简短而有意义的描述,例如使用不可见的文本。 这对我来说似乎已经过时了。 你没错,这不是解决方案。 在谈论可访问性时,我们不必只关注使用屏幕阅读器的盲人,而是关注所有类型的残障。 将文本移出视口是完全无稽之谈。 当ARIA不受支持时,这曾经是使用屏幕阅读器的一小部分人群的(坏)解决方案,但这不再是一个真正的解决方案。 最好的解决方案仍然是撰写全文: [Font-Icon] Delete 是的,很明显,但值得一提。 第二种解决方案是使用title属性。 如果屏幕 ...
  • 这是使用http://schema.org/WebPage加上http://schema.org/Book等的属性完成的,例如 ...
  • 对于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 ...
  • 我会沿着这些方向做点什么...... 在qTip HTML标记中添加你想要的内容(而不是在title属性中):

    And this is the link content

    用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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)