How can I plot a surface with changing constant?

조회 수: 1 (최근 30일)
A
A 2014년 4월 17일
편집: A 2014년 4월 18일
Hi guys,
I have a complex question. I want to graph the following equation as a surface. However, the constant A changes with a certain value of the y-axis:
Want to graph: z = M - 10x - 3.5y
Where
M = 5 + 3 for y < 10
M = 5 + 4 for 10 < y < 20
M = 5 + 5 for 20 < y < 30
Does this make sense? The value of the constant depends on the value of the y.
How can I approach this?
Thanks

채택된 답변

Star Strider
Star Strider 2014년 4월 17일
I suggest this as a possibility:
M = [3 4 5];
z = @(x,y) 5 + M(max(1,fix((y-30+0.1)/10)+3)) - 10.*x - 3.5.*y;
I tested the M-matrix addressing with this statement:
Mr = [y' max(1,(fix((y-30)/10)+3))' M(max(1,fix((y-30+0.1)/10)+3))']
The surface plot is an inclined plane.
  댓글 수: 2
Walter Roberson
Walter Roberson 2014년 4월 17일
There needs to be a jump at y = 10 and at y = 20
Star Strider
Star Strider 2014년 4월 17일
편집: Star Strider 2014년 4월 18일
There are in the code I tested, both with the Mr test variable and with z(y) with a fixed x=15. I was expecting visible discontinuities in the surface plot with X and Y defined with meshgrid with x and y defined as [0:0.1:30], but when I looked for them in the 2D plot, they were there but barely visible.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2014년 4월 17일
[X, Y] = ndgrid(....);
Z = 5 - 10 * X - 3.5 * Y;
Z(10 < Y & Y < 20) = Z(10 < Y & Y < 20) + 4;
and so on.
Note: your M is not defined for Y = 10 exactly or Y = 20 exactly
  댓글 수: 1
A
A 2014년 4월 18일
편집: A 2014년 4월 18일
Thank you for the solutions to you both.
I'm uncertain which solution is the best one to use in my case?
I want to be able to graph this as a surface?
Thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Computational Geometry에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by