How to graph a piecewise function NOT using if-else statements

조회 수: 3 (최근 30일)
David Ip
David Ip 2018년 5월 12일
댓글: David Ip 2018년 5월 13일
Good morning,
My professor is asking is to graph a piecewise function in R3 using anonymous functions and logicals and NOT using if-else statements. He also is asking to use "meshgrid" and the "surf" command. I attached the picture below. How would I start this? Thanks in advance

답변 (1개)

Jan
Jan 2018년 5월 12일
Start by using meshgrid and surf with a non-piecewise function: find out how to draw a plane at all.
Then use this method:
t = linspace(0, 2*pi, 100);
y = sin(t) .* (t < pi) + cos(t) .* (t >= pi);
plot(t, y)
This is a "logical mask" to create a piecewise function. It works in 2D also.
  댓글 수: 3
Image Analyst
Image Analyst 2018년 5월 12일
Use & instead of &&.

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

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by