简体   繁体   English

矩阵函数的图形输出

[英]Plot output of matrix function

I have a matrix function with a scalar output, and I would like to plot this as a function of one of the elements of the matrix. 我有一个带标量输出的矩阵函数,并且我想将其绘制为矩阵元素之一的函数。 The exact function isn't important, so I'll use det for my example: 确切的功能并不重要,因此我将使用det作为示例:

>> fplot(det([x 0;0,1]),[0,1000])
Error using vertcat
CAT arguments dimensions are not consistent.

alternatively: 或者:

>> x=linspace(0,1000,1001);
>> plot(det([x,0;0,1]))
Error using vertcat
CAT arguments dimensions are not consistent. 

I'm sure this is simple, and there just a trick which googling hasn't revealed. 我敢肯定这很简单,而且有一个技巧还没有发现。

x=linspace(0,1000,1001);
plot(det([x,0;0,1]))

This is a problem: [x,0;0,1] 这是一个问题: [x,0;0,1]

because x has 1001 elements so your top row (ie [x,0] ) is 1002 elements and your bottom row is just 2 elements. 因为x有1001个元素,所以您的顶行(即[x,0] )是1002个元素,而底行只有2个元素。 And you're trying to vertically concatenate them ie the [;] operator. 您正在尝试垂直连接它们,即[;]运算符。 This only works if both rows have the same number of columns. 仅当两行的列数相同时,此方法才有效。

I'm not sure exactly what you're trying to plot so I can't recommend a fix, you'll have to explain the problem a bit better first. 我不确定您要绘制的内容到底是什么,因此我不推荐修复程序,您必须先对问题进行更好的解释。

This is possible (as I knew it would be) using fplot . 使用fplot可能(据我所知)。 But the command has to be fplot('det([x,0;0,1])',[0,1000]) (note the quotes). 但是命令必须是fplot('det([x,0;0,1])',[0,1000]) (请注意引号)。 In fact my ancient (matlab 5) paper manual says: 实际上,我古老的(matlab 5)纸质手册说:

"The most common mistake in using fplot (as well as other numerical analysis functions) is forgetting to put the name of the function in quotes That is fplot needs to know the name of the function as a character string" “使用fplot (以及其他数值分析函数)时,最常见的错误是忘记将函数名称放在引号中,这就是fplot需要知道函数名称为字符串”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM