简体   繁体   English

MATLAB帮助。 将变量矩阵插入现有函数

[英]MATLAB Help. Plugging in matrix of variables into existing function

I have an existing function of two variables (x,y) called discriminant defined in the following way: 我有一个两个变量(x,y)的现有函数,称为判别式,用以下方式定义:

discriminant = xSecondPart * ySecondPart - xySecondPart.^2;

Where xSecondPart and ySecondPart are the second partial derivatives of a function f. 其中xSecondPart和ySecondPart是函数f的第二个偏导数。 xySecondPart is the partial derivative with respect to x of the partial derivative with respect to y of the same function f. xySecondPart是关于相同函数f的y的偏导数的x的偏导数。

I need to print out the values of discriminant at each value of x in the matrix xAns. 我需要在矩阵xAns中的x的每个值处打印出判别式的值。

The below code is not working... 以下代码不起作用......

for idx = 1:numel(xAns)
    disp(discriminant(xAns(idx)));
end

Hopefully someone can provide a solution. 希望有人能提供解决方案。 Thank you 谢谢

Best...SL 最佳... SL

If you define the function discriminant anonymously, like so: 如果您匿名定义函数discriminant ,如下所示:

    descriminant = @(x) 24*x.^2 - 32;

Then all you have to do is type the following statement in the command line or function you're running: 然后,您所要做的就是在您运行的命令行或函数中键入以下语句:

    D = discriminant(xAns)

If your function has been defined using the elementwise operator '.' 如果使用元素运算符''定义了函数。 wherever necessary, then the statement above will print out the discriminant function evaluated at every element of the matrix xAns , regardless of its size or shape. 必要时,上面的语句将打印出在矩阵xAns每个元素处评估的discriminant函数,无论其大小或形状如何。 The values returned will be in the same shape as the matrix xAns . 返回的值将与矩阵xAns具有相同的形状。 I think that would be the easiest way to solve your problem. 我认为这将是解决问题的最简单方法。

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

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