Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How does one plot $y=|x|$ in MATLAB?

share|cite|improve this question… Download this pkg and extract it to your path, now just follow his example. – Shuhao Cao Oct 16 '12 at 18:24
I have rolled back the edit on this question to the original, and added the OP's updated question regarding $y=|x|$ to the post in order to maintain a sense of context and continuity with the question the OP is asking, as the disjunction of the two has led to some apparent confusion. @Albert if your original question is no longer relevant, feel free to comment, answer your own question, or edit the post as such. – Emily Oct 16 '12 at 19:12

What does gibbs/fourier have to do with absolute value? Are you supposed to get its fourier expansion and then plot it against the absolute value function? Because that will exhibit gibbs phenomenon.

If you just want to plot y=abs(x), then just do

x = -10:0.01:10; y = abs(x); plot(x,y)

If you need the fourier expansion, MATLAB is not the way to do it. I would do it by hand analytically or use some symbolic software like MATHEMATICA. But if you use mathematica, then might as well plot in it too. It's easier and you get prettier pictures too.

share|cite|improve this answer
Thank you so mutch! – Albert Oct 17 '12 at 3:59
If you let $f(x) = |x|$ on $[-10,10]$ and be $20$-periodic, $f$ will be continuous, and I don't think it will exhibit the Gibbs phenomenon. – Stefan Smith Oct 19 '12 at 0:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.