Need to plot x^2+y^2=z^2; plot in 3D ; also obtain 2D cut in xy plane. How od I do this. Thanks

2 views (last 30 days)
Need to plot x^2+y^2=z^2; plot in 3D ; also obtain 2D cut in xy plane. How od I do this. Thanks

Accepted Answer

Björn
Björn on 15 Oct 2012
There are several ways to do this. First you need to create the x- and y- arrays. This can be done using:
x=x_min:dx:x_max
y=(y_min:dy:y_max)'
x_min, y_min are the minimum values you want for x and y respectively. x_max, y_max are the maximum values. And dx, dy are the step-size between the different points. I take the transpose of y to be able to use BSXFUN so you don't have to create a loop to create the z-matrix.
The z-matrix can then be created by:
z=bsxfun(@plus,x.^2,y.^2)
note that the z-value is in fact z^2.
Next you can plot the 3D-surface using:
surf(x,y,z,'linestyle','none')
The part: 'linestyle','none' suppresses the gridlines, which in the case of a big matrix, you don't want to be shown.
Now if you want to have a 2D cut (or intensity-graph) in the xy plane, you add the command:
view(0,90) % Shows graph from top-view
camva(7) % Camera viewing angle. Alter to increase or decrease size of plot
Hope this is what you are looking for.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!