用迭代法求x=a^1/3求立方根的迭代公式为:xi+1=2/3xi+a/(3xi^2)迭代到xi+1-xi的绝
展开全部
Private Sub Command1_Click()
Dim x As Single, x0 As Single, x1 As Single, a As Single
a = Val(InputBox("请输入一个数a="))
If Abs(a) < 0.000001 Then
x = 0
Else
x0 = a / 2
x1 = (2 / 3 * x0) + a / (3 * x0 ^ 2)
Do While Abs(x1 - x0) > 0.00001
x0 = x1
x1 = (2 / 3 * x0) + a / (3 * x0 ^ 2)
Loop
x = x1
End If
Print a & "的立方根为;"; x
End Sub
Dim x As Single, x0 As Single, x1 As Single, a As Single
a = Val(InputBox("请输入一个数a="))
If Abs(a) < 0.000001 Then
x = 0
Else
x0 = a / 2
x1 = (2 / 3 * x0) + a / (3 * x0 ^ 2)
Do While Abs(x1 - x0) > 0.00001
x0 = x1
x1 = (2 / 3 * x0) + a / (3 * x0 ^ 2)
Loop
x = x1
End If
Print a & "的立方根为;"; x
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
dim a!,x()!,x1!a = 27x() = 2i = 0Doi = i - 1X1 = 2 * x() / 3 + a / (3 * x() * x())If Abs(X1 - x()) < 0.00001 Then Exit Dox() = X1LoopPrint X1, iEnd Sub
dim a!,x()!,x1!a = 27x() = 2i = 0Doi = i - 1X1 = 2 * x() / 3 + a / (3 * x() * x())If Abs(X1 - x()) < 0.00001 Then Exit Dox() = X1LoopPrint X1, iEnd Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
double tion(m)
{
double b, fX, fXplus, fDiff;
printf("Enter a number: ");
scanf("%lf", &b);
fX = b;
do
{
fXplus = fX * 2/3 + b / (3 * fX * fX);
fDiff = fXplus - fX;
fX = fXplus;
}
while((fDiff <= -0.00001) || (fDiff >= 0.00001));
printf("\nThe cube root of %lf is %lf.\n", b, fX);
}
main()
{
double a,i;
i=tion(a);
}
double tion(m)
{
double b, fX, fXplus, fDiff;
printf("Enter a number: ");
scanf("%lf", &b);
fX = b;
do
{
fXplus = fX * 2/3 + b / (3 * fX * fX);
fDiff = fXplus - fX;
fX = fXplus;
}
while((fDiff <= -0.00001) || (fDiff >= 0.00001));
printf("\nThe cube root of %lf is %lf.\n", b, fX);
}
main()
{
double a,i;
i=tion(a);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |