简体   繁体   中英

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:

discriminant = xSecondPart * ySecondPart - xySecondPart.^2;

Where xSecondPart and ySecondPart are the second partial derivatives of a function f. xySecondPart is the partial derivative with respect to x of the partial derivative with respect to y of the same function f.

I need to print out the values of discriminant at each value of x in the matrix xAns.

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

If you define the function discriminant anonymously, like so:

    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. The values returned will be in the same shape as the matrix xAns . I think that would be the easiest way to solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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