Help with plotting triangular wave

  • Thread starter Thread starter Davidlong
  • Start date Start date
  • Tags Tags
    Plotting Wave
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
34 replies · 13K views
lewando said:
Also, one final thing: what is the purpose of doing:

% Make wave start at 0
s = s - s(1);

This introduces an artificial offset to the data. Is this required?

It's not really required. I re-ran is by doing s=0; before all the maxterms and i did get a similar amplitude range for all 3 plots. The peaks don't vary much. The question asks us to provide the peak value hence the reason for hard coding it. Is there a simple bit of code that could automatically provide it?
 
on Phys.org
Try:

m = max(s)
title_string = sprintf('maximum is: %f',m)
title(title_string)

As for your offset-- then don't do it. It is affecting the peak value you are reporting.
 
I guess the peak value is the same for all 3 plots. The only noticeable difference is the sharpening of the edge of the triangle. I assume as convergence occurs there will be less visible change.
 

Attachments

  • graphs.jpg
    graphs.jpg
    36.8 KB · Views: 490
They should not be the same. They should be close, but N=30 should give you a larger peak than N=6. Just considering the summation at the t=0, cos(0)=1, point.
 
Ah it was because i didn't put m=max(s) before every maxterm. I have did that now and got a larger peak. 1.192, 1.209 and 1.225