![]() |
求助:subs 命令的应用
[B][/B]HELP 中有介绍:“subs(S,old,new),If old and new are cell arrays of the same size, each element of old is replaced by the corresponding element of new.”但是当old 和new 中有向量时总是出现错误,求求那位智者能给予解答!!!
syms t t0=1/3*pi; y=[2;2;2]; y0=[1;0;0]; S=sin(t)*y; subs(S,{t,y},{t0,y0}) ans = 3^(1/2) 3^(1/2) 3^(1/2) 答案应该是 3^(1/2)/2 0 0 :confused: |
回复: 急求:subs 命令的应用
我的理解,subs里的old 和 new是这样的:
old 是 syms 定义的变量,而new是old的实例化,你的段程序里: y是一个实例,不是syms变量,因此,当你用t = sin(t0)*y;的时候,t的syms表示就是: [2*sin(t0);2*sin(t0);2*sin(t0)] 所以会得到你的那个结果,如果想得到你希望的结果,需要定义y为cell变量: syms t, y t0=1/3*pi; y0=[1;0;0]; S=sin(t)*y; subs(S,{t,y},{t0,y0}) |
回复: 急求:subs 命令的应用
[QUOTE=yhcode;39827]我的理解,subs里的old 和 new是这样的:
old 是 syms 定义的变量,而new是old的实例化,你的段程序里: y是一个实例,不是syms变量,因此,当你用t = sin(t0)*y;的时候,t的syms表示就是: [2*sin(t0);2*sin(t0);2*sin(t0)] 所以会得到你的那个结果,如果想得到你希望的结果,需要定义y为cell变量: syms t, y t0=1/3*pi; y0=[1;0;0]; S=sin(t)*y; subs(S,{t,y},{t0,y0})[/QUOTE] 您好,感谢您的来帖。用您的方法编程MATLAB 会出现以下的提示: “??? Error using ==> sym.subs Elements of the substitution cell array must be of the same size.”是不是因为size(y)=1 1 |
回复: 急求:subs 命令的应用
S = sin(t)*y 提取t0和y0时,也就变成了S = sin(t0)*y0,这时候要满足矩阵乘法的要求的
|
回复: 急求:subs 命令的应用
一个数和一个向量可以直接相乘的,MATLAB显示的结果最后是sin(t0)*y,而不是sin(t0)*y0,这是我最迷惑的。
|
所有时间均为北京时间。现在的时间是 05:20。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.