问题描述
(考虑函数
f(X)= 1 / XD
,其中newton-Raphson迭代给出了
Xi + 1 = Xi-(f(Xi)/ f'(Xi))= Xi - ((1 / Xi-D)/( - 1 / Xi ^ 2))= Xi + Xi(1-DXi)= Xi(2-DXi) )
哪个可以用Xi计算,只使用乘法和减法,或者使用两个融合乘法加法。你能想到它的作用以及你在实现它时需要注意的事情吗?写一个C代码来计算它。)
我的ans:
#include< stdio.h>
main()
{
浮动X [15],X1 [15]; //我为Xi取X1,为Xi + 1取X1;
int D;
printf(输入X [i]的值:);
scanf(%f,& X [15]);
printf(\输入D的值:);
scanf(%d,& D);
X1 [15] = X [15] *(2-(D * X [15]));
printf(X [i + 1] =%f \ n,X1 [15]);
}
我是c编程的初学者。谢谢。
( Consider the function
f(X)=1/X-D
for which the newton-Raphson iteration gives
Xi+1=Xi-(f(Xi)/f'(Xi))=Xi-((1/Xi-D)/(-1/Xi ^2))=Xi+Xi(1-DXi)=Xi(2-DXi)
Which can be calculated from Xi using only multiplication ans subtraction , or using two fused multiply-addition. Can you expect what it does and what all care you are required to take while implementing it and can you write a C code to compute it. )
my ans:
#include<stdio.h>
main()
{
float X[15],X1[15]; //i took X for Xi and X1 for Xi+1;
int D;
printf("enter the value for X[i]:");
scanf("%f",&X[15]);
printf("\nenter the value of D:");
scanf("%d",&D);
X1[15]=X[15]*(2-(D*X[15]));
printf("X[i+1]=%f \n",X1[15]);
}
Am some what beginner at c programming.Thank you.
推荐答案
这篇关于这是我面试的问题。我的答案是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!