全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
1941 10
2013-06-29
悬赏 100 个论坛币 已解决
小弟报了一门课用matlab,虽然题目简单,但是毫无编程和matlab基础。希望大家指教 题目
以上是题目,接下来是我写的code,不在学校手里没有matlab,暂时没run:

%%initial the values
a=2;

while (s > 0.0001)
    xold=x;
    x=(x+a/x)/2;
    s=abs((x-xold)/x);
    if(s<0.0001)
        break
    end
end
上面的哪些地方要改呢?
还有,如何reture both the result and error? 有个return的code?
display the result as a imaginary number? matlab不是自动用i吗?

谢谢


最佳答案

24578901 查看完整内容

首先介绍一下divide and average method Let A be the number whose square root is wanted. Determine in some way a first guess g of the square root of A. The remaining part of the method is to repeat the following step: Divide A by the current guess g and then average the quotient with g. The average is the new guess.(首先是要对A的平方根做一个估计,我这用x=a/2估计) Repeat until you have calcu ...
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-6-29 11:58:37
首先介绍一下divide and average method
Let A be the number whose square root is wanted.  Determine in some way a first guess g of the square root of A.  The remaining part of the method is to repeat the following step: Divide A by the current guess g and then average the quotient with g.  The average is the new guess.(首先是要对A的平方根做一个估计,我这用x=a/2估计)

Repeat until you have calculated the square root to desired accuracy.  Roughly, the number of decimal places doubles with each repetition.

上传了两幅一样的图,竟然删不了,Sorry
附件列表
流程.jpg

原图尺寸 21.86 KB

流程.jpg

新建 Microsoft Visio 绘图.jpg

原图尺寸 1.42 KB

新建 Microsoft Visio 绘图.jpg

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-29 12:26:07
题目的意思是,根据变换正数a,以获得合理的误差求平方根。
要想有返回值,M文件可以这样写function [result,error]=myfun(x)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-29 12:52:01
24578901 发表于 2013-6-29 12:26
题目的意思是,根据变换正数a,以获得合理的误差求平方根。
要想有返回值,M文件可以这样写function [resu ...
恩,要求a的平方根,先代入2,循环找到一个x给出error在可接受范围内,从而知道a。但是为什么要求make sure it can evaluate the square of number that are equal to and less than zero? 负数的话,不是自动用复数吗?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-29 14:55:48
hrbatanu 发表于 2013-6-29 12:52
恩,要求a的平方根,先代入2,循环找到一个x给出error在可接受范围内,从而知道a。但是为什么要求make su ...
divide and average method是逼近任意正数a(any positive number a)的平方根的一个古老方法,如果要a系小于或等于0,就不能用divide and average method了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-6-30 12:07:48
24578901 发表于 2013-6-29 16:07
首先介绍一下divide and average method
Let A be the number whose square root is wanted.  Determine i ...
恩,第二个图挂了。第一幅图逻辑很清楚,但是我自己还是写不对,我觉得我刚开始学应该多看,多模仿,自己瞎写浪费时间,请问你能帮我直接写出来看看吗?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群