How to graph a piecewise function NOT using if-else statements
Show older comments
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
Answers (1)
Jan
on 12 May 2018
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 Comments
David Ip
on 12 May 2018
Image Analyst
on 12 May 2018
Use & instead of &&.
David Ip
on 13 May 2018
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!