plot and illustrate the intersection

1 回表示 (過去 30 日間)
Nguyen Huy Hoang
Nguyen Huy Hoang 2021 年 5 月 20 日
回答済み: Vedant Shah 2025 年 4 月 3 日
Plot the surface z=x^2−2y^2 and the cylinder x^2+y^2=4 in the same coordinate system Oxyz.Oxyz. Then illustrate the intersection between the two surfaces. I need the matlab code for this. Pls help

回答 (1 件)

Vedant Shah
Vedant Shah 2025 年 4 月 3 日
To plot the surface z = x^2 - 2y^2, the surf command can be utilized as follows:
surf(x, y, z, 'EdgeColor', 'none', 'FaceAlpha', 0.7);
For plotting the cylinder x1^2 + y1^2 = 4, a stack of circles can be created and plotted using plot3 function in 3D. First, define the height for the cylinder and space the points equally to create a stack of circles:
height = linspace(-10, 10, 10000);
Then, iterate through the height values and plot the circles:
for k = 1:length(height)
plot3(x1, y1, height(k) * ones(size(x1)), 'r', 'LineWidth', 1.5);
end
The plot3 function can be used to plot the intersection surface as well.
z_intersection = x1.^2 - 2*y1.^2;
plot3(x1, y1, z_intersection);
Using sample data, the image obtained is as follows:
For more information, you can refer to the following documentation:

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by