MATLAB How Can I Model sin(wt) in MATLAB?

  • Thread starter Thread starter mbolhi
  • Start date Start date
  • Tags Tags
    Matlab Modeling
AI Thread Summary
To model sin(wt) in MATLAB, users can define the variable t as a vector that spans from 0 to 2π in small increments, using the command t=0:pi/100:2*pi. The frequency w can be calculated as w=2*pi*f, where f is the frequency of excitation. The sine function can be applied to this variable with y=sin(w*t), allowing for plotting with the command plot(t,y). Additionally, the discussion highlights the application of this sine function as an input to a dynamical system described by a second-order ordinary differential equation (ODE). Users are encouraged to consult MATLAB's internal documentation for further guidance and to explore resources for both MATLAB and Simulink for more complex modeling tasks.
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 teh 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
 

Similar threads

Replies
5
Views
3K
Replies
1
Views
2K
Replies
10
Views
3K
Replies
10
Views
3K
Replies
4
Views
3K
Back
Top