MATLAB - 具有自变量的矩阵函数?
我正在尝试创建一个函数,该函数返回一个包含变量“l”的矩阵,该变量是一个独立变量,稍后将被扫描以绘制绘图。
我会根据用户输入(包括“n”和“d”)计算“phi”,然后使用“n”、“d”和“phi”来查找“a”、“b”、“c”,和“d”来创建矩阵“m”。该矩阵“m”将是“l”的函数。
phi = 2*pi*n*d/l;
a = cos(phi);
b = 1i*sin(phi)/n;
c = 1i*n*sin(phi);
d = cos(phi);
m = [a b;c d];
与 C++ 和 Python 相比,我真的不喜欢 MATLAB 的编码风格……你们会如何实现这个功能?
摘要:我想要一个返回矩阵的函数,该矩阵包含稍后要扫描的自变量。
I'm trying create a function that returns a matrix containing a variable "l" which is an independent variable to be swept for a plot later on.
I would calculate "phi" based on user inputs which include "n" and "d", then I would use "n", "d", and "phi" to find "a", "b", "c", and "d" to create a matrix "m" with. This matrix "m" will be a function of "l".
phi = 2*pi*n*d/l;
a = cos(phi);
b = 1i*sin(phi)/n;
c = 1i*n*sin(phi);
d = cos(phi);
m = [a b;c d];
I'm really not enjoying MATLAB's coding style as compared to C++ and Python... How would you guys implement this functionality?
Summary: I want a function that returns a matrix which contains an independent variable to be swept for a plot later.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以有两种选择。
1) 创建一个函数,返回基于
n
,d
,l
的矩阵2) 使用符号工具箱(如果可能)
You can two options.
1) Create a function which returns the matrix based on
n
,d
,l
2) Use the symbolic toolbox (if possible)
您的意思是使用符号工具箱吗?
如果是这样,我想您想:
顺便说一句,您是否知道
d
的别名?这是故意的吗?Do you mean to use the symbolic toolbox?
If so, I guess you want:
And as a little aside, are you aware of your aliasing of
d
? Is that intentional?