Syntax error in matlab?! Help Please?

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,'.')

 采纳的回答

John D'Errico
John D'Errico 2017-2-19
编辑:John D'Errico 2017-2-19
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.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by