A part of my code is below. I am plotting a direction field of a differential equation. The second line of code S=-(X.^2 + Y^2)./(X*Y); and it is telling me that "Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
Error in Practice640 (line 6)
S=-(X.^2 + Y^2)./(X*Y); "
Could anyone help me in how to type it in so it correctly reads it?
[X,Y]=meshgrid(-5:0.1:5, -4:0.1:4);
S=-(X.^2 + Y^2)./(X*Y);
L=sqrt(1+S.^2);
figure
hold on
quiver(X, Y, 1./L, S./L,0.4,'.')

 Réponse acceptée

John D'Errico
John D'Errico le 19 Fév 2017
Modifié(e) : John D'Errico le 19 Fév 2017

1 vote

It looks like you are randomly using the elementwise operators in some places, but not in others. That will get you in trouble. For example, I see that you used X.^2, but then tried to use Y^2.
By the way, your next question might be to ask why you still have problems. That will be due to the fact that you try to use X*Y, instead of X.*Y.
If I could suggest that you need to be more careful in the code that you write.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by