資源簡介
matlab開發-使用gnewton-raphson方法查找任意多變量的根。用牛頓-拉斐遜法求任意多項式的根

代碼片段和文件信息
function?root=find_root(coef)
len=length(coef);?%number?of?coefficients?of?the?given?polynomial.
x=100;?%?initial?guess(This?can?be?set?to?any?value?as?the?preference)
error=inf;
while(error>0.00001)?%answer?is?correct?up?to?0.00001.
?y=0;
?ydif=0;????
????for?n=0:len-1
????y=y+coef(len-n)*x^n;?%calculating?the?polynomial?value
????ydif=ydif+n*coef(len-n)*x^(n-1);?%calculating?the?derivative?value
????end
????error=y/ydif;?%difference?between?previous?approximation?and?new?approximation?in?newtorn?rapson?method.
????x=x-y/ydif;?%newly?approximated?value?for?the?newtown?rapson?method
end
disp(x);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????622??2010-09-26?09:10??find_root.m
?????文件????????1318??2014-02-12?13:16??license.txt
評論
共有 條評論