How can I plot both a surface and line on the same plot image?

조회 수: 15 (최근 30일)
Richard Jones
Richard Jones 2020년 7월 14일
답변: Anshika Chaurasia 2020년 8월 12일
I'll start by saying this is motivated by my interest in complex numbers and analysis. This is something I feel I could do by hand, but as an engineer, it would be handy to know the tools MATLAB can offer to carry out my question.
I am looking for the following:
  • 1 plot
  • 2 Dimensional function (f = 2*x^2+2*x+2)
  • 3 Dimensional surface to plot the complex plane. I intend to use the following video as far as how I imagine plotting the C plane in MATLAB.
Any guidance or direction would be much appreciated. Thank you!
PS: I had to put the version for clarity, but it is implied that the answer doesn't have to be possible in the version I have downloaded.

답변 (1개)

Anshika Chaurasia
Anshika Chaurasia 2020년 8월 12일
Hi Richard,
It is my understanding that you want to have a 2-D line and surface plot of f = 2*x^2+2*x+2 in one plot.
You could try following code:
a = -2:0.1:2;
b = -2:0.1:2;
[A,B] = meshgrid(a,b);
Y = 2*(A+1i*B).^2 + 2*(A+1i*B) + 2;
surf(a,b,abs(Y));
hold on;
plot3(a,b*0,2*a.^2+2*a+2,'Color','red','LineWidth',5);
hold off;
Refer to the documentation of plot3, surf and hold for better information on plotting of a surface and line plots in the same figure.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by