I am getting a syntax error with +

I need to calculate the value of y for a hw problem using an element by element operation but the first + is giving me a syntax error and I have no idea what I did wrong. (sorry for the abundance of parenthesis, this is the only way I could figure it out). Where I have the first (t.+1) the + is giving me an error
t=[0,1,2,3,4,5,6,7,8];
y=((20.*t.^(2/3))/(t.+1))-(((t.+1)^2)/(e^((.3.*t)+5)))+(2/(t.+1))

 Accepted Answer

t=[0,1,2,3,4,5,6,7,8];
y=((20.*t.^(2/3))/(t+1))-(((t+1).^2)/(exp((.3.*t)+5)))+(2./(t+1))
+ is implied to be an elementwise operation so you do not need a . in front of it. You do need one in front of the / and ^. There is a convenience function vectorize that will do this for you.
Also note, exp() instead of e^

3 Comments

Thank you, that fixed the + and thanks for the exp(), the professor hasn't gone over it yet. It's working now, but just out of wanting to understand what's happening at y= the = is giving me a red squiggle and when I hover right before it, it tells me 1x9 double with each value in the column listed and if I put the mouse directly after it tells me to terminate statement with semicolon to suppress output. is it the program just telling me what the results will be without running it yet and the option that I have with that line of code? Thanks
t=[0,1,2,3,4,5,6,7,8];
y=((20.*t.^(2/3))./(t+1))-(((t+1).^2)./(exp((.3.*t)+5)))+(2./(t+1))
That is a warning pointing out that you do not have a semi-colon after the expression, and because of that the result of the calculation will be automatically displayed. If you do not want the result to be automatically displayed then add a semi-colon at the end of the line.
And to be pedantic, it's probably an orange squiggle not a red one :)
The red means it's broken and will not run; orange is for warnings, best practices, possible bugs, etc.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!