MATLAB Problem with drawing a function in MATLAB

AI Thread Summary
The discussion revolves around troubleshooting a MATLAB code intended to plot the function z = x + (y – 100)^2, with specified ranges for x and y. The user initially encounters errors due to incorrect syntax, specifically the use of dots in the code. The correct syntax for the meshgrid and surf functions is provided, emphasizing the need for element-wise operations in MATLAB. The corrected code is: [x,y]=meshgrid(-50:1:50,0:1:200) and surf(x, y, x + (y-100).^2). This highlights the importance of proper syntax and element-wise operations when working with MATLAB for function plotting.
Physics_rocks
Messages
12
Reaction score
0
hi guys ,

I'm trying to draw the following function , however MATLAB doesn't like my code . What am I doing wrong ?

z = x + (y – 100)^2

where x = -50 : 50,
y = 0 : 200


my code :

[x,y]=meshgrid(-50:1:50,-0:1:200)
surf(x , y , x. + (y.-100)^2)


thank you
 
Physics news on Phys.org
You have the dots in the wrong place
Code:
surf(x , y , x + (y-100).^2)
 

Similar threads

Replies
4
Views
1K
Replies
8
Views
2K
Replies
5
Views
2K
Replies
2
Views
3K
Replies
2
Views
3K
Back
Top