作业帮 > 综合 > 作业

matlab看不懂.function y=f(x) y=1./x+2*sin((2*x).^0.5);end >> fo

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/11 00:35:14
matlab看不懂.
function y=f(x)
y=1./x+2*sin((2*x).^0.5);
end

>> format long
>> x=3.3;h=0.1;
g=(f(x+h)-2*f(x)+f(x-h))/(h^2)

g =

-0.009399348448680

>> x=3.3;h=0.001;
g=(f(x+h)-2*f(x)+f(x-h))/(h^2)

g =

-0.009377437715230

>> x=3.3;h=0.001;
g=(f(x+h)-2*f(x)+f(x-h))/(h^2)

g =

-0.009377437715230
代码定义了一个函数:f(x) =1/x + 2*sin(√(2x))
里面的下标“.” 表示当x为数组时,预算是对数组成员分别进行的.
下面f(x+h)相当于把3.3001代入上面的函数,f(x) f(x-h)也一样.
format long 表示改变了精度.