Warning message when creating surface plot.

2 visualizzazioni (ultimi 30 giorni)
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?
  1 Commento
Leaysia Lampkin
Leaysia Lampkin il 22 Gen 2023
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)) .

Accedi per commentare.

Risposta accettata

Voss
Voss il 22 Gen 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 Commenti
Leaysia Lampkin
Leaysia Lampkin il 22 Gen 2023
Thank you so much. I was able to proceed with no more issues.
Voss
Voss il 22 Gen 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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Linear Algebra in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by