Trouble plotting a simple sin function

Click For Summary
SUMMARY

The discussion focuses on plotting the function y = (2sin(3w))/w, where w represents angular frequency, using MATLAB. The initial attempt to plot the function resulted in a graph of nothing due to a division by zero error when w equals zero. The correct approach involves using element-wise division with the operator '. /' and starting the x values from 0.01 to avoid NaN results. Implementing these changes allows for successful visualization of the function.

PREREQUISITES
  • Understanding of MATLAB syntax and plotting functions
  • Knowledge of angular frequency and its relationship to radians
  • Familiarity with element-wise operations in MATLAB
  • Basic concepts of sine functions and their graphical representation
NEXT STEPS
  • Learn MATLAB element-wise operations for effective array manipulations
  • Explore MATLAB plotting functions and customization options
  • Study the concept of angular frequency and its applications in signal processing
  • Investigate handling of NaN values in MATLAB to prevent errors in calculations
USEFUL FOR

Mathematics students, engineers, and data analysts who are working with MATLAB for plotting functions and analyzing waveforms.

Lolsauce
Messages
21
Reaction score
0
So all I'm trying to do is plot y = (2sin(3w))/w, w is the angular frequency. I basically want this graph in radians. So this is what I did at first:

Code:
>> x = [0:.01:20] ;    //want bounds from 0 to 20
y = 2.*((sin(3.*x))/x);
plot(y)

But when I do this I get a graph of nothing, I assumed it was in radians by default. Next I tried this

Code:
>> x = [0:.01:20] ;    //want bounds from 0 to 20
y = 2.*((sin(3.*(2.*pi)/x))/x);
plot(y)

I knew angular frequency is 2pi/T, so I tried converting the values of x to radians, but it didn't work either. Any tips?
 
Physics news on Phys.org
Your y is only 1 value at the end change your ))/x to ))./x and your graph comes out correctly.

Also you might want to change your starting index from 0 to 0.01, since you get y(1) = NaN. The plot still comes out correctly but if you're doing anything else with y you will run into problems.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K