来帮我做道matlab编程题!!

用最简单,易懂,并且直接复制到matlab软件中就能运行的程序。题目如下:

设f(x)=x^5-4x^4+3x^2-2x+6
(1)取x=[-2,8]之间函数的值(取100个点),画出曲线,看它有几个零点。
(提示:用polyval函数)

一楼回答的不错了 ,但我把范围缩小下

x=linspace(-1.5,4,100);

fx=x.^5-4*x.^4+3*x.^2-2*x+6;

plot(x,fx);

%零点

p=[1 -4 0 3 -2 6];

roots(p)

%-------------

结果是三个实根 两个虚根! 

polyval是一个多项式赋值函数,不能求精确的零点,roots可以

温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-24

x=linspace(-2,8,100);

fx=x.^5-4*x.^4+3*x.^2-2*x+6;

plot(x,fx)

polyval(fx,x)

零点数在command windows显示。

本回答被网友采纳
第2个回答  2010-12-24
x=linspace(-2,8,100);
fx=[1 -4 0 3 -2 6];%多项式的系数
y=polyval(fx,x);
plot(x,y)

求多项式的零点使用roots
roots(fx)

3.7999
-1.2607
1.3479
0.0564 + 0.9623i
0.0564 - 0.9623i
第3个回答  2010-12-26
>> x=linspace(-2,8,100);
>> p=[1,-4,3,-2,6]; %the coefficient in descending order of the function
>> y=polyval(p,x);
>> plot(x,y)
>> grid on
第4个回答  2010-12-25
A=[3 4 -7 -12;
5 -7 4 2;
1 0 8 -5;
-6 5 -2 10];
B=[4;-3;9;-8];
rank(A)
X=A\B
相似回答