How Can I Model sin(wt) in MATLAB?

In summary, this person uses MATLAB to model sin(wt) and then passes it through a gain block to create a sin(wt) waveform. They then use a fcn block to define a cosine wave equation.
  • #1
mbolhi
10
0
Hello all,

I am a beginenr and I need help as to how to model sin(wt) in matlab?

how could i define the variale t ?

I would liek to have cases for different frequencies where w = 2* PI * f

and f is teh freuqency of excitation...

thanks for your help
 
Physics news on Phys.org
  • #2
Welcome to PhysicsForums!

In MATLAB, you generally work on arrays of data, not symbolic data (though you can do some symbolic tasks, and there's a whole symbolic toolbox that has the MAPLE kernel, if I recall correctly).

I'm not quite sure what it is that you're attempting to do, but the following commands would help you plot a small graph (note that anything that follows the % sign is not interpreted by MATLAB, i.e. a comment). As well, note that MATLAB's internal documentation is quite helpful: just type help followed by the command, and you'll get a short blurb on how to use the command.

Code:
w=4
t=0:pi/100:2*pi %this creates a vector of values for t, from 0 to 2*pi in pi/100 increments.
y=sin(w*t) %takes sin of w * all the values in the t vector
plot(t,y)
 
  • #3
Thansk for your help dude,

in my problem that I need to solve:

the sin(w*t) is the input (excitation) to a dynamical system. this latter is described by a second order ODE as follows:

dy(1) = y(2);

dy(2) = - B1*U1/m - B2*U2/m + g + C_x/m * y(2) ;

where

U1 and U2 are the excitation that need to be sinosoidal = sin(w*t)



MATLABdude said:
Welcome to PhysicsForums!

In MATLAB, you generally work on arrays of data, not symbolic data (though you can do some symbolic tasks, and there's a whole symbolic toolbox that has the MAPLE kernel, if I recall correctly).

I'm not quite sure what it is that you're attempting to do, but the following commands would help you plot a small graph (note that anything that follows the % sign is not interpreted by MATLAB, i.e. a comment). As well, note that MATLAB's internal documentation is quite helpful: just type help followed by the command, and you'll get a short blurb on how to use the command.

Code:
w=4
t=0:pi/100:2*pi %this creates a vector of values for t, from 0 to 2*pi in pi/100 increments.
y=sin(w*t) %takes sin of w * all the values in the t vector
plot(t,y)
 
  • #4
I'm afraid that, despite my username, I don't have a whole lot of experience with Simulink (which is what I think you're working with). That being the case, perhaps the Mathworks documentation page might be of help? It is really quite thorough, and their "Getting Started" series is fairly straight forward:
http://www.mathworks.com/products/simulink/

For help in getting started in the basic MATLAB environment, I'd recommend the following (it's also available in dead-tree format, but I believe the whole thing is online):
http://www.mathworks.com/help/techdoc/index.html
 
  • #5
MATLABdude said:
I'm afraid that, despite my username, I don't have a whole lot of experience with Simulink (which is what I think you're working with). That being the case, perhaps the Mathworks documentation page might be of help? It is really quite thorough, and their "Getting Started" series is fairly straight forward:
http://www.mathworks.com/products/simulink/

For help in getting started in the basic MATLAB environment, I'd recommend the following (it's also available in dead-tree format, but I believe the whole thing is online):
http://www.mathworks.com/help/techdoc/index.html



Thanks for your help, but I actually use MATLAB not simulink (from which I take only SFunctions)
 
  • #6
mbolhi said:
Thanks for your help, but I actually use MATLAB not simulink (from which I take only SFunctions)

hi simply use a clock in simulink after that pass it through a gain block (we) we=2*pi*f
after that use a fcn block by double click define the sine or cosine wave equation
 

1. What is the purpose of modeling sin(wt) in Matlab?

The purpose of modeling sin(wt) in Matlab is to simulate and analyze a sinusoidal function with a variable frequency, represented by w, over time. This can be useful in a variety of fields such as signal processing, electrical engineering, and physics.

2. How do I generate a plot of sin(wt) in Matlab?

To generate a plot of sin(wt) in Matlab, you can use the "plot" function with the appropriate x and y values. For example, if you want to plot sin(wt) from 0 to 2*pi with a frequency of 1, you can use the code "t = 0:0.01:2*pi; plot(t,sin(t))".

3. Can I change the frequency of sin(wt) in Matlab?

Yes, you can change the frequency of sin(wt) in Matlab by modifying the value of w in the function. For example, if you want to plot sin(2wt), you would use the code "t = 0:0.01:2*pi; plot(t,sin(2*t))".

4. How can I add noise to my sin(wt) plot in Matlab?

To add noise to your sin(wt) plot in Matlab, you can use the "randn" function to generate a random noise vector with the same length as your time vector. Then, you can add this noise vector to your sin(wt) vector using the "+" operator. For example, if your sin(wt) vector is "y = sin(t)", you can add noise by using the code "y = y + randn(size(t))".

5. Can I export my sin(wt) plot in Matlab as an image file?

Yes, you can export your sin(wt) plot in Matlab as an image file by using the "saveas" function. This function allows you to save your plot as a variety of image file formats such as JPEG, PNG, or PDF. For example, if you want to save your plot as a JPEG file, you can use the code "saveas(gcf,'sin_wt_plot.jpg')".

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
985
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
737
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
972
Back
Top