How Can I Model sin(wt) in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter mbolhi
  • Start date Start date
  • Tags Tags
    Matlab Modeling
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
5 replies · 13K views
mbolhi
Messages
10
Reaction score
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 the freuqency of excitation...

thanks for your help
 
Physics news on Phys.org
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)
 
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)
 
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
 
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)
 
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