'Unbalanced or Unexpected Paranthesis or Bracket' Error in my Command Window

Hello, I'm trying to plot an equation for one of my assignments. Whenever I try to submit my function, I get the error. The lines are as followed:
>> y=exp(-2*t.)*(.034*cos(19.9*t)-.00095*sin(19.9*t))+.066*cos(10*t)+.0087*sin(10*t);
y=exp(-2*t.)*(.034*cos(19.9*t)-.00095*sin(19.9*t))+.066*cos(10*t)+.0087*sin(10*t);
Error: Unbalanced or unexpected parenthesis or bracket.
I cannot figure out what is wrong with that one parenthesis in the first component.
Any help is appreciated. Thanks!

 Accepted Answer

Change
y=exp(-2*t.)*(.034*cos(19.9*t)-.00095*sin(19.9*t))+.066*cos(10*t)+.0087*sin(10*t)
to
y=exp(-2*t).*(.034*cos(19.9*t)-.00095*sin(19.9*t))+.066*cos(10*t)+.0087*sin(10*t)

3 Comments

Thank you so much. Why would moving that point change it like that?
The places that a "." can appear are:
  • indicating the decimal point as part of a number, such as 19.9
  • as part of the operators that are named .* (formal name: times), ./ (formal name: rdivide), .^ (formal name: power); these three pairs of characters must occur together with no space, such as (1:10) .^ 2 . These are different operators than * (formal name: mtimes), / (formal name: rdivide) or ^ (formal name: mpower) -- just like the >= operator is a pair of characters together that is not the > operator and not the = operator either.
  • indicating a field of a structure is being accessed, such as s.x = 17 indicates field x in structure s
  • indicating a property or method of an object is being accessed, which looks exactly like the field name case, such as ax = gca; ax.XTick = 1:10; is accessing the XTick property of the ax object
  • indicating that a function that is part of a "+" package is being referred to, which looks exactly like the field name case
The situation you wrote was similar to having written exp(-2*t&) in that there is just no meaning to an operator appearing by itself at the end of an expression.
If you had happened to write
y=exp(-t*2.)*(.034*cos(19.9*t)-.00095*sin(19.9*t))+.066*cos(10*t)+.0087*sin(10*t)
then that would have been legal because the period would be interpreted as being part of the number. In that expression if t happened to be a scalar then the line would be fine as it is, but if t happened to be a vector or array then you probably would have gotten a failure trying to carry out the multiplication of the exp(-t*2.) part by the (.034*cos(19.9*t)-.00095*sin(19.9*t)) part. The * operator (formal name: mtimes) is algebraic matrix multiplication like you would have studied in high school, where the number of columns of what is on the left has to equal the number of rows of what is on the right.
t.
is not valid syntax. You can't have trailing decimal points after variable names. The decimal point would need to be part of something else following to be valid (e.g. part of a struct field name syntax, or part of an element-wise operator syntax, etc)

Sign in to comment.

More Answers (0)

Asked:

on 26 Sep 2017

Edited:

on 27 Sep 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!