Reputation: 2864
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
Upvotes: 0
Views: 663
Reputation: 126
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.
Upvotes: 2