matlab 新手,想编一个切比雪夫多项式的程序,但运行不了,到底应该怎么改
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/09/29 18:25:52
matlab 新手,想编一个切比雪夫多项式的程序,但运行不了,到底应该怎么改
具体程序是:
function T=Chebyshev2(n)
syms x
T(1:n)=0;
T(1)=1;
T(2)=x;
for i=3:n
T(i)=2*x*T(i-1)-T(i-2);
end
T(n)
x=[-pi:0.01:pi];
plot(x,T(n))
运行结果是:
The following error occurred converting from sym to double:
Error using ==> sym.double at 29
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable,use the VPA function instead.
Error in ==> Chebyshev2 at 5
T(2)=x;
应该怎么改呢
具体程序是:
function T=Chebyshev2(n)
syms x
T(1:n)=0;
T(1)=1;
T(2)=x;
for i=3:n
T(i)=2*x*T(i-1)-T(i-2);
end
T(n)
x=[-pi:0.01:pi];
plot(x,T(n))
运行结果是:
The following error occurred converting from sym to double:
Error using ==> sym.double at 29
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable,use the VPA function instead.
Error in ==> Chebyshev2 at 5
T(2)=x;
应该怎么改呢
问题:1、对T进行初始化要使用sym对象;2、plot的时候,要对符号表达式进行代入. 参考代码:function T=Chebyshev2(n)
syms x
T(1:n)=sym(0);
T(1)=1;
T(2)=x;
for i=3:n
T(i)=2*x*T(i-1)-T(i-2);
end
T(n)
x=[-pi:0.01:pi];
plot(x,subs(T(n),x))调用Chebyshev2(10)的结果如图:
syms x
T(1:n)=sym(0);
T(1)=1;
T(2)=x;
for i=3:n
T(i)=2*x*T(i-1)-T(i-2);
end
T(n)
x=[-pi:0.01:pi];
plot(x,subs(T(n),x))调用Chebyshev2(10)的结果如图:
下面的matlab 程序运行不了,求改错
求大神帮帮,我的matlab程序为什么运行不了?
怎么编一个计算圆锥的体积的程序啊?新手求教.
MATLAB的一个程序,运行出错,画不出图,求大牛!程序如下:
请问怎么用C++编一个程序,完成输入多项式系数后输出多项式,并计算多项式的值?
帮忙看下一个Lingo程序,自己编的运行不了了
小弟我用Lingo编了一个旅行商问题的程序,可以运行,但结果不符合约束条件,
哪位高手帮我看下我的matlab程序哪里出错了,运行不了.
刚学matlab菜鸟一枚,为什么书上的程序运行不了啊,求大神指教.
一个matlab的画图程序,怎么将for循环去掉,提高运行速度
这个程序为什么在MATLAB中运行不了?
下面程序为何在matlab中运行不了啊?