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))

 採用された回答

Sean de Wolski
Sean de Wolski 2017 年 9 月 20 日

2 投票

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 件のコメント

Kimberly Siwek
Kimberly Siwek 2017 年 9 月 20 日
編集済み: Walter Roberson 2017 年 9 月 20 日
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))
Walter Roberson
Walter Roberson 2017 年 9 月 20 日
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.
Sean de Wolski
Sean de Wolski 2017 年 9 月 21 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Coder についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by