楼主: hrbatanu
1447 7

[问答] 一道入门matlab [推广有奖]

  • 17关注
  • 4粉丝

已卖:2份资源

讲师

41%

还不是VIP/贵宾

-

威望
0
论坛币
199 个
通用积分
0.3600
学术水平
2 点
热心指数
6 点
信用等级
1 点
经验
4807 点
帖子
264
精华
0
在线时间
679 小时
注册时间
2011-6-23
最后登录
2022-6-4

楼主
hrbatanu 发表于 2013-6-30 12:03:35 |AI写论文
100论坛币
遇到一道题目:"for computers, the machine epsilon (lets call it m) can also be thought of as the smallest number that when added to one gives a number greater than 1. An algorithm based on this idea can be developed as:

step 1 : set m = 1.
step 2 : if 1+m is less than or equal to 1, then go to step 5. otherwise go to step 3.
step 3: m = m/2
step 4: return to step 2.
step 5:m = 2*m

write you own M-file based on this algorithm to determine the machine epsilon. validate the results by running the built in file epsilon

我从网上找到一段:
%machine epsilonclc,clear
m = realmin;
while ((1+m) <= 1)   
m = 2*m;
end
m
eps


为什么要用clear?clc是什么?为什么没有如果》=1,则除以2的code?应该怎么写呢?谢谢赐教!

最佳答案

URSIMON 查看完整内容

等你开始使用matlab完成很多工作时就知道了,只是为了清爽用清屏,至于清除现有变量你不同的工作的代码可能用相同的变量名这是就会发生错误
关键词:MATLAB matla atlab Atl Lab matlab

本帖被以下文库推荐

沙发
URSIMON 发表于 2013-6-30 12:03:36
hrbatanu 发表于 2013-6-30 12:44
谢谢回复,但是为什么要清屏和清除现有变量呢?是因为无限循环?
等你开始使用matlab完成很多工作时就知道了,只是为了清爽用清屏,至于清除现有变量你不同的工作的代码可能用相同的变量名这是就会发生错误

藤椅
URSIMON 发表于 2013-6-30 12:09:46
CLC 清屏命令;clear 清除现有变量;用if else

板凳
hrbatanu 发表于 2013-6-30 12:37:41
URSIMON 发表于 2013-6-30 12:09
CLC 清屏命令;clear 清除现有变量;用if else
为什么没有如果》=1,则除以2的code?

报纸
qlb061 发表于 2013-6-30 12:42:04
  1. clc;%clear screen;
  2. clear;%clear variables in the workspace;

  3. m = 1;
  4. while m+1 > 1
  5.     m = m/2;
  6. end
  7. m = 2*m;
  8. display(m);
  9. 或者直接在Matlab中输入命令:eps
  10. 要求的就是“机器零阀值”
复制代码
天道酬勤!

地板
hrbatanu 发表于 2013-6-30 12:44:26
qlb061 发表于 2013-6-30 12:42
谢谢回复,但是为什么要清屏和清除现有变量呢?是因为无限循环?

7
URSIMON 发表于 2013-6-30 12:48:17
这是标准做法你代码看多了就知道了

8
qlb061 发表于 2013-6-30 12:56:02
hrbatanu 发表于 2013-6-30 12:44
谢谢回复,但是为什么要清屏和清除现有变量呢?是因为无限循环?
可以不清屏的,只是美观一点罢了!
但是清除工作空间的变量一般是必须的,否则容易造成变量覆盖或者名称冲突。
天道酬勤!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 10:13