For context, the function eps was added to the starting formula, to avoid the outcome of when X and Y both equal 0. The inital formula is Z = sin(sqrt(X * X + Y * Y)) / (sqrt(X * X + Y * Y)) .
Warning message when creating surface plot.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Leaysia Lampkin
am 22 Jan. 2023
Kommentiert: Voss
am 22 Jan. 2023
I was working on a code that will produce a scatter plot for the following equation, Z = sin(sqrt(X * X + Y * Y)) / (sqrt(X * X + Y * Y)). When writting it in matlab, I get to the last line of my code and I get this error "Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 7.112887e-37.". I changed the values in my linspace values thinking that was the issue but I got the same error.
Here is my code:
>> xg = linspace (-10,10,25);
>> [X,Y] = meshgrid (xg,xg);
>> Z = sin(sqrt(X * X + Y * Y)) / (sqrt(X * X + Y * Y + eps));
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 7.112887e-37.
I do know that in order for a surface plot to prodoce I need to use "surf(X,Y,Z)". I got stuck trying to find a work around for this message. Is it because of my linspace or is it with the formula I am trying to enter?
Akzeptierte Antwort
Voss
am 22 Jan. 2023
You probably mean to use element-wise multiplication and division, in order to get a matrix Z the same size as X and Y:
Z = sin(sqrt(X .* X + Y .* Y)) ./ (sqrt(X .* X + Y .* Y));
Or, the same, but using .^2 to square X and Y, and storing the result of sqrt() to avoid computing it twice:
d = sqrt(X.^2 + Y.^2);
Z = sin(d)./d;
3 Kommentare
Voss
am 22 Jan. 2023
"because of how I typed the formula"
Yes.
"*" is matrix multiplication, and ".*" is element-wise multiplication. Two different operations. Similarly "/" and "./" are different operations.
Glad it's working now!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!