How do at write the equation

1 visualizzazione (ultimi 30 giorni)
Anna Nordin
Anna Nordin il 3 Set 2019
Commentato: Torsten il 3 Set 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.

Risposta accettata

Torsten
Torsten il 3 Set 2019
f = x.^2.*sin(x*pi)
  2 Commenti
Anna Nordin
Anna Nordin il 3 Set 2019
Thank you!
I thought you only had to pun "." after the x
Torsten
Torsten il 3 Set 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 ".*" .

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by