How Can I Model sin(wt) in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter mbolhi
  • Start date Start date
  • Tags Tags
    Matlab Modeling
Click For Summary

Discussion Overview

The discussion revolves around modeling the function sin(wt) in MATLAB, particularly in the context of simulating a dynamical system described by a second-order ordinary differential equation (ODE). Participants explore how to define variables and set up simulations for different frequencies.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • A participant seeks guidance on defining the variable t and modeling sin(wt) for different frequencies, where w = 2 * PI * f.
  • Another participant provides MATLAB commands to create a vector for t and plot the sine function, emphasizing the use of arrays in MATLAB.
  • One participant describes a specific problem where sin(wt) serves as input to a dynamical system governed by a second-order ODE, detailing the equations involved.
  • Some participants suggest referring to Mathworks documentation for additional help with MATLAB and Simulink, although one clarifies they are using MATLAB and not Simulink.
  • A later reply proposes using a clock and gain block in Simulink to generate the sine wave, indicating a potential misunderstanding of the original request.

Areas of Agreement / Disagreement

Participants express differing levels of familiarity with MATLAB and Simulink, leading to some confusion regarding the appropriate tools for the task. There is no consensus on the best approach to model sin(wt) specifically within MATLAB versus Simulink.

Contextual Notes

Some participants reference the need for specific MATLAB commands and documentation, but there is uncertainty about the exact requirements for the dynamical system modeling and how sin(wt) fits into it.

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
 

Similar threads

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