matlab怎么输入取整函数?

例如输入 y=x^3-4*[x] 用floor 只能对数值取整~ 如果定义函数的话怎么让x,[x]同时出现在一个函数中并且不引入新的变量
我也是刚学matlab不久,要不超过x的最大整数,应该使用floor吧 现在需要用牛顿法解方程
syms x
x0=1;
f=x^3-3*x-1;
eps=1e-6;
maxcnt=1000;
fx=diff(f,x);
x1=x0;
cnt=1;
while cnt<=maxcnt
x2=x1-subs(f/fx,x,x1);
if abs(x1-x2)<eps
break;
end
[cnt,x1,x2]
x1=x2;
cnt=cnt+1;
end
这是可以运行的一个程序 现在需要把上面的f 换成f=-11.58t^3+69.36t^2*[t]-34.68t*[t]^2+40.8t^2+36.96t[t]+33t-140 ([t]为不超过t的最大整数) 求一个可以运行的程序 万分感谢!

y=@(x)x.^3-4*round(x);


y(1:0.1:3)



x取整后就变成常数了,所以在求导时先用另一个符号替代它,之后得到表达式后再替代回来(如果不替换直接写成floor(x),由于符号计算的核maple或MuPad的一些函数表达方式与matlab不同,用diff求导后得到的表达式matlab不认识导致出错)

clear;clc 
syms x y
x0=1;
f=-11.58*x^3+69.36*x^2*y-34.68*x*y^2+40.8*x^2+36.96*x*y+33*x-140
eps=1e-6;
maxcnt=1000;
fx=diff(f,x);
F=subs(f/fx,y,floor(x))
x1=x0;
cnt=1;
while cnt<=maxcnt
    x2=x1-subs(F,x,x1);
    if abs(x1-x2)<eps
        break;
    end
    [cnt,x1,x2]
    x1=x2;
    cnt=cnt+1;
end

温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2017-09-05
1)fix(x) : 截尾取整.
>> fix( [3.12 -3.12])
ans =
3 -3
(2)floor(x):不超过x 的最大整数.(高斯取整)
>> floor( [3.12 -3.12])
ans =
3 -4
(3)ceil(x) : 大于x 的最小整数
>> ceil( [3.12 -3.12])
ans =
4 -3
(4)四舍五入取整
>> round(3.12 -3.12)
ans =
0
>> round([3.12 -3.12])
ans =
3 -3
相似回答