码迷,mamicode.com
首页 > 其他好文 > 详细

matlab hornerDemo

时间:2017-04-23 10:50:37      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:quick   eth   actor   method   and   hit   atl   first   com   

% a quick demo of Horner‘s method and its effects

clear all
close all

% first a comparison of ways to compute

x = 0.988:.0001:1.012;
y1 = x.^7-7*x.^6+21*x.^5-35*x.^4+35*x.^3-21*x.^2+7*x-1;
plot(x,y1,‘r--‘)
pause

% because this polynomial can be nicely factored ...

y2 = (x-1).^7;
plot(x,y2)
pause

% now let‘s see Horner‘s method

y3=-1+x.*(7+x.*(-21+x.*(35+x.*(-35+x.*(21+x.*(-7+x))))));
plot(x,y3)
pause

% now for the head-to-head comparison

plot(x,y1,‘r--‘,x,y3)

matlab hornerDemo

标签:quick   eth   actor   method   and   hit   atl   first   com   

原文地址:http://www.cnblogs.com/wzjhoutai/p/6751737.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!