Borrar filtros
Borrar filtros

draw a function composed of sin and cos

1 visualización (últimos 30 días)
khaled Abdelghafar
khaled Abdelghafar el 26 de Feb. de 2022
Comentada: Steven Lord el 26 de Feb. de 2022
i encounter an error when trying ti plot this function
x=-pi:0.1*pi:pi;
y1=100*sqrt(2*pi)/sqrt(0.05*pi).*cos(x/2)*(1.-cos(x/2.)*sin(x/2.)*sin(3.*x/2.));
figure
plot(x,y1)

Respuesta aceptada

Star Strider
Star Strider el 26 de Feb. de 2022
Use element-wise operations
y1=100*sqrt(2*pi)/sqrt(0.05*pi).*cos(x/2).*(1.-cos(x/2.).*sin(x/2.).*sin(3.*x/2.));
See Array vs Matrix Operations for details.
x=-pi:0.1*pi:pi;
y1=100*sqrt(2*pi)/sqrt(0.05*pi).*cos(x/2).*(1.-cos(x/2.).*sin(x/2.).*sin(3.*x/2.));
figure
plot(x,y1)
.
  1 comentario
Steven Lord
Steven Lord el 26 de Feb. de 2022
What @Star Strider has written is correct but one section might be slightly misleading for newer users.
% (1.-cos(x/2.).*sin(x/2.).*sin(3.*x/2.))
That first part may make you think there is an operator .- that does element-wise subtraction. But that's not the case. That period is not part of the operator but part of the number itself, since subtraction already applies element-wise. [There's also no .+ operator; just + is sufficient.]
x = 1.; % one
y = 1; % also one
x == y % true
ans = logical
1
Note that something like this would error instead.
x = 1.1 .- 1
Invalid use of operator.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by