MATLAB Answers

0

How do at write the equation

Asked by Anna Nordin on 3 Sep 2019
Latest activity Commented on by Torsten
on 3 Sep 2019
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.

  0 Comments

Sign in to comment.

1 Answer

Torsten
Answer by Torsten
on 3 Sep 2019
 Accepted Answer

f = x.^2.*sin(x*pi)

  2 Comments

Thank you!
I thought you only had to pun "." after the x
Torsten
on 3 Sep 2019
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 ".*" .

Sign in to comment.