Need Help Plotting exp(-0.5*x)*sin(x)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Need Help Plotting exp(-0.5*x)*sin(x)

Jonathan Drews
Hello:

 I am new user of Octave and I would like to know how to get it to plot
exp(-0.5*x)*sin(x). I am making the following entries:

x=(0.0:0.1:10.0)';
data=[x,exp(-0.5*x)*sin(x)]

It returns the message:

error: operator *: nonconformant arguments (op1 is 101x1, op2 is 101x1)
error: evaluating assignment expression near line 8, column 5

As it is trying to multiply to column vectors.  What is the correct way to
plot an expression like exp(-0.5*x)*sin(x).


                                respectfully


                                John



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Need Help Plotting exp(-0.5*x)*sin(x)

Vivek Shanmuganathan (95410006-BS)


On Sat, 5 Aug 2000, Jonathan Drews wrote:

> x=(0.0:0.1:10.0)';
> data=[x,exp(-0.5*x)*sin(x)]
>
> It returns the message:
>
> error: operator *: nonconformant arguments (op1 is 101x1, op2 is 101x1)
> error: evaluating assignment expression near line 8, column 5

Use ".*" instead of "*". The former is elementwise operation, and the
latter is defined as matrix multiplication. Try the code below:


        x=[0.0:0.1:10.0] ;
        y=exp(-0.5*x).*sin(x) ;
        plot (x, y)

It will be a good idea to spend an hour going through online docs of octave
using the command:

        help -i

There are enough examples there.

Vivek...



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Need Help Plotting exp(-0.5*x)*sin(x)

Alfredo Tomasini
In reply to this post by Jonathan Drews
You are using vector and exp(x)*sin(x) it does not what you see.


        [exp(x1), exp(x2), ........ exp(xn)] * [sin(x1) , sin(x2) .........
sin(xn) ]

what kind of product do you what to apply ? It does not make sense unless you
transpose the second matrix
and you get a scalar product of the vectors.

To multiply memer by member use .

        exp(x).*sin(x) = [exp(x1)*sin(x1), exp(x2)*sin(x2), .........]

Alfredo






-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------