Function that shouldn't be able to generate complex numbers giving me complex results
Show older comments
Basically the original question. I've got a function that shouldnt physically be able to give me complex numbers (the only thing that is taken to a root is a sum of two squares, which has to be positive). I've included the code that I have here. If someone could give me some info on why this is returning complex outputs I would love you forever.
f = @(x1,x2)((1/5)*((x1)^2 + (x2)^2)^(3/2) - (x1^2 + x2^2) + x1/2 + x2/2 + 7);
lim=[-5,0,-5,0];
X1 = linspace(lim(1),lim(2),10);
X2 = linspace(lim(3),lim(4),10);
[x1,x2] = meshgrid(X1,X2);
f(x1,x2)
The only reason I really care is that i'm trying to take this function and put it into the surf function, which threw the error
Error using surf (line 71)
X, Y, Z, and C cannot be complex.
I did a little hunting on my own, and discovered that for some reason, when I put just straight values (like if I were to call f(-4, -3)) it returns a positive decimal number, but when I pass the two matrices, it returns a bunch of complex numbers.
Accepted Answer
More Answers (0)
Categories
Find more on Parametric Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!