How to plot out a triangular wave in matlab

In summary, the conversation discusses a Matlab program that visualizes the Fourier series with animation and investigates the largest error when the number of terms is based on the highest digit of a student's ID number. The program uses a for loop and the plot function, and the suggestion is made to add labels and a title to the plot for better tracking.
  • #1
karbarca
1
0
that's my programe :
n=0;
T=2;
Ts=T/200;
t=-T/2:Ts:T/2;

for n=0:0.1:8;
V= 0;
V=V+8/pi^2*(-1)^n*sin(pi*(2*n+1)*t)/(2*n+1)^2;
pause
drawnow
plot(t,V);

end

When T=2, write a Matlab program to visualize the Fourier series (with animation) and investigate the largest error you may have when the number of terms is k (=the highest digit of your student ID number). For example, if you student number is M0001234572, then k=7. In this case, your sum
should run from n=0 to 8.
i need someone to check for me thanks
 
Physics news on Phys.org
  • #2
a lot! §§ FILEYour code looks good. I would suggest adding an xlabel and ylabel to the plot. Additionally, you could add a title to the plot that mentions the number of terms you are using, so it is easy to track the animation as it progresses. For example: plot(t,V);xlabel('Time (s)');ylabel('Amplitude');title(['Fourier Series, k = ' num2str(k)]);
 

1. How do I create a triangular wave in Matlab?

To create a triangular wave in Matlab, you can use the "sawtooth" function. This function takes in two parameters: the period of the wave and the amplitude. By varying these parameters, you can adjust the shape and size of your triangular wave.

2. How can I plot a triangular wave in Matlab?

To plot a triangular wave in Matlab, you can use the "plot" function. First, create a vector of x-values to represent the time intervals you want to plot. Then, use the "sawtooth" function to generate the y-values for your triangular wave. Finally, use the "plot" function to plot the x and y vectors.

3. Can I change the frequency of the triangular wave in Matlab?

Yes, you can change the frequency of the triangular wave in Matlab by adjusting the period parameter in the "sawtooth" function. A smaller period will result in a higher frequency, while a larger period will result in a lower frequency.

4. How can I add a phase shift to my triangular wave in Matlab?

To add a phase shift to your triangular wave in Matlab, you can use the "phase" parameter in the "sawtooth" function. This parameter allows you to shift the wave horizontally on the plot, creating a delay or advance in the wave.

5. Is there a way to create a symmetrical triangular wave in Matlab?

Yes, you can create a symmetrical triangular wave in Matlab by using the "sawtooth" function with a period of 2*pi. This will generate a wave that is symmetrical about the x-axis. You can then adjust the amplitude to change the height of the wave.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
826
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
955
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
0
Views
513
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
34
Views
11K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Back
Top