Asked by Shaila parvin
on 9 May 2013

My code is:

x = linspace(-pi/2,pi/2,40);

y = x;

[X,Y] = meshgrid(x,y);

f = sin(X.ˆ2-Y.ˆ2);

figure(1)

contour(X,Y,f)

figure(2)

contourf(X,Y,f,20)

figure(3)

surf(X,Y,f)

the error is: ??? f = sin(Xˆ2-Yˆ2); |

Error: The input character is not valid in MATLAB statements or expressions.

How can I solve it?

*No products are associated with this question.*

Answer by John Doe
on 9 May 2013

Edited by John Doe
on 9 May 2013

Accepted answer

This should work:

[X,Y] = meshgrid(x,y); f = sin(power(X,2)-power(Y,2))

Hope it helps =)

Shaila parvin
on 9 May 2013

Answer by Wayne King
on 9 May 2013

Edited by Wayne King
on 9 May 2013

The problem is the character you have in for "^", not sure where you entered that in from, but copy and paste the below directly into the MATLAB workspace.

x = linspace(-pi/2,pi/2,40); y = x; [X,Y] = meshgrid(x,y); f = sin(X.^2-Y.^2); figure(1) contour(X,Y,f) figure(2) contourf(X,Y,f,20) figure(3) surf(X,Y,f)

Opportunities for recent engineering grads.

## 0 Comments