From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Mathscript Syntax question with trig functions tia sal2

Greetings, 


Mathscript syntax question

 

I’m trying to plot x and y using the mathscript window.  The following mathscript gives me an error of

t=linspace(1, 2*pi, 20);


x=t*cos(t)


y = sin(t);


plot(x, y, 'bo-');

 


“Error in function * (mtimes) at line 2.  The sizes of the input matrices are incompatible.  Verify that the matrices have the same size or that one is a scalar.”

 

but this version works

t = linspace(1, 2*pi, 20);


x = cos(t)


y = sin(t);


plot(x, y, 'bo-');


 

why can’t I plot x and y as two trig functions can someone tell me the proper syntax

 


tia
sal2

0 Kudos
Message 1 of 4
(7,258 Views)
Hello,

LabVIEW 8.0 MathScript has a built-in help infrastructure to help you understand the syntax and semantics of the language.  Simply type

help

in the command window to get started.  This gives a brief overview of the language as well as instructions to type

help help

for a list of help commands.  Typing

help classes

will return a list of classes of MathScript functions available.  When you see a class of functions you are interested in, you can type

help class

(replacing "class" with the name of the class you wish to see) in order to list the available functions within that class.  Finally, you can type

help function

(replacing "function" with the name of the function you wish to see) in order to display help for that particular function.  In your particular example, MathScript is reporting an error in function mtimes.  This function is simply the prefix notation for the * infix operator.  In order to see the proper syntax, type

help mtimes

The help says that "if a is a matrix, the number of columns in a must equal the number of rows in b."  To see if there is a dimension mismatch in your case, execute your first two statements of the working script:

t = linspace(1, 2*pi, 20);
x = cos(t);

The size function will return the size of each dimension of a given matrix.  Typing

help size

tells us that by default the size function returns a two-element vector containing the dimensions of the given matrix.  The dimensions are returned with the first dimension listed first (i.e. the rows).  Thus, we can see the number of rows and columns of a matrix by using the size function.  Typing

size(t)
size(x)

returns the dimensions of each matrix.  Since the dimensions are equal, we can see that the number of columns in t is not equal to the number of rows in x.  This is the problem that mtimes is reporting.  You can restructure your code to perform an appropriate multiplication.  However, if we read the help for mtimes a little closer, we see that it performs a matrix multiplication.  You probably want to perform a scalar multiplication.  The second line of the help output states that the function is part of the matrixops class.  By typing

help matrixops

we can see if there is a function in this class that performs a scalar multiplication.  We see there is a function called "times" that performs an element-wise multiplication.  Typing

help times

we can see that ".*" is the corresponding infix operator.  This may be the operator you wish to use.

The second issue you reported is trying to plot two vectors on the same graph.  The plot function can certainly do this.  To determine the appropriate syntax, type

help plot

We can see that, for multiple plots, the plot function expects (x, y, attributes) triplets to specify each plot.  We see that the attributes input is optional, so you can also use (x, y) pairs.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 2 of 4
(7,250 Views)

How can I can solve the lenght of ramp if I have 2 meter height and 30 degrees wich fuction I should use in rigth triangale

0 Kudos
Message 3 of 4
(5,791 Views)

@kukin wrote:

How can I can solve the lenght of ramp if I have 2 meter height and 30 degrees wich fuction I should use in rigth triangale



(For some reason you added to a 6 year old thread with an unrelated new question. I would recommend to start a new thread instead.)

 

It is not clear what you are looking for. Do you have a programming question or a simple trigonometry question? Since you posted in the MathScript forum, I assume MathScript has something to do with it.

 

 

0 Kudos
Message 4 of 4
(5,783 Views)