How do at write the equation

4 次查看(过去 30 天)
How do I make this equation work for a vector? (the vector x=[-1:0.1:1])
f = x 2 sin(πx)
I've tried the following:
f=x.^2*sin(x.*pi)
f=x.^2*sin(x*pi)
It doesn't work.

采纳的回答

Torsten
Torsten 2019-9-3
f = x.^2.*sin(x*pi)
  2 个评论
Anna Nordin
Anna Nordin 2019-9-3
Thank you!
I thought you only had to pun "." after the x
Torsten
Torsten 2019-9-3
No. As soon as you multiply vectors elementwise, you have to use the ".*", "./", ".^" operators.
x.^2 is a vector, sin(pi*x) is a vector. To multiply them elementwise, you have to use ".*" .

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Quadratic Programming and Cone Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by