Problem with drawing a function in MATLAB

Click For Summary
SUMMARY

The forum discussion centers on a MATLAB coding issue related to plotting a function defined as z = x + (y – 100)^2. The user initially attempts to create a meshgrid with the command [x,y]=meshgrid(-50:1:50,-0:1:200) and uses incorrect syntax in the surf function. The correct code is surf(x, y, x + (y-100).^2), which resolves the syntax errors by ensuring proper operator placement and element-wise operations.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with meshgrid function in MATLAB
  • Knowledge of element-wise operations in MATLAB (using .^ and .*)
  • Basic concepts of 3D plotting in MATLAB using surf
NEXT STEPS
  • Explore MATLAB's documentation on the meshgrid function
  • Learn about element-wise operations in MATLAB, specifically .^ and .*
  • Research advanced 3D plotting techniques in MATLAB
  • Practice debugging common MATLAB syntax errors in plotting functions
USEFUL FOR

MATLAB users, data analysts, and engineers looking to enhance their skills in 3D plotting and debugging code in MATLAB.

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 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K