Jean-Marie
Jean-Marie

Reputation: 11

Plot sine function in MATLAB

I'm trying to plot this equation but i'm some difficulties, some help please. I here is what i have tried.

    x=[0:pi/20:4*pi];
    y= (25*sin(3)*t);
    plot (x,y)

Upvotes: 1

Views: 1352

Answers (3)

Devendra Lattu
Devendra Lattu

Reputation: 2812

You need to assign equal vector length value to t as of x. However, I believe, you need to replace x with t in your equation.

y= (25*sin(3)*x);  # will plot a straight line since you have a constant sin(3)
                   # which you are just multiplying with x resulting in x verses constant x

I assume you want to write the equation as

x=[0:pi/20:4*pi];
y= (25*sin(3*x));
plot (x,y)

Plot Matlab

Upvotes: 0

Craig C.
Craig C.

Reputation: 26

Your code isn't working because t is undefined. You either need to change your definition of x to be t, for example:

t=[0:pi/20:4*pi];

or you need to make your y a function of x, rather than t, for example:

y= (25*sin(3)*x);

I am curious if your original equation/function that you are trying to plot is y(t)=25 sin(3 t). If this is the case, then you need to change your parenthesis so that sin is a function of the independent variable (x or t). This would look like:

y = 25*sin(3*x);

Upvotes: 1

qbzenker
qbzenker

Reputation: 4662

I think you meant to get oscillations:

x = [0:pi/20:4*pi];
y = 25*sin(3*x);
plot(x,y)

Upvotes: 0

Related Questions