Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

share|improve this question
    
mathworks.com/matlabcentral/fileexchange/… 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. –  Arkamis Oct 16 '12 at 19:12
add comment

1 Answer

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|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
add comment

Your Answer

 
discard

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.