MATLAB已知函数为f(x)=x^3-3*x^2-x+3,编辑函数文件 hanshu.m,计算…

已知函数为f(x)=x^3-3*x^2-x+3,编辑函数文件 hanshu.m,计算f(0.3)、f(6.87)、f(3)-f(2)[f^2(-4)],并画出他的图形

函数文件 hanshu.m

function f=hanshu(x)

f=x.^3-3*x.^2-x+3;

end

f(0.3)、f(6.87)、f(3)-f(2)[f^2(-4)]的计算值

x=-10:0.5:10;y=hanshu(x);plot(x,y),xlabel('x'),ylabel('f(x)')

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

hanshu.m文件

function y = hanshu(x)
y = x^3 - 3*x^2 - x + 3;

另一个m文件

t = -5 : 0.01 : 5
a = hanshu(0.3);
b = hanshu(6.87);
plot(t, hanshu(t));

本回答被网友采纳
相似回答